rendered paste bodyint make_sfv(char *reldir) { static struct dirent *dp; DIR *dirp; int fd, fcount = 0; static char buf[PATH_MAX + 3]; char *fp; struct stat stat_buf; if (!(dirp = opendir("."))) { d_log("make_sfv: Failed to open current dir: %s\n", strerror(errno)); return 1; } if ((fd = open("pzs-ng.sfv", O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { d_log("make_sfv: Failed to create pzs-ng.sfv: %s\n", strerror(errno)); (void)closedir(dirp); return 1; } while ((dp = readdir(dirp)) != NULL) { fp = dp->d_name + NAMLEN(dp) - 3; if (NAMLEN(dp) > 2 && *dp->d_name != '.' && !strcomp(ignored_types, fp) && (!strcomp(allowed_types, fp) || (strcomp(allowed_types, fp) && matchpath(allowed_types_exemption_dirs, reldir))) && strcmp(dp->d_name, "pzs-ng.sfv") &&// dp->d_type == DT_REG && stat (dp->d_name, &stat_buf) == 0 && S_ISREG (stat_buf.st_mode) && strcmp(fp, "nfo")) { d_log("make_sfv: Adding \"%-20s 00000000\" to sfv\n", dp->d_name); snprintf(buf, sizeof(buf), "%-20s 00000000\n", dp->d_name); fcount++; if ((write(fd, buf, strlen(buf))) == -1) { d_log("make_sfv: write failed: %s\n", strerror(errno)); (void)close(fd); (void)closedir(dirp); return 1; } } else d_log("make_sfv: Ignoring %s (check allowed_types and ignored_types if this is wrong)\n", dp->d_name); } if (!fcount) { d_log("make_sfv: Did not find anything to put in the sfv - removing sfv\n"); unlink("pzs-ng.sfv"); } (void)close(fd); (void)closedir(dirp); return 0;}