diff --git a/CHANGES.md b/CHANGES.md index 8a781769..234ea391 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,39 @@ # Major changes to the IOCCC entry toolkit +## Release 2.4.5 2025-03-10 + +Add `-U UUID` option - resolve #1229. + +Also fixed an error with `-u uuidfile` where it would not set the `test` boolean +to true if the UUID was `"true"`. + +The `-u uuidfile` and `-U UUID` options may not be used with `-i answers`, `-d` +or `-s seed`. + +Partial fix to issue #1208. The `-x` option to force delete the +submission directory and `-r rm` option to set path to `rm(1)` were added to +`mkiocccentry` as part of #1208. The change in order of args is **NOT** done and +will not be done until **AFTER** IOCCC28. + +Fixed bug where `overwrite_answers` was always true by default (`mkiocccentry`). + +Updated man page for the above changes. + +Resolved issues #1233 and #1218. Both `mkiocccentry` and `txzchk` (the only ones +that use other tools) now search `$PATH` for the tools first by way of the +`find_utils()` function (modified a fair bit) and a new util function in jparse +called `resolve_path()`. The jparse util functions `shell_cmd()` and +`pipe_open()` were also improved to resolve paths if no `/` is in the command +name. As for `make`: we now search for `gmake` first as the Makefiles we need +are GNU Makefiles. + +Add missing `-r` to `rm` in `mkiocccentry_test.sh`. + +**IMPORTANT NOTE**: you do NOT need to use this update in order to participate +in the IOCCC28! + + ## Release 2.4.4 2025-03-09 Resolve some (mostly top priority) issues. diff --git a/jparse/CHANGES.md b/jparse/CHANGES.md index aff46ac3..a2c53c4d 100644 --- a/jparse/CHANGES.md +++ b/jparse/CHANGES.md @@ -1,5 +1,35 @@ # Significant changes in the JSON parser repo + +## Release 2.2.35 2025-03-10 + +Improved `shell_cmd()` and `pipe_open()` to resolve path (using `resolve_path()` +which searches `$PATH`) if there is no `/` in the command. + +Updated `JPARSE_UTILS_VERSION` to `"2.0.5 2025-03-10"`. + + +## Release 2.2.34 2025-03-09 + +Updated `base_name()`, `dir_name()` and added new function `resolve_path()`. + +The function `base_name()` now will, on a NULL or empty string, return a copy of +`"."` just like `basename(3)` does. + +The function `dir_name()` now will, on a NULL or empty string or a string that +has no `/` (unless `level < 0`) , return a copy of `"."` just like `dirname(3)` +(though that function does not have the `level` functionality). + +The function `resolve_path()` will go through the process's `$PATH` and search +for an executable file with the name passed to the function, returning either a +copy of the path or NULL. If the command starts with `/` or `./` then the +`$PATH` is not searched and instead that exact string is duplicated and +returned. + +Updated `JPARSE_UTILS_VERSION` to `"2.0.4 2025-03-09"`. +Updated `UTIL_TEST_VERSION` to `"2.0.2 2025-03-09"`. + + ## Release 2.2.33 2025-03-07 Additional sanity checks added to FTS code. diff --git a/jparse/util.c b/jparse/util.c index a3017464..9e347d22 100644 --- a/jparse/util.c +++ b/jparse/util.c @@ -118,8 +118,11 @@ static char const * const usage = * * This function does not return on error. * - * NOTE: It is the caller's responsibility to free the returned string when it + * NOTE: it is the caller's responsibility to free the returned string when it * is no longer needed. + * + * NOTE: on a NULL or empty string this function returns a copy of the string + * "." like basename(3). */ char * base_name(char const *path) @@ -133,9 +136,14 @@ base_name(char const *path) /* * firewall */ - if (path == NULL) { - err(100, __func__, "called with NULL path"); /*coo*/ - not_reached(); + if (path == NULL || *path == '\0') { + errno = 0; /* pre-clear errno for errp() */ + copy = strdup("."); + if (copy == NULL) { + errp(55, __func__, "strdup(\".\") returned NULL"); + not_reached(); + } + return copy; } /* @@ -144,7 +152,7 @@ base_name(char const *path) errno = 0; /* pre-clear errno for errp() */ copy = strdup(path); if (copy == NULL) { - errp(101, __func__, "strdup(\"%s\") failed", path); + errp(56, __func__, "strdup(\"%s\") failed", path); not_reached(); } @@ -202,7 +210,7 @@ base_name(char const *path) errno = 0; /* pre-clear errno for errp() */ ret = strdup(p + 1); if (ret == NULL) { - errp(102, __func__, "strdup(\"%s\") failed", p + 1); + errp(57, __func__, "strdup(\"%s\") failed", p + 1); not_reached(); } @@ -275,8 +283,12 @@ base_name(char const *path) * * and level == -1 we will return: "foo". * - * NOTE: an empty string will result in a strdup()d copy of it so you still have - * to free() it when you're done with it. + * NOTE: a NULL path, an empty string path or a path with no '/' will return '.' + * indicating the current working directory, except if level < 0 in which case + * if it's not an empty string it'll return the string itself. + * + * The returned value is always a strdup()d copy so you must free() it when + * done. */ char * dir_name(char const *path, int level) @@ -292,9 +304,17 @@ dir_name(char const *path, int level) /* * firewall */ - if (path == NULL) { - err(103, __func__, "called with NULL path"); - not_reached(); + if (path == NULL || *path == '\0' || (strchr(path, '/') == NULL && level >= 0)) { + /* + * emulate dirname(3): return string "." + */ + errno = 0; /* pre-clear errno for errp() */ + copy = strdup("."); + if (copy == NULL) { + errp(58, __func__, "failed to strdup(\".\")"); + not_reached(); + } + return copy; } /* @@ -307,7 +327,7 @@ dir_name(char const *path, int level) errno = 0; /* pre-clear errno for errp() */ copy = strdup(path); if (copy == NULL) { - errp(104, __func__, "strdup(\"%s\") failed", path); + errp(59, __func__, "strdup(\"%s\") failed", path); not_reached(); } @@ -319,8 +339,8 @@ dir_name(char const *path, int level) /* * case: path string is empty */ - dbg(DBG_VVHIGH, "#0: dir_name(\"%s\", %d): path is an empty string", path, level); - return copy; + err(60, __func__, "#0: dir_name(\"%s\", %d): copied string is empty", path, level); + not_reached(); } /* @@ -349,6 +369,19 @@ dir_name(char const *path, int level) * if length <= 0 we will return a copy of the (now) modified string */ dbg(DBG_VVHIGH, "#1: dir_name(\"%s\", %d) is an empty string", path, level); + /* + * free copy and strdup(".") like dirname(3) + */ + if (copy != NULL) { + free(copy); + copy = NULL; + } + errno = 0; /* pre-clear errno for errp() */ + copy = strdup("."); + if (copy == NULL) { + errp(61, __func__, "failed to strdup(\".\")"); + not_reached(); + } return copy; } @@ -391,7 +424,7 @@ dir_name(char const *path, int level) errno = 0; /* pre-clear errno for errp() */ ret = strdup(copy); if (ret == NULL) { - errp(105, __func__, "failed to strdup(\"%s\")", copy); + errp(62, __func__, "failed to strdup(\"%s\")", copy); not_reached(); } p = strtok_r(ret, "/", &saveptr); @@ -415,7 +448,7 @@ dir_name(char const *path, int level) errno = 0; /* pre-clear errno for errp() */ ret = strdup(p); if (ret == NULL) { - errp(106, __func__, "strdup(\"%s\") failed", p); + errp(63, __func__, "strdup(\"%s\") failed", p); not_reached(); } @@ -467,7 +500,7 @@ dir_name(char const *path, int level) errno = 0; /* pre-clear errno for errp() */ ret = strdup(copy); if (ret == NULL) { - errp(107, __func__, "strdup(\"%s\") failed", copy); + errp(64, __func__, "strdup(\"%s\") failed", copy); not_reached(); } @@ -524,7 +557,7 @@ count_comps(char const *str, char comp, bool remove_all) * firewall */ if (str == NULL) { - err(108, __func__, "called with NULL str"); + err(65, __func__, "called with NULL str"); not_reached(); } @@ -535,7 +568,7 @@ count_comps(char const *str, char comp, bool remove_all) errno = 0; /* pre-clear errno for errp() */ copy = strdup(str); if (copy == NULL) { - errp(109, __func__, "strdup(\"%s\") failed", str); + errp(66, __func__, "strdup(\"%s\") failed", str); not_reached(); } @@ -691,7 +724,7 @@ count_dirs(char const *path) * firewall */ if (path == NULL) { - err(110, __func__, "path is NULL"); + err(67, __func__, "path is NULL"); not_reached(); } @@ -725,7 +758,7 @@ exists(char const *path) * firewall */ if (path == NULL) { - err(111, __func__, "called with NULL path"); + err(68, __func__, "called with NULL path"); not_reached(); } @@ -783,7 +816,7 @@ file_type(char const *path) * firewall */ if (path == NULL) { - err(112, __func__, "called with NULL path"); + err(69, __func__, "called with NULL path"); not_reached(); } @@ -850,7 +883,7 @@ file_type(char const *path) /* * unknown type - shouldn't happen */ - err(113, __func__, "path is unknown file type: %s", path); + err(70, __func__, "path is unknown file type: %s", path); not_reached(); } @@ -884,7 +917,7 @@ is_mode(char const *path, mode_t mode) * firewall */ if (path == NULL) { - err(114, __func__, "called with NULL path"); + err(71, __func__, "called with NULL path"); not_reached(); } @@ -901,7 +934,7 @@ is_mode(char const *path, mode_t mode) switch (file_type(path)) { case FILE_TYPE_ERR: - err(115, __func__, "error in obtaining file type of path: %s", path); + err(72, __func__, "error in obtaining file type of path: %s", path); not_reached(); case FILE_TYPE_ENOENT: warn(__func__, "path does not exist: %s", path); @@ -965,7 +998,7 @@ has_mode(char const *path, mode_t mode) * firewall */ if (path == NULL) { - err(116, __func__, "called with NULL path"); + err(73, __func__, "called with NULL path"); not_reached(); } @@ -1018,7 +1051,7 @@ is_file(char const *path) * firewall */ if (path == NULL) { - err(117, __func__, "called with NULL path"); + err(74, __func__, "called with NULL path"); not_reached(); } @@ -1066,7 +1099,7 @@ is_dir(char const *path) * firewall */ if (path == NULL) { - err(118, __func__, "called with NULL path"); + err(75, __func__, "called with NULL path"); not_reached(); } @@ -1114,7 +1147,7 @@ is_symlink(char const *path) * firewall */ if (path == NULL) { - err(119, __func__, "called with NULL path"); + err(76, __func__, "called with NULL path"); not_reached(); } @@ -1162,7 +1195,7 @@ is_socket(char const *path) * firewall */ if (path == NULL) { - err(120, __func__, "called with NULL path"); + err(77, __func__, "called with NULL path"); not_reached(); } @@ -1210,7 +1243,7 @@ is_chardev(char const *path) * firewall */ if (path == NULL) { - err(121, __func__, "called with NULL path"); + err(78, __func__, "called with NULL path"); not_reached(); } @@ -1258,7 +1291,7 @@ is_blockdev(char const *path) * firewall */ if (path == NULL) { - err(122, __func__, "called with NULL path"); + err(79, __func__, "called with NULL path"); not_reached(); } @@ -1306,7 +1339,7 @@ is_fifo(char const *path) * firewall */ if (path == NULL) { - err(123, __func__, "called with NULL path"); + err(80, __func__, "called with NULL path"); not_reached(); } @@ -1357,7 +1390,7 @@ is_read(char const *path) * firewall */ if (path == NULL) { - err(124, __func__, "called with NULL path"); + err(81, __func__, "called with NULL path"); not_reached(); } @@ -1408,7 +1441,7 @@ is_write(char const *path) * firewall */ if (path == NULL) { - err(125, __func__, "called with NULL path"); + err(82, __func__, "called with NULL path"); not_reached(); } @@ -1458,7 +1491,7 @@ is_exec(char const *path) * firewall */ if (path == NULL) { - err(126, __func__, "called with NULL path"); + err(83, __func__, "called with NULL path"); not_reached(); } @@ -1554,7 +1587,7 @@ reset_fts(struct fts *fts, bool free_ignored) * firewall */ if (fts == NULL) { - err(128, __func__, "fts is NULL"); + err(84, __func__, "fts is NULL"); not_reached(); } @@ -1569,7 +1602,7 @@ reset_fts(struct fts *fts, bool free_ignored) if (fts->initialised && fts->tree != NULL) { errno = 0; /* pre-clear errno for errp() */ if (fts_close(fts->tree) != 0) { - errp(129, __func__, "fts_close(fts->tree) failed"); + errp(85, __func__, "fts_close(fts->tree) failed"); not_reached(); } } @@ -1638,11 +1671,11 @@ fts_path(FTSENT *ent) /* * Treebeard died :( */ - err(130, __func__, "ent is NULL"); + err(86, __func__, "ent is NULL"); not_reached(); } if (ent->fts_path == NULL || *(ent->fts_path) == '\0') { - err(131, __func__, "ent->fts_path == NULL or empty string"); + err(87, __func__, "ent->fts_path == NULL or empty string"); not_reached(); } else if (ent->fts_path[0] == '\0' || ent->fts_path[1] == '\0' || ent->fts_path[2] == '\0') { /* @@ -1661,13 +1694,13 @@ fts_path(FTSENT *ent) /* * Fangorn Forest burnt down :-( */ - err(132, __func__, "error: path ended up NULL for FTS entry"); + err(88, __func__, "error: path ended up NULL for FTS entry"); not_reached(); } else if (*path == '\0') { /* * Fangorn Forest burnt down :-( */ - err(133, __func__, "error: path ended up as empty string for FTS entry"); + err(89, __func__, "error: path ended up as empty string for FTS entry"); not_reached(); } @@ -1698,11 +1731,11 @@ fts_cmp(const FTSENT **a, const FTSENT **b) * firewall */ if (a == NULL || *a == NULL) { - err(134, __func__, "a is NULL"); + err(90, __func__, "a is NULL"); not_reached(); } if (b == NULL || *b == NULL) { - err(135, __func__, "b is NULL"); + err(91, __func__, "b is NULL"); not_reached(); } @@ -1756,11 +1789,11 @@ fts_rcmp(const FTSENT **a, const FTSENT **b) * firewall */ if (a == NULL || *a == NULL) { - err(136, __func__, "a is NULL"); + err(92, __func__, "a is NULL"); not_reached(); } if (b == NULL || *b == NULL) { - err(137, __func__, "b is NULL"); + err(93, __func__, "b is NULL"); not_reached(); } @@ -1842,14 +1875,14 @@ check_fts_info(FTS *fts, FTSENT *ent) * firewall */ if (fts == NULL) { - err(138, __func__, "fts is NULL"); + err(94, __func__, "fts is NULL"); not_reached(); } if (ent == NULL) { /* * Treebeard died :( */ - err(139, __func__, "ent is NULL"); + err(95, __func__, "ent is NULL"); not_reached(); } path = fts_path(ent); @@ -1859,7 +1892,7 @@ check_fts_info(FTS *fts, FTSENT *ent) * * This should never happen but if it does it is an error */ - err(140, __func__, "path is NULL or empty string"); + err(96, __func__, "path is NULL or empty string"); not_reached(); } @@ -1867,7 +1900,7 @@ check_fts_info(FTS *fts, FTSENT *ent) case FTS_DC: /* cycle in directory tree */ errno = 0; /* pre-clear errno for errp() */ if (fts_set(fts, ent, FTS_SKIP) != 0) { - errp(141, __func__, "failed to set FTS_SKIP on a directory that causes a cycle in the tree: %s", path); + errp(97, __func__, "failed to set FTS_SKIP on a directory that causes a cycle in the tree: %s", path); not_reached(); } else { warn(__func__, "skipping directory %s because it causes a cycle in the tree", path); @@ -1877,7 +1910,7 @@ check_fts_info(FTS *fts, FTSENT *ent) case FTS_DNR: /* directory not readable */ errno = 0; /* pre-clear errno for errp() */ if (fts_set(fts, ent, FTS_SKIP) != 0) { - errp(142, __func__, "failed to set FTS_SKIP on an unreadable directory in the tree: %s", path); + errp(98, __func__, "failed to set FTS_SKIP on an unreadable directory in the tree: %s", path); not_reached(); } else { warn(__func__, "skipping unreadable directory %s in the tree", path); @@ -1889,11 +1922,11 @@ check_fts_info(FTS *fts, FTSENT *ent) * fake errno */ errno = ent->fts_errno; - errp(143, __func__, "no stat(2) info available for %s in tree", path); + errp(99, __func__, "no stat(2) info available for %s in tree", path); not_reached(); break; case FTS_NSOK: /* stat(2) not requested */ - err(144, __func__, "stat(2) info not requested for %s in tree: FTS_NOSTAT set!", path); + err(100, __func__, "stat(2) info not requested for %s in tree: FTS_NOSTAT set!", path); not_reached(); break; case FTS_ERR: /* some error condition */ @@ -1901,7 +1934,7 @@ check_fts_info(FTS *fts, FTSENT *ent) * fake errno */ errno = ent->fts_errno; /* pre-clear errno for errp() */ - errp(145, __func__, "encountered error from path %s in tree", path); + errp(101, __func__, "encountered error from path %s in tree", path); not_reached(); break; default: @@ -2119,12 +2152,12 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) if (*cwd > 0) { errno = 0; /* pre-clear errno for errp() */ if (fchdir(*cwd) != 0) { - errp(146, __func__, "failed to fchdir(%d)", *cwd); + errp(102, __func__, "failed to fchdir(%d)", *cwd); not_reached(); } errno = 0; /* pre-clear errno for errp() */ if (close(*cwd) != 0) { - errp(147, __func__, "close(%d) failed", *cwd); + errp(103, __func__, "close(%d) failed", *cwd); not_reached(); } *cwd = -1; @@ -2139,7 +2172,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) * firewall */ if (fts == NULL) { - err(148, __func__, "fts is NULL"); + err(104, __func__, "fts is NULL"); not_reached(); } @@ -2155,7 +2188,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) errno = 0; /* pre-clear errno for errp() */ *cwd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (*cwd < 0) { - errp(149, __func__, "cannot open ."); + errp(105, __func__, "cannot open ."); not_reached(); } } @@ -2170,7 +2203,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) if (dirfd > 0) { errno = 0; /* pre-clear errno for errp() */ if (fchdir(dirfd) != 0) { - errp(150, __func__, "both chdir(\"%s\") and fchdir(%d) failed", + errp(106, __func__, "both chdir(\"%s\") and fchdir(%d) failed", dir, dirfd); not_reached(); } @@ -2179,7 +2212,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) } else if (dirfd > 0) { errno = 0; /* pre-clear errno for errp() */ if (fchdir(dirfd) != 0) { - errp(151, __func__, "fchdir(%d) failed", dirfd); + errp(107, __func__, "fchdir(%d) failed", dirfd); not_reached(); } } @@ -2240,7 +2273,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) if (fts->tree == NULL) { fts->tree = fts_open(path, fts->options, fts->cmp); if (fts->tree == NULL) { - errp(152, __func__, "fts_open() returned NULL for: %s", dir != NULL ? dir : "."); + errp(108, __func__, "fts_open() returned NULL for: %s", dir != NULL ? dir : "."); not_reached(); } } @@ -2289,7 +2322,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) * a condition but as an additional sanity check we will * check here too. */ - err(153, __func__, "ent has NULL path, skipping"); + err(109, __func__, "ent has NULL path, skipping"); not_reached(); } @@ -2435,7 +2468,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) /* get next string pointer */ u = dyn_array_value(fts->ignore, char *, i); if (u == NULL) { /* paranoia */ - err(154, __func__, "found NULL pointer in fts->ignore[%ju]", (uintmax_t)i); + err(110, __func__, "found NULL pointer in fts->ignore[%ju]", (uintmax_t)i); not_reached(); } if ((fts->base || count_dirs(name) == 1) && ((fts->match_case && !strcmp(ent->fts_name, u)) || @@ -2510,7 +2543,7 @@ read_fts(char *dir, int dirfd, int *cwd, struct fts *fts) } } while (ent != NULL); } else { - err(155, __func__, "fts->tree is NULL when it shouldn't be"); + err(111, __func__, "fts->tree is NULL when it shouldn't be"); not_reached(); } return NULL; @@ -2578,10 +2611,10 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct * firewall */ if (path == NULL) { - err(156, __func__, "passed NULL path"); + err(112, __func__, "passed NULL path"); not_reached(); } else if (fts == NULL) { - err(157, __func__, "passed NULL fts struct"); + err(113, __func__, "passed NULL fts struct"); not_reached(); } @@ -2607,7 +2640,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct errno = 0; /* pre-clear errno for errp() */ dirname = getcwd(NULL, 0); if (dirname == NULL) { - errp(158, __func__, "failed to get absolute path"); + errp(114, __func__, "failed to get absolute path"); not_reached(); } } else { @@ -2617,7 +2650,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct do { char *p = fts_path(ent); if (p == NULL) { - err(159, __func__, "fts_path(ent) returned NULL"); + err(115, __func__, "fts_path(ent) returned NULL"); not_reached(); } if (*path == '\0') { @@ -2642,7 +2675,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct if (abspath && dirname != NULL) { path_found = calloc_path(dirname, p); if (path_found == NULL) { - err(160, __func__, "failed to allocate absolute path of %s", p); + err(116, __func__, "failed to allocate absolute path of %s", p); not_reached(); } if (dirname != NULL) { @@ -2654,7 +2687,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct errno = 0; /* pre-clear errno for errp() */ path_found = strdup(p); if (path_found == NULL) { - errp(161, __func__, "failed to strdup(\"%s\")", p); + errp(117, __func__, "failed to strdup(\"%s\")", p); not_reached(); } } @@ -2685,7 +2718,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct if (abspath && dirname != NULL) { path_found = calloc_path(dirname, p); if (path_found == NULL) { - err(162, __func__, "failed to allocate absolute path of %s", p); + err(118, __func__, "failed to allocate absolute path of %s", p); not_reached(); } if (dirname != NULL) { @@ -2697,7 +2730,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct errno = 0; /* pre-clear errno for errp() */ path_found = strdup(p); if (path_found == NULL) { - errp(163, __func__, "failed to strdup(\"%s\")", p); + errp(119, __func__, "failed to strdup(\"%s\")", p); not_reached(); } } @@ -2732,7 +2765,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct if (abspath && dirname != NULL) { path_found = calloc_path(dirname, p); if (path_found == NULL) { - err(164, __func__, "failed to allocate absolute path of %s", p); + err(120, __func__, "failed to allocate absolute path of %s", p); not_reached(); } if (dirname != NULL) { @@ -2744,7 +2777,7 @@ find_path(char const *path, char *dir, int dirfd, int *cwd, bool abspath, struct errno = 0; /* pre-clear errno for errp() */ path_found = strdup(p); if (path_found == NULL) { - errp(165, __func__, "failed to strdup(\"%s\")", p); + errp(121, __func__, "failed to strdup(\"%s\")", p); not_reached(); } } @@ -2836,7 +2869,7 @@ array_has_path(struct dyn_array *array, char *path, bool match_case, intmax_t *i /* get next string pointer */ u = dyn_array_value(array, char *, i); if (u == NULL) { /* paranoia */ - err(166, __func__, "found NULL pointer in path name dynamic array element: %ju", (uintmax_t)i); + err(122, __func__, "found NULL pointer in path name dynamic array element: %ju", (uintmax_t)i); not_reached(); } @@ -2951,11 +2984,11 @@ append_path(struct dyn_array **paths, char *path, bool unique, bool duped, bool * firewall */ if (paths == NULL) { - err(167, __func__, "paths is NULL"); + err(123, __func__, "paths is NULL"); not_reached(); } if (path == NULL) { - err(168, __func__, "path is NULL"); + err(124, __func__, "path is NULL"); not_reached(); } @@ -2965,7 +2998,7 @@ append_path(struct dyn_array **paths, char *path, bool unique, bool duped, bool */ *paths = dyn_array_create(sizeof(char *), 64, 64, true); if (*paths == NULL) { - err(169, __func__, "failed to create paths paths"); + err(125, __func__, "failed to create paths paths"); not_reached(); } } @@ -2987,7 +3020,7 @@ append_path(struct dyn_array **paths, char *path, bool unique, bool duped, bool errno = 0; /* pre-clear errno for errp() */ u = strdup(path); if (u == NULL) { - errp(170, __func__, "failed to strdup(\"%s\")", path); + errp(126, __func__, "failed to strdup(\"%s\")", path); not_reached(); } } else { @@ -3139,11 +3172,11 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath * firewall */ if (paths == NULL) { - err(171, __func__, "paths list is NULL"); + err(128, __func__, "paths list is NULL"); not_reached(); } if (fts == NULL) { - err(172, __func__, "fts is NULL"); + err(129, __func__, "fts is NULL"); not_reached(); } @@ -3170,7 +3203,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath errno = 0; /* pre-clear errno for errp() */ dirname = getcwd(NULL, 0); if (dirname == NULL) { - errp(173, __func__, "failed to get absolute path"); + errp(130, __func__, "failed to get absolute path"); not_reached(); } } else { @@ -3180,7 +3213,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath do { char *p = fts_path(ent); if (p == NULL) { - err(174, __func__, "fts_path(ent) returned NULL"); + err(131, __func__, "fts_path(ent) returned NULL"); not_reached(); } @@ -3188,7 +3221,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath for (j = 0; j < len; ++j) { path = dyn_array_value(paths, char *, j); if (path == NULL) { - err(175, __func__, "paths[%ju] == NULL", j); + err(132, __func__, "paths[%ju] == NULL", j); not_reached(); } if (*path == '\0') { @@ -3210,7 +3243,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath if (abspath && dirname != NULL) { name = calloc_path(dirname, p); if (name == NULL) { - err(176, __func__, "failed to allocate path: %s/%s", dirname, p); + err(133, __func__, "failed to allocate path: %s/%s", dirname, p); not_reached(); } else { dbg(DBG_VVHIGH, "allocated absolute path: %s", name); @@ -3256,7 +3289,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath if (abspath && dirname != NULL) { name = calloc_path(dirname, p); if (name == NULL) { - err(177, __func__, "failed to allocate path: %s/%s", dirname, p); + err(134, __func__, "failed to allocate path: %s/%s", dirname, p); not_reached(); } else { dbg(DBG_VVHIGH, "allocated absolute path: %s", name); @@ -3303,7 +3336,7 @@ find_paths(struct dyn_array *paths, char *dir, int dirfd, int *cwd, bool abspath if (abspath && dirname != NULL) { name = calloc_path(dirname, p); if (name == NULL) { - err(178, __func__, "failed to allocate path: %s/%s", dirname, p); + err(135, __func__, "failed to allocate path: %s/%s", dirname, p); not_reached(); } else { dbg(DBG_VVHIGH, "allocated absolute path: %s", name); @@ -3379,7 +3412,7 @@ filemode(char const *path, bool printing) * firewall */ if (path == NULL) { - err(179, __func__, "called with NULL path"); + err(136, __func__, "called with NULL path"); not_reached(); } @@ -3433,7 +3466,7 @@ filemode(char const *path, bool printing) st_mode &= ~S_IFIFO; break; default: - err(180, __func__, "unexpected error in determining file type"); + err(137, __func__, "unexpected error in determining file type"); not_reached(); break; } @@ -3840,7 +3873,7 @@ flush_tty(char const *name, bool flush_stdin, bool abort_on_error) if (ret < 0) { /* exit or error return depending on abort_on_error */ if (abort_on_error) { - errp(181, name, "fflush(stdin): error code: %d", ret); + errp(138, name, "fflush(stdin): error code: %d", ret); not_reached(); } else { dbg(DBG_MED, "%s: called via %s: fflush(stdin) failed: %s", __func__, name, strerror(errno)); @@ -3865,7 +3898,7 @@ flush_tty(char const *name, bool flush_stdin, bool abort_on_error) if (ret < 0) { /* exit or error return depending on abort_on_error */ if (abort_on_error) { - errp(182, name, "fflush(stdout): error code: %d", ret); + errp(139, name, "fflush(stdout): error code: %d", ret); not_reached(); } else { dbg(DBG_MED, "%s: called from %s: fflush(stdout) failed: %s", __func__, name, strerror(errno)); @@ -3889,7 +3922,7 @@ flush_tty(char const *name, bool flush_stdin, bool abort_on_error) if (ret < 0) { /* exit or error return depending on abort_on_error */ if (abort_on_error) { - errp(183, name, "fflush(stderr): error code: %d", ret); + errp(140, name, "fflush(stderr): error code: %d", ret); not_reached(); } else { dbg(DBG_MED, "%s: called from %s: fflush(stderr) failed: %s", __func__, name, strerror(errno)); @@ -3925,7 +3958,7 @@ file_size(char const *path) * firewall */ if (path == NULL) { - err(184, __func__, "called with NULL path"); + err(141, __func__, "called with NULL path"); not_reached(); } @@ -3970,7 +4003,7 @@ is_empty(char const *path) * firewall */ if (path == NULL) { - err(185, __func__, "called with NULL path"); + err(142, __func__, "called with NULL path"); not_reached(); } @@ -4239,6 +4272,123 @@ vcmdprintf(char const *fmt, va_list ap) return cmd; } +/* + * resolve_path - resolve an executable under $PATH + * + * given: + * + * cmd - string to find under $PATH + * + * This function does not return on a NULL cmd. + * + * If getenv("PATH") returns NULL or an empty string or the command is not found + * under the path the original cmd is returned, strdup()d. + * + * Returns a char * which is the path to the executable file or the original + * cmd if not found; in either case the return value is a strdup()d copy. + * + * It is the caller's responsibility to free() the returned value. + */ +char * +resolve_path(char const *cmd) +{ + char *path = NULL; /* getenv("PATH") if path == NULL or *path == '\0' */ + char *dup = NULL; /* to duplicate path or path as strtok_r() modifies the string */ + char *saveptr = NULL; /* for strtok_r() */ + char *p = NULL; /* to tokenise path */ + char *str = NULL; /* string to return */ + + /* + * firewall + */ + if (cmd == NULL) { + err(143, __func__, "passed NULL cmd"); + not_reached(); + } + /* + * check if absolute path or if it starts with ./ + */ + if (*cmd == '/' || (*cmd == '.' && cmd[1] == '/')) { + errno = 0; /* pre-clear errno for errp() */ + str = strdup(cmd); + if (str == NULL) { + errp(144, __func__, "strstr(cmd) returned NULL"); + not_reached(); + } + return str; + } + + /* + * get PATH variable + */ + path = getenv("PATH"); + if (path == NULL || *path == '\0') { + /* + * if NULL or empty we will just strdup() the original command + */ + errno = 0; /* pre-clear errno for errp() */ + str = strdup(cmd); + if (str == NULL) { + errp(145, __func__, "strdup(cmd) returned NULL"); + not_reached(); + } + return str; + } + /* + * now duplicate path to tokenise + */ + errno = 0; /* pre-clear errno for errp() */ + dup = strdup(path); + if (dup == NULL) { + errp(146, __func__, "strdup(path) returned NULL"); + not_reached(); + } + + /* + * now we can tokenise the path + */ + for (p = strtok_r(dup, ":", &saveptr); p != NULL; p = strtok_r(NULL, ":", &saveptr)) { + str = calloc_path(p, cmd); + if (str == NULL) { + err(147, __func__, "failed to allocate path: %s/%s", p, cmd); + not_reached(); + } + if (is_file(str) && is_exec(str)) { + /* + * str should be the command's path + */ + dbg(DBG_MED, "found executable file at: %s/%s", p, cmd); + /* + * free dup + */ + if (dup != NULL) { + free(dup); + dup = NULL; + } + return str; + } + + if (str != NULL) { + free(str); + str = NULL; + } + } + + /* + * free memory + */ + if (dup != NULL) { + free(dup); + dup = NULL; + } + + /* + * nothing found + */ + return NULL; +} + + /* * shell_cmd - pass a command, via vcmdprintf() interface, to the shell @@ -4279,36 +4429,38 @@ vcmdprintf(char const *fmt, va_list ap) int shell_cmd(char const *name, bool flush_stdin, bool abort_on_error, char const *format, ...) { - va_list ap; /* variable argument list */ - char *cmd = NULL; /* e.g. cp prog.c submission_dir/prog.c */ - int exit_code; /* exit code from system(cmd) */ + va_list ap; /* variable argument list */ + char *cmd = NULL; /* e.g. cp prog.c submission_dir/prog.c */ + int exit_code; /* exit code from system(cmd) */ int saved_errno = 0; /* before we return from the function we need to let the caller have the errno */ + char *command = NULL; + char *path = NULL; /* for resolve_path() */ /* * firewall */ if (name == NULL) { - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - err(186, __func__, "function name is not caller name because we were called with NULL name"); - not_reached(); - } else { - dbg(DBG_MED, "called with NULL name, returning: %d < 0", EXIT_NULL_ARGS); - return EXIT_NULL_ARGS; - } + /* exit or error return depending on abort_on_error */ + if (abort_on_error) { + err(148, __func__, "function name is not caller name because we were called with NULL name"); + not_reached(); + } else { + dbg(DBG_MED, "called with NULL name, returning: %d < 0", EXIT_NULL_ARGS); + return EXIT_NULL_ARGS; + } } if (format == NULL) { - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - err(187, name, "called with NULL format"); - not_reached(); - } else { - dbg(DBG_MED, "called with NULL format, returning: %d < 0", EXIT_NULL_ARGS); - return EXIT_NULL_ARGS; - } + /* exit or error return depending on abort_on_error */ + if (abort_on_error) { + err(149, name, "called with NULL format"); + not_reached(); + } else { + dbg(DBG_MED, "called with NULL format, returning: %d < 0", EXIT_NULL_ARGS); + return EXIT_NULL_ARGS; + } } - /* + /* * stdarg variable argument list setup */ va_start(ap, format); @@ -4316,21 +4468,21 @@ shell_cmd(char const *name, bool flush_stdin, bool abort_on_error, char const *f /* * build a safe shell command */ - errno = 0; /* pre-clear errno for errp() */ + errno = 0; /* pre-clear errno for errp() */ cmd = vcmdprintf(format, ap); if (cmd == NULL) { saved_errno = 0; - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - errp(188, name, "calloc failed in vcmdprintf()"); - not_reached(); - } else { - dbg(DBG_MED, "called from %s: calloc failed in vcmdprintf(): %s, returning: %d < 0", - name, strerror(errno), EXIT_CALLOC_FAILED); - va_end(ap); /* stdarg variable argument list cleanup */ + /* exit or error return depending on abort_on_error */ + if (abort_on_error) { + errp(150, name, "calloc failed in vcmdprintf()"); + not_reached(); + } else { + dbg(DBG_MED, "called from %s: calloc failed in vcmdprintf(): %s, returning: %d < 0", + name, strerror(errno), EXIT_CALLOC_FAILED); + va_end(ap); /* stdarg variable argument list cleanup */ errno = saved_errno; - return EXIT_CALLOC_FAILED; - } + return EXIT_CALLOC_FAILED; + } } /* @@ -4339,71 +4491,80 @@ shell_cmd(char const *name, bool flush_stdin, bool abort_on_error, char const *f flush_tty(name, flush_stdin, abort_on_error); /* - * execute the command + * if we don't have a path we will try resolving the command + */ + if (strchr(cmd, '/') == NULL) { + /* + * try resolving path + */ + path = resolve_path(cmd); + if (path != NULL) { + free(cmd); + cmd = path; + } + } + + /* + * try executing the command directly */ dbg(DBG_HIGH, "about to perform: system(\"%s\")", cmd); - errno = 0; /* pre-clear errno for errp() */ exit_code = system(cmd); + /* + * if it failed try running directly with the shell + */ if (exit_code < 0) { - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - errp(189, __func__, "error calling system(\"%s\")", cmd); - not_reached(); - } else { - saved_errno = errno; - dbg(DBG_MED, "called from %s: error calling system(\"%s\")", name, cmd); - va_end(ap); /* stdarg variable argument list cleanup */ - /* free allocated command storage */ - if (cmd != NULL) { - free(cmd); - cmd = NULL; - } - errno = saved_errno; - return EXIT_SYSTEM_FAILED; - } + dbg(DBG_HIGH, "system(\"%s\") failed, will attempt to run through shell", cmd); + errno = 0; /* pre-clear errno for errp() */ + command = calloc(1, LITLEN("/bin/sh -c ") + strlen(cmd) + 1); + if (command == NULL) { + errp(151, __func__, "calloc failed"); + free(cmd); + cmd = NULL; + return EXIT_CALLOC_FAILED; + } else { + sprintf(command, "/bin/sh -c %s", cmd); + /* + * now try executing the command via the shell + */ + exit_code = system(command); + free(command); + command = NULL; + } /* * case: exit code 127 usually means the fork/exec was unable to invoke the shell */ } else if (exit_code == 127) { - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - errp(190, __func__, "execution of the shell failed for system(\"%s\")", cmd); - not_reached(); - } else { + /* exit or error return depending on abort_on_error */ + if (abort_on_error) { + errp(152, __func__, "execution of the shell failed for system(\"%s\")", cmd); + not_reached(); + } else { saved_errno = errno; - dbg(DBG_MED, "called from %s: execution of the shell failed for system(\"%s\")", name, cmd); - va_end(ap); /* stdarg variable argument list cleanup */ - /* free allocated command storage */ - if (cmd != NULL) { - free(cmd); - cmd = NULL; - } + dbg(DBG_MED, "called from %s: execution of the shell failed for system(\"%s\")", name, cmd); + va_end(ap); /* stdarg variable argument list cleanup */ + /* free allocated command storage */ + if (cmd != NULL) { + free(cmd); + cmd = NULL; + } errno = saved_errno; - return EXIT_SYSTEM_FAILED; - } - } - - /* - * free allocated command storage - */ - if (cmd != NULL) { - free(cmd); - cmd = NULL; + return EXIT_SYSTEM_FAILED; + } } /* * stdarg variable argument list cleanup */ va_end(ap); - /* - * return exit code from system() + * free storage */ + free(cmd); + cmd = NULL; + return exit_code; } - - /* * pipe_open - pass a command, via vcmdprintf() interface, to the shell * @@ -4422,7 +4583,7 @@ shell_cmd(char const *name, bool flush_stdin, bool abort_on_error, char const *f * that the shell might threaten as command characters. * In the worst case, the algorithm will make twice as * many characters. Will not use escaping if it isn't needed. - * ... - args to give after the format + * ... - args to give after the format * * returns: * FILE * stream for open pipe to shell, or NULL ==> error @@ -4441,6 +4602,7 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo FILE *stream = NULL; /* open pipe to shell command or NULL */ int ret; /* libc function return */ int saved_errno = 0; /* in case of error, save errno for before we return */ + char *path = NULL; /* for resolve_path() */ /* * firewall @@ -4448,7 +4610,7 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo if (name == NULL) { /* exit or error return depending on abort */ if (abort_on_error) { - err(191, __func__, "function name is not caller name because we were called with NULL name"); + err(153, __func__, "function name is not caller name because we were called with NULL name"); not_reached(); } else { dbg(DBG_MED, "called with NULL name, returning NULL"); @@ -4458,7 +4620,7 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo if (format == NULL) { /* exit or error return depending on abort */ if (abort_on_error) { - err(192, name, "called with NULL format"); + err(154, name, "called with NULL format"); not_reached(); } else { dbg(DBG_MED, "called with NULL format, returning NULL"); @@ -4479,7 +4641,7 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo if (cmd == NULL) { /* exit or error return depending on abort */ if (abort_on_error) { - errp(193, name, "calloc failed in vcmdprintf()"); + errp(155, name, "calloc failed in vcmdprintf()"); not_reached(); } else { dbg(DBG_MED, "called from %s: calloc failed in vcmdprintf(): %s returning: %d < 0", @@ -4489,6 +4651,17 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo } } + /* + * if it has no path resolve it + */ + if (strchr(cmd, '/') == NULL) { + path = resolve_path(cmd); + if (path != NULL) { + free(cmd); + cmd = path; + } + } + /* * flush stdio as needed * @@ -4500,29 +4673,28 @@ pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *fo /* * establish the open pipe to the shell command */ - dbg(DBG_HIGH, "about to perform: popen(\"%s\", \"%s\")", cmd, write_mode?"w":"r"); - errno = 0; /* pre-clear errno for errp() */ - stream = popen(cmd, write_mode?"w":"r"); + dbg(DBG_HIGH, "about to perform: popen(\"%s\", \"%s\")", cmd, write_mode ? "w" : "r"); + errno = 0; /* pre-clear errno for errp() */ + stream = popen(cmd, write_mode ? "w" : "r"); if (stream == NULL) { - /* exit or error return depending on abort_on_error */ - if (abort_on_error) { - errp(194, name, "error calling popen(\"%s\", \"%s\")", cmd, write_mode?"w":"r"); - not_reached(); - } else { + if (abort_on_error) { + errp(156, name, "error calling popen(\"%s\", \"%s\")", cmd, write_mode ? "w" : "r"); + not_reached(); + } else { saved_errno = errno; - dbg(DBG_MED, "called from %s: error calling popen(\"%s\", \"%s\"): %s", name, cmd, write_mode?"w":"r", - strerror(errno)); - va_end(ap); /* stdarg variable argument list cleanup */ - /* free allocated command storage */ - if (cmd != NULL) { - free(cmd); - cmd = NULL; - } + dbg(DBG_MED, "called from %s: error calling popen(\"%s\", \"%s\"): %s", name, cmd, write_mode ? "w" : "r", + strerror(errno)); + va_end(ap); /* stdarg variable argument list cleanup */ + if (cmd != NULL) { + free(cmd); + cmd = NULL; + } errno = saved_errno; - return NULL; - } + return NULL; + } } + /* * set stream to line buffered */ @@ -4585,7 +4757,7 @@ para(char const *line, ...) * firewall */ if (stdout == NULL) { - err(195, __func__, "stdout is NULL"); + err(157, __func__, "stdout is NULL"); not_reached(); } clearerr(stdout); /* pre-clear ferror() status */ @@ -4595,7 +4767,7 @@ para(char const *line, ...) */ fd = fileno(stdout); if (fd < 0) { - errp(196, __func__, "fileno on stdout returned: %d < 0", fd); + errp(158, __func__, "fileno on stdout returned: %d < 0", fd); not_reached(); } clearerr(stdout); /* paranoia */ @@ -4614,13 +4786,13 @@ para(char const *line, ...) ret = fputs(line, stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(197, __func__, "error writing paragraph to a stdout"); + errp(159, __func__, "error writing paragraph to a stdout"); not_reached(); } else if (feof(stdout)) { - err(198, __func__, "EOF while writing paragraph to a stdout"); + err(160, __func__, "EOF while writing paragraph to a stdout"); not_reached(); } else { - errp(199, __func__, "unexpected fputs error writing paragraph to stdout"); + errp(161, __func__, "unexpected fputs error writing paragraph to stdout"); not_reached(); } } @@ -4633,13 +4805,13 @@ para(char const *line, ...) ret = fputc('\n', stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(200, __func__, "error writing newline to stdout"); + errp(162, __func__, "error writing newline to stdout"); not_reached(); } else if (feof(stdout)) { - err(201, __func__, "EOF while writing newline to stdout"); + err(163, __func__, "EOF while writing newline to stdout"); not_reached(); } else { - errp(202, __func__, "unexpected fputc error writing newline to stdout"); + errp(164, __func__, "unexpected fputc error writing newline to stdout"); not_reached(); } } @@ -4664,13 +4836,13 @@ para(char const *line, ...) ret = fflush(stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(203, __func__, "error flushing stdout"); + errp(165, __func__, "error flushing stdout"); not_reached(); } else if (feof(stdout)) { - err(204, __func__, "EOF while flushing stdout"); + err(166, __func__, "EOF while flushing stdout"); not_reached(); } else { - errp(205, __func__, "unexpected fflush error while flushing stdout"); + errp(167, __func__, "unexpected fflush error while flushing stdout"); not_reached(); } } @@ -4713,7 +4885,7 @@ fpara(FILE * stream, char const *line, ...) * firewall */ if (stream == NULL) { - err(206, __func__, "stream is NULL"); + err(168, __func__, "stream is NULL"); not_reached(); } @@ -4724,7 +4896,7 @@ fpara(FILE * stream, char const *line, ...) errno = 0; /* pre-clear errno for errp() */ fd = fileno(stream); if (fd < 0) { - errp(207, __func__, "fileno on stream returned: %d < 0", fd); + errp(169, __func__, "fileno on stream returned: %d < 0", fd); not_reached(); } clearerr(stream); /* paranoia */ @@ -4743,13 +4915,13 @@ fpara(FILE * stream, char const *line, ...) ret = fputs(line, stream); if (ret == EOF) { if (ferror(stream)) { - errp(208, __func__, "error writing paragraph to stream"); + errp(170, __func__, "error writing paragraph to stream"); not_reached(); } else if (feof(stream)) { - err(209, __func__, "EOF while writing paragraph to stream"); + err(171, __func__, "EOF while writing paragraph to stream"); not_reached(); } else { - errp(210, __func__, "unexpected fputs error writing paragraph to stream"); + errp(172, __func__, "unexpected fputs error writing paragraph to stream"); not_reached(); } } @@ -4762,13 +4934,13 @@ fpara(FILE * stream, char const *line, ...) ret = fputc('\n', stream); if (ret == EOF) { if (ferror(stream)) { - errp(211, __func__, "error writing newline to stream"); + errp(173, __func__, "error writing newline to stream"); not_reached(); } else if (feof(stream)) { - err(212, __func__, "EOF while writing newline to stream"); + err(174, __func__, "EOF while writing newline to stream"); not_reached(); } else { - errp(213, __func__, "unexpected fputc error writing newline to stream"); + errp(175, __func__, "unexpected fputc error writing newline to stream"); not_reached(); } } @@ -4793,13 +4965,13 @@ fpara(FILE * stream, char const *line, ...) ret = fflush(stream); if (ret == EOF) { if (ferror(stream)) { - errp(214, __func__, "error flushing stream"); + errp(176, __func__, "error flushing stream"); not_reached(); } else if (feof(stream)) { - err(215, __func__, "EOF while flushing stream"); + err(177, __func__, "EOF while flushing stream"); not_reached(); } else { - errp(216, __func__, "unexpected fflush error while flushing stream"); + errp(178, __func__, "unexpected fflush error while flushing stream"); not_reached(); } } @@ -4993,7 +5165,7 @@ readline(char **linep, FILE * stream) * firewall */ if (linep == NULL || stream == NULL) { - err(217, __func__, "called with NULL arg(s)"); + err(179, __func__, "called with NULL arg(s)"); not_reached(); } @@ -5008,10 +5180,10 @@ readline(char **linep, FILE * stream) dbg(DBG_VVHIGH, "EOF detected in getline"); return -1; /* EOF found */ } else if (ferror(stream)) { - errp(218, __func__, "getline() error"); + errp(180, __func__, "getline() error"); not_reached(); } else { - errp(219, __func__, "unexpected getline() error"); + errp(181, __func__, "unexpected getline() error"); not_reached(); } } @@ -5019,7 +5191,7 @@ readline(char **linep, FILE * stream) * paranoia */ if (*linep == NULL) { - err(220, __func__, "*linep is NULL after getline()"); + err(182, __func__, "*linep is NULL after getline()"); not_reached(); } @@ -5075,7 +5247,7 @@ readline_dup(char **linep, bool strip, size_t *lenp, FILE *stream) * firewall */ if (linep == NULL || stream == NULL) { - err(221, __func__, "called with NULL arg(s)"); + err(183, __func__, "called with NULL arg(s)"); not_reached(); } @@ -5097,7 +5269,7 @@ readline_dup(char **linep, bool strip, size_t *lenp, FILE *stream) errno = 0; /* pre-clear errno for errp() */ ret = calloc((size_t)len+1+1, sizeof(char)); if (ret == NULL) { - errp(222, __func__, "calloc of read line of %jd bytes failed", (intmax_t)len+1+1); + errp(184, __func__, "calloc of read line of %jd bytes failed", (intmax_t)len+1+1); not_reached(); } memcpy(ret, *linep, (size_t)len); @@ -5200,7 +5372,7 @@ read_all(FILE *stream, size_t *psize) * firewall */ if (stream == NULL) { - err(223, __func__, "called with NULL stream"); + err(185, __func__, "called with NULL stream"); not_reached(); } @@ -5364,18 +5536,18 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * firewall */ if (src == NULL) { - err(224, __func__, "src path is NULL"); + err(186, __func__, "src path is NULL"); not_reached(); } else if (*src == '\0') { - err(225, __func__, "src path is empty string"); + err(187, __func__, "src path is empty string"); not_reached(); } if (dest == NULL) { - err(226, __func__, "dest path is NULL"); + err(188, __func__, "dest path is NULL"); not_reached(); } else if (*dest == '\0') { - err(227, __func__, "dest path is empty string"); + err(189, __func__, "dest path is empty string"); not_reached(); } @@ -5383,13 +5555,13 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * verify that src file exists */ if (!exists(src)) { - err(228, __func__, "src file does not exist: %s", src); + err(190, __func__, "src file does not exist: %s", src); not_reached(); } else if (!is_file(src)) { - err(229, __func__, "src file is not a regular file: %s", src); + err(191, __func__, "src file is not a regular file: %s", src); not_reached(); } else if (!is_read(src)) { - err(230, __func__, "src file is not readable: %s", src); + err(192, __func__, "src file is not readable: %s", src); not_reached(); } @@ -5397,7 +5569,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * verify dest path does NOT exist */ if (exists(dest)) { - err(231, __func__, "dest file already exists: %s", dest); + err(193, __func__, "dest file already exists: %s", dest); not_reached(); } @@ -5407,7 +5579,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ in_file = fopen(src, "rb"); if (in_file == NULL) { - errp(232, __func__, "couldn't open src file %s for reading: %s", src, strerror(errno)); + errp(194, __func__, "couldn't open src file %s for reading: %s", src, strerror(errno)); not_reached(); } @@ -5417,7 +5589,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ infd = open(src, O_RDONLY|O_CLOEXEC, S_IRWXU); if (infd < 0) { - errp(233, __func__, "failed to obtain file descriptor for %s: %s", src, strerror(errno)); + errp(195, __func__, "failed to obtain file descriptor for %s: %s", src, strerror(errno)); not_reached(); } @@ -5427,7 +5599,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fstat(infd, &in_st); if (ret < 0) { - errp(234, __func__, "failed to get stat info for %s, stat returned: %s", src, strerror(errno)); + errp(196, __func__, "failed to get stat info for %s, stat returned: %s", src, strerror(errno)); not_reached(); } @@ -5441,7 +5613,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) */ buf = read_all(in_file, &inbytes); if (buf == NULL) { - err(235, __func__, "couldn't read in src file: %s", src); + err(197, __func__, "couldn't read in src file: %s", src); not_reached(); } @@ -5453,7 +5625,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fclose(in_file); if (ret < 0) { - errp(236, __func__, "fclose error for %s: %s", src, strerror(errno)); + errp(198, __func__, "fclose error for %s: %s", src, strerror(errno)); not_reached(); } @@ -5467,7 +5639,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) free(buf); buf = NULL; } - errp(237, __func__, "couldn't open dest file %s for writing: %s", dest, strerror(errno)); + errp(199, __func__, "couldn't open dest file %s for writing: %s", dest, strerror(errno)); not_reached(); } @@ -5477,7 +5649,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ outfd = open(dest, O_WRONLY|O_CLOEXEC, S_IRWXU); if (outfd < 0) { - errp(238, __func__, "failed to obtain file descriptor for %s: %s", dest, strerror(errno)); + errp(200, __func__, "failed to obtain file descriptor for %s: %s", dest, strerror(errno)); not_reached(); } @@ -5488,7 +5660,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for warnp() */ outbytes = fwrite(buf, 1, inbytes, out_file); if (outbytes != inbytes) { - errp(239, __func__, "error: wrote %ju bytes out of expected %ju bytes", + errp(201, __func__, "error: wrote %ju bytes out of expected %ju bytes", (uintmax_t)outbytes, (uintmax_t)inbytes); not_reached(); } else { @@ -5502,7 +5674,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fclose(out_file); if (ret < 0) { - errp(240, __func__, "fclose error for %s: %s", dest, strerror(errno)); + errp(202, __func__, "fclose error for %s: %s", dest, strerror(errno)); not_reached(); } @@ -5517,7 +5689,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) free(buf); buf = NULL; } - err(241, __func__, "couldn't open dest file for reading: %s: %s", dest, strerror(errno)); + err(203, __func__, "couldn't open dest file for reading: %s: %s", dest, strerror(errno)); not_reached(); } @@ -5535,7 +5707,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) */ copy = read_all(out_file, &inbytes); if (copy == NULL) { - err(242, __func__, "couldn't read in dest file: %s", dest); + err(204, __func__, "couldn't read in dest file: %s", dest); not_reached(); } @@ -5547,7 +5719,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fclose(out_file); if (ret < 0) { - errp(243, __func__, "fclose error for %s: %s", dest, strerror(errno)); + errp(205, __func__, "fclose error for %s: %s", dest, strerror(errno)); not_reached(); } @@ -5555,7 +5727,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * first check that the bytes read in is the same as the bytes written */ if (outbytes != inbytes) { - err(244, __func__, "error: read %ju bytes out of expected %ju bytes", + err(206, __func__, "error: read %ju bytes out of expected %ju bytes", (uintmax_t)inbytes, (uintmax_t)outbytes); not_reached(); } else { @@ -5568,7 +5740,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * buffer from the dest file (copy of src file) */ if (memcmp(copy, buf, inbytes) != 0) { - err(245, __func__, "copy of src file %s is not the same as the contents of the dest file %s", src, dest); + err(207, __func__, "copy of src file %s is not the same as the contents of the dest file %s", src, dest); not_reached(); } else { dbg(DBG_HIGH, "copy of src file %s is identical to dest file %s", src, dest); @@ -5597,7 +5769,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fchmod(outfd, in_st.st_mode); if (ret != 0) { - errp(246, __func__, "fchmod(2) failed to set source file %s mode %o on %s: %s", src, in_st.st_mode, + errp(208, __func__, "fchmod(2) failed to set source file %s mode %o on %s: %s", src, in_st.st_mode, dest, strerror(errno)); not_reached(); } @@ -5608,7 +5780,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fstat(outfd, &out_st); if (ret != 0) { - errp(247, __func__, "failed to get stat info for %s, stat returned: %s", dest, strerror(errno)); + errp(209, __func__, "failed to get stat info for %s, stat returned: %s", dest, strerror(errno)); not_reached(); } @@ -5616,7 +5788,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) * we now need to verify that the modes are the same */ if (in_st.st_mode != out_st.st_mode) { - err(248, __func__, "failed to copy st_mode %o from %s to %s: %o != %o", in_st.st_mode, src, dest, in_st.st_mode, + err(210, __func__, "failed to copy st_mode %o from %s to %s: %o != %o", in_st.st_mode, src, dest, in_st.st_mode, out_st.st_mode); not_reached(); } @@ -5627,7 +5799,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear errno for errp() */ ret = fchmod(outfd, mode); if (ret != 0) { - errp(249, __func__, "fchmod(2) failed to set requested mode on %s: %s", dest, strerror(errno)); + errp(211, __func__, "fchmod(2) failed to set requested mode on %s: %s", dest, strerror(errno)); not_reached(); } @@ -5654,7 +5826,7 @@ copyfile(char const *src, char const *dest, bool copy_mode, mode_t mode) errno = 0; /* pre-clear for errp() */ ret = close(outfd); if (ret < 0) { - errp(10, __func__, "close(outfd) failed: %s", strerror(errno)); + errp(212, __func__, "close(outfd) failed: %s", strerror(errno)); not_reached(); } @@ -5705,7 +5877,7 @@ touch(char const *path, mode_t mode) errno = 0; /* pre-clear errno for errp() */ fd = open(path, O_CREAT | O_WRONLY, mode); if (fd < 0) { - errp(11, __func__, "failed to create file: %s", path); + errp(213, __func__, "failed to create file: %s", path); not_reached(); } @@ -5716,7 +5888,7 @@ touch(char const *path, mode_t mode) */ errno = 0; /* pre-clear errno for errp() */ if (close(fd) != 0) { - errp(12, __func__, "failed to close newly created file: %s", path); + errp(214, __func__, "failed to close newly created file: %s", path); not_reached(); } } @@ -5764,7 +5936,7 @@ touchat(char const *path, mode_t mode, char const *dir, int dirfd) errno = 0; /* pre-clear errno for errp() */ cwd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (cwd < 0) { - errp(13, __func__, "cannot open ."); + errp(215, __func__, "cannot open ."); not_reached(); } @@ -5774,18 +5946,18 @@ touchat(char const *path, mode_t mode, char const *dir, int dirfd) if (dirfd >= 0) { errno = 0; /* pre-clear errno for errp() */ if (fchdir(dirfd) != 0) { - errp(14, __func__, "both chdir(2) and fchdir(2) failed"); + errp(216, __func__, "both chdir(2) and fchdir(2) failed"); not_reached(); } } else { - errp(15, __func__, "chdir(2) failed"); + errp(217, __func__, "chdir(2) failed"); not_reached(); } } } else if (dirfd >= 0) { errno = 0; /* pre-clear errno for errp() */ if (fchdir(dirfd) != 0) { - errp(16, __func__, "fchdir(2) failed"); + errp(218, __func__, "fchdir(2) failed"); not_reached(); } } @@ -5803,7 +5975,7 @@ touchat(char const *path, mode_t mode, char const *dir, int dirfd) */ errno = 0; /* pre-clear errno for errp() */ if (fchdir(cwd) != 0) { - errp(17, __func__, "failed to fchdir(2) back to original directory"); + errp(219, __func__, "failed to fchdir(2) back to original directory"); not_reached(); } @@ -5812,7 +5984,7 @@ touchat(char const *path, mode_t mode, char const *dir, int dirfd) */ errno = 0; /* pre-clear errno for errp() */ if (close(cwd) != 0) { - errp(18, __func__, "failed to close(cwd)"); + errp(220, __func__, "failed to close(cwd)"); not_reached(); } } @@ -5852,20 +6024,20 @@ mkdirs(int dirfd, const char *str, mode_t mode) * firewall */ if (str == NULL) { - err(19, __func__, "str (path) is NULL"); + err(221, __func__, "str (path) is NULL"); not_reached(); } len = strlen(str); if (len <= 0) { - err(20, __func__, "str (path) is empty"); + err(222, __func__, "str (path) is empty"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ dup = strdup(str); if (dup == NULL) { - errp(21, __func__, "duplicating \"%s\" failed", str); + errp(223, __func__, "duplicating \"%s\" failed", str); not_reached(); } @@ -5878,7 +6050,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) errno = 0; /* pre-clear errno for errp() */ cwd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (cwd < 0) { - errp(22, __func__, "cannot open ."); + errp(224, __func__, "cannot open ."); not_reached(); } @@ -5894,7 +6066,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp() */ if (fchdir(dirfd) != 0) { - errp(23, __func__, "failed to change to parent directory"); + errp(225, __func__, "failed to change to parent directory"); not_reached(); } @@ -5909,7 +6081,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) errno = 0; /* pre-clear errno for errp() */ if (mkdir(dup, 0) != 0) { if (errno != EEXIST) { - errp(24, __func__, "mkdir() of %s failed with: %s", dup, strerror(errno)); + errp(226, __func__, "mkdir() of %s failed with: %s", dup, strerror(errno)); not_reached(); } else { /* @@ -5917,7 +6089,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(dup, mode) != 0) { - errp(25, __func__, "chmod(\"%s\", %o) failed", dup, mode); + errp(227, __func__, "chmod(\"%s\", %o) failed", dup, mode); not_reached(); } else { dbg(DBG_HIGH, "set modes %o on %s", mode, dup); @@ -5930,7 +6102,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(dup, mode) != 0) { - errp(26, __func__, "chmod(\"%s\", %o) failed", dup, mode); + errp(228, __func__, "chmod(\"%s\", %o) failed", dup, mode); not_reached(); } else { dbg(DBG_HIGH, "set modes %o on %s", mode, dup); @@ -5947,7 +6119,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) errno = 0; /* pre-clear errno for errp() */ if (mkdir(p, 0) != 0) { if (errno != EEXIST) { - errp(27, __func__, "mkdir() of %s failed with: %s", p, strerror(errno)); + errp(229, __func__, "mkdir() of %s failed with: %s", p, strerror(errno)); not_reached(); } else { /* @@ -5955,7 +6127,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(dup, mode) != 0) { - errp(28, __func__, "chmod(\"%s\", %o) failed", dup, mode); + errp(230, __func__, "chmod(\"%s\", %o) failed", dup, mode); not_reached(); } else { dbg(DBG_HIGH, "set mode %o on %s", mode, dup); @@ -5968,7 +6140,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(dup, mode) != 0) { - errp(29, __func__, "chmod(\"%s\", %o) failed", dup, mode); + errp(231, __func__, "chmod(\"%s\", %o) failed", dup, mode); not_reached(); } else { dbg(DBG_HIGH, "set mode %o on %s", mode, dup); @@ -5980,7 +6152,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp() */ if (chdir(p) != 0) { - errp(30, __func__, "failed to change to %s", p); + errp(232, __func__, "failed to change to %s", p); not_reached(); } @@ -5991,7 +6163,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) errno = 0; /* pre-clear errno for errp() */ if (mkdir(p, 0) != 0) { if (errno != EEXIST) { - errp(31, __func__, "mkdir() of %s failed with: %s", p, strerror(errno)); + errp(233, __func__, "mkdir() of %s failed with: %s", p, strerror(errno)); not_reached(); } else { /* @@ -5999,7 +6171,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(p, mode) != 0) { - errp(32, __func__, "chmod(\"%s\", %o) failed", p, mode); + errp(234, __func__, "chmod(\"%s\", %o) failed", p, mode); not_reached(); } else { dbg(DBG_HIGH, "set mode %o on %s", mode, p); @@ -6011,7 +6183,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp */ if (chmod(p, mode) != 0) { - errp(33, __func__, "chmod(\"%s\", %o) failed", p, mode); + errp(235, __func__, "chmod(\"%s\", %o) failed", p, mode); not_reached(); } else { dbg(DBG_HIGH, "set mode %o on %s", mode, p); @@ -6020,7 +6192,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) errno = 0; /* pre-clear errno for errp() */ dir = chdir(p); if (dir < 0) { - errp(34, __func__, "failed to open directory %s", p); + errp(236, __func__, "failed to open directory %s", p); not_reached(); } } @@ -6031,7 +6203,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp() */ if (fchdir(cwd) != 0) { - errp(35, __func__, "failed to change back to previous directory"); + errp(237, __func__, "failed to change back to previous directory"); not_reached(); } @@ -6040,7 +6212,7 @@ mkdirs(int dirfd, const char *str, mode_t mode) */ errno = 0; /* pre-clear errno for errp() */ if (close(cwd) != 0) { - errp(36, __func__, "failed to close(cwd): %s", strerror(errno)); + errp(238, __func__, "failed to close(cwd): %s", strerror(errno)); not_reached(); } @@ -7199,7 +7371,7 @@ sane_relative_path(char const *str, uintmax_t max_path_len, uintmax_t max_filena errno = 0; /* pre-clear errno for errp() */ dup = strdup(str); if (dup == NULL) { - errp(37, __func__, "duplicating \"%s\" failed", str); + errp(239, __func__, "duplicating \"%s\" failed", str); not_reached(); } @@ -7538,18 +7710,18 @@ path_has_component(char const *path, char const *name) * firewall */ if (path == NULL) { - err(38, __func__, "path is NULL"); + err(240, __func__, "path is NULL"); not_reached(); } if (name == NULL) { - err(39, __func__, "name is NULL"); + err(241, __func__, "name is NULL"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ path_dup = strdup(path); if (path_dup == NULL) { - errp(40, __func__, "duplicating %s failed", path); + errp(242, __func__, "duplicating %s failed", path); not_reached(); } @@ -7606,7 +7778,7 @@ posix_safe_chk(char const *str, size_t len, bool *slash, bool *posix_safe, bool * firewall */ if (str == NULL || slash == NULL || posix_safe == NULL || first_alphanum == NULL || upper == NULL) { - err(41, __func__, "called with NULL arg(s)"); + err(243, __func__, "called with NULL arg(s)"); not_reached(); } @@ -8695,7 +8867,7 @@ calloc_path(char const *dirname, char const *filename) * firewall */ if (filename == NULL) { - err(42, __func__, "filename is NULL"); + err(244, __func__, "filename is NULL"); not_reached(); } @@ -8712,7 +8884,7 @@ calloc_path(char const *dirname, char const *filename) errno = 0; /* pre-clear errno for errp() */ buf = strdup(filename); if (buf == NULL) { - errp(43, __func__, "strdup of filename failed: %s", filename); + errp(245, __func__, "strdup of filename failed: %s", filename); not_reached(); } @@ -8730,7 +8902,7 @@ calloc_path(char const *dirname, char const *filename) buf = calloc(len+2, sizeof(char)); /* + 1 for paranoia padding */ errno = 0; /* pre-clear errno for errp() */ if (buf == NULL) { - errp(44, __func__, "calloc of %ju bytes failed", (uintmax_t)len); + errp(246, __func__, "calloc of %ju bytes failed", (uintmax_t)len); not_reached(); } @@ -8750,7 +8922,7 @@ calloc_path(char const *dirname, char const *filename) errno = 0; /* pre-clear errno for errp() */ ret = snprintf(buf, len, "%s/%s", dirname, filename); if (ret < 0) { - errp(45, __func__, "snprintf returned: %zu < 0", len); + errp(247, __func__, "snprintf returned: %zu < 0", len); not_reached(); } } @@ -8759,7 +8931,7 @@ calloc_path(char const *dirname, char const *filename) * return malloc path */ if (buf == NULL) { - errp(46, __func__, "function attempted to return NULL"); + errp(248, __func__, "function attempted to return NULL"); not_reached(); } return buf; @@ -8798,7 +8970,7 @@ open_dir_file(char const *dir, char const *file) * firewall */ if (file == NULL) { - err(47, __func__, "called with NULL file"); + err(249, __func__, "called with NULL file"); not_reached(); } @@ -8809,7 +8981,7 @@ open_dir_file(char const *dir, char const *file) errno = 0; /* pre-clear errno for errp() */ cwd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (cwd < 0) { - errp(48, __func__, "cannot open ."); + errp(10, __func__, "cannot open ."); not_reached(); } @@ -8822,15 +8994,15 @@ open_dir_file(char const *dir, char const *file) * check if we can search / work within the directory */ if (!exists(dir)) { - err(49, __func__, "directory does not exist: %s", dir); + err(11, __func__, "directory does not exist: %s", dir); not_reached(); } if (!is_dir(dir)) { - err(50, __func__, "is not a directory: %s", dir); + err(12, __func__, "is not a directory: %s", dir); not_reached(); } if (!is_exec(dir)) { - err(51, __func__, "directory is not searchable: %s", dir); + err(13, __func__, "directory is not searchable: %s", dir); not_reached(); } @@ -8840,7 +9012,7 @@ open_dir_file(char const *dir, char const *file) errno = 0; /* pre-clear errno for errp() */ ret = chdir(dir); if (ret < 0) { - errp(52, __func__, "cannot cd %s", dir); + errp(14, __func__, "cannot cd %s", dir); not_reached(); } } @@ -8849,15 +9021,15 @@ open_dir_file(char const *dir, char const *file) * must be a readable file */ if (!exists(file)) { - err(53, __func__, "file does not exist: %s", file); + err(15, __func__, "file does not exist: %s", file); not_reached(); } if (!is_file(file)) { - err(54, __func__, "file is not a regular file: %s", file); + err(16, __func__, "file is not a regular file: %s", file); not_reached(); } if (!is_read(file)) { - err(55, __func__, "file is not a readable file: %s", file); + err(17, __func__, "file is not a readable file: %s", file); not_reached(); } @@ -8867,7 +9039,7 @@ open_dir_file(char const *dir, char const *file) errno = 0; /* pre-clear errno for errp() */ ret_stream = fopen(file, "r"); if (ret_stream == NULL) { - errp(56, __func__, "cannot open file: %s", file); + errp(18, __func__, "cannot open file: %s", file); not_reached(); } @@ -8882,13 +9054,13 @@ open_dir_file(char const *dir, char const *file) errno = 0; /* pre-clear errno for errp() */ ret = fchdir(cwd); if (ret < 0) { - errp(57, __func__, "cannot fchdir to the previous current directory"); + errp(19, __func__, "cannot fchdir to the previous current directory"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = close(cwd); if (ret < 0) { - errp(58, __func__, "close of previous current directory failed"); + errp(20, __func__, "close of previous current directory failed"); not_reached(); } } @@ -8920,7 +9092,7 @@ count_char(char const *str, int ch) * firewall */ if (str == NULL) { - err(59, __func__, "given NULL str"); + err(21, __func__, "given NULL str"); not_reached(); } @@ -8997,7 +9169,7 @@ check_invalid_option(char const *prog, int ch, int opt) */ #include "../json_utf8.h" -#define UTIL_TEST_VERSION "2.0.1 2025-03-02" /* version format: major.minor YYYY-MM-DD */ +#define UTIL_TEST_VERSION "2.0.2 2025-03-09" /* version format: major.minor YYYY-MM-DD */ int main(int argc, char **argv) @@ -9037,7 +9209,7 @@ main(int argc, char **argv) while ((i = getopt(argc, argv, ":hv:J:Vqe:")) != -1) { switch (i) { case 'h': /* -h - write help, to stderr and exit 0 */ - fprintf_usage(60, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, + fprintf_usage(22, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, JPARSE_LIBRARY_VERSION); /*ooo*/ not_reached(); break; @@ -9083,19 +9255,19 @@ main(int argc, char **argv) break; case ':': (void) fprintf(stderr, "%s: requires an argument -- %c\n\n", program, optopt); - fprintf_usage(61, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, + fprintf_usage(23, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, JPARSE_LIBRARY_VERSION); /*ooo*/ not_reached(); break; case '?': (void) fprintf(stderr, "%s: illegal option -- %c\n\n", program, optopt); - fprintf_usage(62, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, + fprintf_usage(24, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, JPARSE_LIBRARY_VERSION); /*ooo*/ not_reached(); break; default: fprintf_usage(DO_NOT_EXIT, stderr, "invalid -flag"); - fprintf_usage(63, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, + fprintf_usage(25, stderr, usage, program, UTIL_TEST_VERSION, JPARSE_UTILS_VERSION, JPARSE_UTF8_VERSION, JPARSE_LIBRARY_VERSION); /*ooo*/ not_reached(); } @@ -9132,10 +9304,10 @@ main(int argc, char **argv) errno = 0; /* pre-clear errno for errp() */ buf = calloc_path(dirname, filename); if (buf == NULL) { - errp(64, __func__, "calloc_path(\"%s\", \"%s\") returned NULL", dirname, filename); + errp(26, __func__, "calloc_path(\"%s\", \"%s\") returned NULL", dirname, filename); not_reached(); } else if (strcmp(buf, "foo/bar") != 0) { - err(65, __func__, "buf: %s != %s/%s", buf, dirname, filename); + err(27, __func__, "buf: %s != %s/%s", buf, dirname, filename); not_reached(); } else { fdbg(stderr, DBG_MED, "calloc_path(\"%s\", \"%s\"): returned %s", dirname, filename, buf); @@ -9156,10 +9328,10 @@ main(int argc, char **argv) errno = 0; /* pre-clear errno for errp() */ buf = calloc_path(dirname, filename); if (buf == NULL) { - errp(66, __func__, "calloc_path(NULL, \"%s\") returned NULL", filename); + errp(28, __func__, "calloc_path(NULL, \"%s\") returned NULL", filename); not_reached(); } else if (strcmp(buf, "bar") != 0) { - err(67, __func__, "buf: %s != %s", buf, filename); + err(29, __func__, "buf: %s != %s", buf, filename); not_reached(); } else { fdbg(stderr, DBG_MED, "calloc_path(NULL, \"%s\"): returned %s", filename, buf); @@ -9191,7 +9363,7 @@ main(int argc, char **argv) */ sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_OK) { - err(68, __func__, "sane_relative_path(\"%s\", 99, 25, 4, fale): expected PATH_OK, got: %s", + err(30, __func__, "sane_relative_path(\"%s\", 99, 25, 4, fale): expected PATH_OK, got: %s", relpath, path_sanity_name(sanity)); /*coo*/ not_reached(); } else { @@ -9204,7 +9376,7 @@ main(int argc, char **argv) relpath = "foo/bar"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_OK) { - err(69, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_OK, got: %s", + err(31, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_OK, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9217,7 +9389,7 @@ main(int argc, char **argv) relpath = ""; sanity = sane_relative_path(relpath, 99, 25, 2, false); if (sanity != PATH_ERR_PATH_EMPTY) { - err(70, __func__, "sane_relative_path(\"%s\", 99, 25, 2, false): expected PATH_ERR_PATH_EMPTY, got: %s", + err(32, __func__, "sane_relative_path(\"%s\", 99, 25, 2, false): expected PATH_ERR_PATH_EMPTY, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9230,7 +9402,7 @@ main(int argc, char **argv) relpath = "foo/bar/baz"; sanity =sane_relative_path(relpath, 2, 99, 2, false); if (sanity != PATH_ERR_PATH_TOO_LONG) { - err(71, __func__, "sane_relative_path(\"%s\", 2, 99, 2, false): expected PATH_ERR_PATH_TOO_LONG, got: %s", + err(33, __func__, "sane_relative_path(\"%s\", 2, 99, 2, false): expected PATH_ERR_PATH_TOO_LONG, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9243,7 +9415,7 @@ main(int argc, char **argv) relpath = "foo/bar/baz"; sanity =sane_relative_path(relpath, 0, 25, 2, false); if (sanity != PATH_ERR_MAX_PATH_LEN_0) { - err(72, __func__, "sane_relative_path(\"%s\", 0, 25, 2, false): expected PATH_ERR_MAX_PATH_LEN_0, got: %s", + err(34, __func__, "sane_relative_path(\"%s\", 0, 25, 2, false): expected PATH_ERR_MAX_PATH_LEN_0, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9256,7 +9428,7 @@ main(int argc, char **argv) relpath = "foo/bar/baz"; sanity = sane_relative_path(relpath, 99, 25, 0, false); if (sanity != PATH_ERR_MAX_DEPTH_0) { - err(73, __func__, "sane_relative_path(\"%s\", 99, 25, 0, false): expected PATH_ERR_MAX_DEPTH_0, got: %s", + err(35, __func__, "sane_relative_path(\"%s\", 99, 25, 0, false): expected PATH_ERR_MAX_DEPTH_0, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9269,7 +9441,7 @@ main(int argc, char **argv) relpath = "/foo"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_ERR_NOT_RELATIVE) { - err(74, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_RELATIVE, got: %s", + err(36, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_RELATIVE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9282,7 +9454,7 @@ main(int argc, char **argv) relpath = "aequeosalinocalcalinoceraceoaluminosocupreovitriolic"; /* 52 letter word recognised by some */ sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_ERR_NAME_TOO_LONG) { - err(75, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NAME_TOO_LONG, got: %s", + err(37, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NAME_TOO_LONG, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9295,7 +9467,7 @@ main(int argc, char **argv) relpath = "foo"; sanity = sane_relative_path(relpath, 99, 0, 2, false); if (sanity != PATH_ERR_MAX_NAME_LEN_0) { - err(76, __func__, "sane_relative_path(\"%s\", 99, 0, 2, false): expected PATH_ERR_MAX_NAME_LEN_0, got: %s", + err(38, __func__, "sane_relative_path(\"%s\", 99, 0, 2, false): expected PATH_ERR_MAX_NAME_LEN_0, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9308,7 +9480,7 @@ main(int argc, char **argv) relpath = "foo/bar"; sanity = sane_relative_path(relpath, 99, 25, 1, false); if (sanity != PATH_ERR_PATH_TOO_DEEP) { - err(77, __func__, "sane_relative_path(\"%s\", 99, 25, 1, false): expected PATH_ERR_PATH_TOO_DEEP, got: %s", + err(39, __func__, "sane_relative_path(\"%s\", 99, 25, 1, false): expected PATH_ERR_PATH_TOO_DEEP, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9321,7 +9493,7 @@ main(int argc, char **argv) relpath = "foo/../"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_ERR_NOT_POSIX_SAFE) { - err(78, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", + err(40, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9334,7 +9506,7 @@ main(int argc, char **argv) relpath = "foo/./"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_ERR_NOT_POSIX_SAFE) { - err(79, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", + err(41, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9347,7 +9519,7 @@ main(int argc, char **argv) relpath = "./foo/"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_ERR_NOT_POSIX_SAFE) { - err(80, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", + err(42, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9360,7 +9532,7 @@ main(int argc, char **argv) relpath = "foo1"; sanity = sane_relative_path(relpath, 99, 25, 4, false); if (sanity != PATH_OK) { - err(81, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_OK, got: %s", + err(43, __func__, "sane_relative_path(\"%s\", 99, 25, 4, false): expected PATH_OK, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9373,7 +9545,7 @@ main(int argc, char **argv) relpath = "a/b/c/d"; sanity = sane_relative_path(relpath, 99, 25, 3, false); if (sanity != PATH_ERR_PATH_TOO_DEEP) { - err(82, __func__, "sane_relative_path(\"%s\", 99, 25, 3, false): expected PATH_ERR_PATH_TOO_DEEP, got: %s", + err(44, __func__, "sane_relative_path(\"%s\", 99, 25, 3, false): expected PATH_ERR_PATH_TOO_DEEP, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9386,7 +9558,7 @@ main(int argc, char **argv) relpath = "./foo"; sanity = sane_relative_path(relpath, 99, 25, 3, true); if (sanity != PATH_OK) { - err(83, __func__, "sane_relative_path(\"%s\", 99, 25, 3, true): expected PATH_OK, got: %s", + err(45, __func__, "sane_relative_path(\"%s\", 99, 25, 3, true): expected PATH_OK, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9399,7 +9571,7 @@ main(int argc, char **argv) relpath = "./foo"; sanity = sane_relative_path(relpath, 99, 25, 3, false); if (sanity != PATH_ERR_NOT_POSIX_SAFE) { - err(84, __func__, "sane_relative_path(\"%s\", 99, 25, 3, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", + err(46, __func__, "sane_relative_path(\"%s\", 99, 25, 3, false): expected PATH_ERR_NOT_POSIX_SAFE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9414,7 +9586,7 @@ main(int argc, char **argv) relpath = ".//foo"; sanity = sane_relative_path(relpath, 99, 25, 3, true); if (sanity != PATH_ERR_NOT_RELATIVE) { - err(85, __func__, "sane_relative_path(\"%s\", 99, 25, 3, true): expected PATH_ERR_NOT_RELATIVE, got: %s", + err(47, __func__, "sane_relative_path(\"%s\", 99, 25, 3, true): expected PATH_ERR_NOT_RELATIVE, got: %s", relpath, path_sanity_name(sanity)); not_reached(); } else { @@ -9441,10 +9613,10 @@ main(int argc, char **argv) relpath = ""; name = dir_name(relpath, -1); if (name == NULL) { - err(86, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(48, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); - } else if (*name != '\0') { - err(87, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected an empty string", relpath, name); + } else if (strcmp(name, ".") != 0) { + err(49, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected empty string", relpath); @@ -9465,10 +9637,10 @@ main(int argc, char **argv) relpath = "//foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(88, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(50, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, relpath+2) != 0) { - err(89, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath+2); + err(51, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath+2); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"%s\"", relpath, relpath+2); @@ -9490,10 +9662,10 @@ main(int argc, char **argv) relpath = "//foo//foo//"; name = dir_name(relpath, -1); if (name == NULL) { - err(90, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(52, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(91, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); + err(53, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"foo\"", relpath); @@ -9514,10 +9686,10 @@ main(int argc, char **argv) relpath = "/foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(92, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(54, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(93, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); + err(55, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"foo\"", relpath); @@ -9538,10 +9710,10 @@ main(int argc, char **argv) relpath = "/foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(94, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(56, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(95, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); + err(57, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"foo\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"foo\"", relpath); @@ -9562,10 +9734,10 @@ main(int argc, char **argv) relpath = "///"; name = dir_name(relpath, -1); if (name == NULL) { - err(96, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(58, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "/") != 0) { - err(97, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"/\"", relpath, name); + err(59, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"/\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"/\"", relpath); @@ -9586,10 +9758,10 @@ main(int argc, char **argv) relpath = "///."; name = dir_name(relpath, -1); if (name == NULL) { - err(98, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(60, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, ".") != 0) { - err(99, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); + err(61, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \".\"", relpath); @@ -9610,10 +9782,10 @@ main(int argc, char **argv) relpath = "///../....//"; name = dir_name(relpath, -1); if (name == NULL) { - err(100, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(62, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "..") != 0) { - err(101, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"..\"", relpath, name); + err(63, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"..\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"..\"", relpath); @@ -9636,10 +9808,10 @@ main(int argc, char **argv) relpath = "foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(102, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(64, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, relpath) != 0) { - err(103, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath); + err(65, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"%s\"", relpath, relpath); @@ -9660,10 +9832,10 @@ main(int argc, char **argv) relpath = "./foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(104, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(66, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name,".") != 0) { - err(105, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); + err(67, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \".\"", relpath); @@ -9684,10 +9856,10 @@ main(int argc, char **argv) relpath = "./foo//"; name = dir_name(relpath, -1); if (name == NULL) { - err(106, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(68, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, ".") != 0) { - err(107, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); + err(69, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \".\"", relpath); @@ -9708,10 +9880,10 @@ main(int argc, char **argv) relpath = ".//foo/."; name = dir_name(relpath, -1); if (name == NULL) { - err(108, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(70, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, ".") != 0) { - err(109, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); + err(71, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \".\"", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \".\"", relpath); @@ -9732,10 +9904,10 @@ main(int argc, char **argv) relpath = "foo"; name = dir_name(relpath, -1); if (name == NULL) { - err(110, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(72, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, relpath) != 0) { - err(111, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath); + err(73, __func__, "dir_name(\"%s\", -1): returned \"%s\", expected \"%s\"", relpath, name, relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): got expected \"%s\"", relpath, relpath); @@ -9758,10 +9930,10 @@ main(int argc, char **argv) relpath = "/foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, -1); if (name == NULL) { - err(112, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(74, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(113, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); + err(75, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): %s", relpath, name); @@ -9782,10 +9954,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, -1); if (name == NULL) { - err(114, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(76, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(115, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); + err(77, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1): %s", relpath, name); @@ -9807,10 +9979,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 0); if (name == NULL) { - err(116, __func__, "dir_name(\"%s\", 0): returned NULL", relpath); + err(78, __func__, "dir_name(\"%s\", 0): returned NULL", relpath); not_reached(); } else if (strcmp(name, relpath) != 0) { - err(117, __func__, "dir_name(\"%s\", 0): returned %s, expected: %s", relpath, name, relpath); + err(79, __func__, "dir_name(\"%s\", 0): returned %s, expected: %s", relpath, name, relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 0): %s", relpath, relpath); @@ -9830,10 +10002,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 1); if (name == NULL) { - err(118, __func__, "dir_name(\"%s\", 1): returned NULL", relpath); + err(80, __func__, "dir_name(\"%s\", 1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo/bar/baz/zab/rab") != 0) { - err(119, __func__, "dir_name(\"%s\", 1): returned %s, expected: foo/bar/baz/zab/rab", relpath, name); + err(81, __func__, "dir_name(\"%s\", 1): returned %s, expected: foo/bar/baz/zab/rab", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 1) == foo/bar/baz/zab/rab", relpath); @@ -9849,10 +10021,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 2); if (name == NULL) { - err(120, __func__, "dir_name(\"%s\", 2): returned NULL", relpath); + err(82, __func__, "dir_name(\"%s\", 2): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo/bar/baz/zab") != 0) { - err(121, __func__, "dir_name(\"%s\", 2): returned %s, expected: foo/bar/baz/zab", relpath, name); + err(83, __func__, "dir_name(\"%s\", 2): returned %s, expected: foo/bar/baz/zab", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 2) == foo/bar/baz/zab", relpath); @@ -9868,10 +10040,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 3); if (name == NULL) { - err(122, __func__, "dir_name(\"%s\", 3): returned NULL", relpath); + err(84, __func__, "dir_name(\"%s\", 3): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo/bar/baz") != 0) { - err(123, __func__, "dir_name(\"%s\", 3): returned %s, expected: foo/bar/baz", relpath, name); + err(85, __func__, "dir_name(\"%s\", 3): returned %s, expected: foo/bar/baz", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 3) == foo/bar/baz", relpath); @@ -9887,10 +10059,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 4); if (name == NULL) { - err(124, __func__, "dir_name(\"%s\", 4): returned NULL", relpath); + err(86, __func__, "dir_name(\"%s\", 4): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo/bar") != 0) { - err(125, __func__, "dir_name(\"%s\", 4): returned %s, expected: foo/bar", relpath, name); + err(87, __func__, "dir_name(\"%s\", 4): returned %s, expected: foo/bar", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 4) == foo/bar", relpath); @@ -9906,10 +10078,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 5); if (name == NULL) { - err(126, __func__, "dir_name(\"%s\", 5): returned NULL", relpath); + err(88, __func__, "dir_name(\"%s\", 5): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(128, __func__, "dir_name(\"%s\", 5): returned %s, expected: foo", relpath, name); + err(89, __func__, "dir_name(\"%s\", 5): returned %s, expected: foo", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 5) == foo", relpath); @@ -9931,34 +10103,68 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, 6); if (name == NULL) { - err(129, __func__, "dir_name(\"%s\", 6): returned NULL", relpath); + err(90, __func__, "dir_name(\"%s\", 6): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(130, __func__, "dir_name(\"%s\", 6): returned %s, expected: foo", relpath, name); + err(91, __func__, "dir_name(\"%s\", 6): returned %s, expected: foo", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", 6) == foo", relpath); } - /* - * test remove -1 levels - */ if (name != NULL) { free(name); name = NULL; } + /* + * test remove -1 levels + */ relpath = "foo/bar/baz/zab/rab/oof"; name = dir_name(relpath, -1); if (name == NULL) { - err(131, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); + err(92, __func__, "dir_name(\"%s\", -1): returned NULL", relpath); not_reached(); } else if (strcmp(name, "foo") != 0) { - err(132, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); + err(93, __func__, "dir_name(\"%s\", -1): returned %s, expected: foo", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "dir_name(\"%s\", -1) == foo", relpath); } + if (name != NULL) { + free(name); + name = NULL; + } + + /* + * test NULL path + */ + relpath = NULL; + name = dir_name(NULL, -1); + if (name == NULL) { + err(94, __func__, "dir_name(NULL, -1): returned NULL"); + not_reached(); + } else if (strcmp(name, ".") != 0) { + err(95, __func__, "dir_name(NULL, -1): returned %s, expected: \".\"", name); + not_reached(); + } else { + fdbg(stderr, DBG_MED, "dir_name(NULL, -1) == \".\""); + } + + /* + * test empty path + */ + relpath = ""; + name = dir_name("", -1); + if (name == NULL) { + err(96, __func__, "dir_name(\"\", -1): returned NULL"); + not_reached(); + } else if (strcmp(name, ".") != 0) { + err(97, __func__, "dir_name(\"\", -1): returned %s, expected: \".\"", name); + not_reached(); + } else { + fdbg(stderr, DBG_MED, "dir_name(\"\", -1) == \".\""); + } /* @@ -9971,10 +10177,10 @@ main(int argc, char **argv) relpath = "foo/bar/baz/zab/rab/oof"; name = base_name(relpath); if (name == NULL) { - err(133, __func__, "base_name(\"%s\"): returned NULL", relpath); + err(98, __func__, "base_name(\"%s\"): returned NULL", relpath); not_reached(); } else if (strcmp(name, "oof") != 0) { - err(134, __func__, "base_name(\"%s\"): returned %s, expected: oof", relpath, name); + err(99, __func__, "base_name(\"%s\"): returned %s, expected: oof", relpath, name); not_reached(); } else { fdbg(stderr, DBG_MED, "base_name(\"%s\") == oof", relpath); @@ -9985,13 +10191,53 @@ main(int argc, char **argv) name = NULL; } + /* + * try again but with a NULL string + */ + relpath = NULL; + name = base_name(NULL); + if (name == NULL) { + err(100, __func__, "base_name(NULL): returned NULL"); + not_reached(); + } else if (strcmp(name, ".") != 0) { + err(101, __func__, "base_name(NULL): returned %s, expected: \".\"", name); + not_reached(); + } else { + fdbg(stderr, DBG_MED, "base_name(NULL) == \".\""); + } + + if (name != NULL) { + free(name); + name = NULL; + } + + /* + * try again but with an empty string + */ + relpath = ""; + name = base_name(relpath); + if (name == NULL) { + err(102, __func__, "base_name(\"%s\"): returned NULL", relpath); + not_reached(); + } else if (strcmp(name, ".") != 0) { + err(103, __func__, "base_name(\"%s\"): returned %s, expected: \".\"", relpath, name); + not_reached(); + } else { + fdbg(stderr, DBG_MED, "base_name(\"%s\") == \".\"", relpath); + } + + if (name != NULL) { + free(name); + name = NULL; + } + /* * now we have to count the number of directories in a path */ relpath = "foo/bar/baz"; comps = count_dirs(relpath); if (comps != 2) { - err(135, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); + err(104, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 2", relpath); @@ -10003,7 +10249,7 @@ main(int argc, char **argv) relpath = "foo//baz"; comps = count_dirs(relpath); if (comps != 1) { - err(136, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(105, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10015,7 +10261,7 @@ main(int argc, char **argv) relpath = "///"; comps = count_dirs(relpath); if (comps != 1) { - err(137, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(106, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10027,7 +10273,7 @@ main(int argc, char **argv) relpath = "/"; comps = count_dirs(relpath); if (comps != 1) { - err(138, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(107, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10039,7 +10285,7 @@ main(int argc, char **argv) relpath = "foo///"; comps = count_dirs(relpath); if (comps != 1) { - err(139, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(108, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10051,7 +10297,7 @@ main(int argc, char **argv) relpath = ""; comps = count_dirs(relpath); if (comps != 0) { - err(140, __func__, "count_dirs(\"%s\"): %ju != 0", relpath, comps); + err(109, __func__, "count_dirs(\"%s\"): %ju != 0", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 0", relpath); @@ -10063,7 +10309,7 @@ main(int argc, char **argv) relpath = "foo/..//foo"; comps = count_dirs(relpath); if (comps != 2) { - err(141, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); + err(110, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 2", relpath); @@ -10075,7 +10321,7 @@ main(int argc, char **argv) relpath = "foo/..//foo/3/"; comps = count_dirs(relpath); if (comps != 4) { - err(142, __func__, "count_dirs(\"%s\"): %ju != 4", relpath, comps); + err(111, __func__, "count_dirs(\"%s\"): %ju != 4", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 4", relpath); @@ -10087,7 +10333,7 @@ main(int argc, char **argv) relpath = "foo/../foo"; comps = count_dirs(relpath); if (comps != 2) { - err(143, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); + err(112, __func__, "count_dirs(\"%s\"): %ju != 2", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 2", relpath); @@ -10099,7 +10345,7 @@ main(int argc, char **argv) relpath = "foo/../foo/3/"; comps = count_dirs(relpath); if (comps != 4) { - err(144, __func__, "count_dirs(\"%s\"): %ju != 4", relpath, comps); + err(113, __func__, "count_dirs(\"%s\"): %ju != 4", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 4", relpath); @@ -10111,7 +10357,7 @@ main(int argc, char **argv) relpath = "foo//foo"; comps = count_dirs(relpath); if (comps != 1) { - err(145, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(114, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10123,7 +10369,7 @@ main(int argc, char **argv) relpath = "foo//foo/3/"; comps = count_dirs(relpath); if (comps != 3) { - err(146, __func__, "count_dirs(\"%s\"): %ju != 3", relpath, comps); + err(115, __func__, "count_dirs(\"%s\"): %ju != 3", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 3", relpath); @@ -10135,7 +10381,7 @@ main(int argc, char **argv) relpath = "foo/foo"; comps = count_dirs(relpath); if (comps != 1) { - err(147, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); + err(116, __func__, "count_dirs(\"%s\"): %ju != 1", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 1", relpath); @@ -10147,7 +10393,7 @@ main(int argc, char **argv) relpath = "foo/foo/3/"; comps = count_dirs(relpath); if (comps != 3) { - err(148, __func__, "count_dirs(\"%s\"): %ju != 3", relpath, comps); + err(117, __func__, "count_dirs(\"%s\"): %ju != 3", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_dirs(\"%s\") == 3", relpath); @@ -10163,7 +10409,7 @@ main(int argc, char **argv) relpath = "foo,bar,,,"; comps = count_comps(relpath, ',', true); if (comps != 2) { - err(149, __func__, "count_comps(\"%s\", ',', true): %ju != 2", relpath, comps); + err(118, __func__, "count_comps(\"%s\", ',', true): %ju != 2", relpath, comps); not_reached(); } else { fdbg(stderr, DBG_MED, "count_comps(\"%s\", ',', true) == 2", relpath); @@ -10174,7 +10420,7 @@ main(int argc, char **argv) */ relpath = "foo/bar/baz"; if (!path_has_component(relpath, "baz")) { - err(150, __func__, "path_has_component(\"%s\", \"baz\") returned false: expected true", relpath); + err(119, __func__, "path_has_component(\"%s\", \"baz\") returned false: expected true", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "path_has_component(\"%s\", \"baz\") == true", relpath); @@ -10185,7 +10431,7 @@ main(int argc, char **argv) */ relpath = "foo/bar/baz"; if (!path_has_component(relpath, "bar")) { - err(151, __func__, "path_has_component(\"%s\", \"bar\") returned false: expected true", relpath); + err(120, __func__, "path_has_component(\"%s\", \"bar\") returned false: expected true", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "path_has_component(\"%s\", \"bar\") == true", relpath); @@ -10196,7 +10442,7 @@ main(int argc, char **argv) */ relpath = "foo//bar/baz"; if (!path_has_component(relpath, "bar")) { - err(152, __func__, "path_has_component(\"%s\", \"bar\") returned false: expected true", relpath); + err(121, __func__, "path_has_component(\"%s\", \"bar\") returned false: expected true", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "path_has_component(\"%s\", \"bar\") == true", relpath); @@ -10207,7 +10453,7 @@ main(int argc, char **argv) */ relpath = "foo//bar/baz"; if (!path_has_component(relpath, "baz")) { - err(153, __func__, "path_has_component(\"%s\", \"baz\") returned false: expected true", relpath); + err(122, __func__, "path_has_component(\"%s\", \"baz\") returned false: expected true", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "path_has_component(\"%s\", \"baz\") == true", relpath); @@ -10218,7 +10464,7 @@ main(int argc, char **argv) */ relpath = "foo//bar/.git//"; if (!path_has_component(relpath, ".git")) { - err(154, __func__, "path_has_component(\"%s\", \".git\") returned false: expected true", relpath); + err(123, __func__, "path_has_component(\"%s\", \".git\") returned false: expected true", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "path_has_component(\"%s\", \".git\") == true", relpath); @@ -10228,19 +10474,19 @@ main(int argc, char **argv) if (relpath != NULL) { errno = 0; /* pre-clear errno for errp() */ if (stat(relpath, &in_st) != 0) { - errp(155, __func__, "couldn't stat file %s", relpath); + errp(124, __func__, "couldn't stat file %s", relpath); not_reached(); } bytes = copyfile(relpath, "util_test.copy.c", true, 0); fdbg(stderr, DBG_MED, "copyfile(\"%s\", \"util_test.copy.c\", true, 0): %ju bytes", relpath, (uintmax_t)bytes); errno = 0; /* pre-clear errno for errp() */ if (stat("util_test.copy.c", &out_st) != 0) { - errp(156, __func__, "couldn't stat file util_test.copy.c"); + errp(125, __func__, "couldn't stat file util_test.copy.c"); not_reached(); } if (!is_mode("util_test.copy.c", in_st.st_mode)) { - err(157, __func__, "copyfile() failed to copy st_mode of file %s", relpath); + err(126, __func__, "copyfile() failed to copy st_mode of file %s", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "copyfile() successfully copied st_mode of file %s: %04o == %04o", relpath, @@ -10252,7 +10498,7 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (unlink("util_test.copy.c") != 0) { - errp(158, __func__, "unable to delete file util_test.copy.c"); + errp(128, __func__, "unable to delete file util_test.copy.c"); not_reached(); } else { fdbg(stderr, DBG_MED, "successfully deleted copied file util_test.copy.c"); @@ -10262,7 +10508,7 @@ main(int argc, char **argv) * now check that the size is empty */ if (!is_empty("util_test.copy.c")) { - errp(159, __func__, "just deleted file util_test.copy.c is not empty"); + errp(129, __func__, "just deleted file util_test.copy.c is not empty"); not_reached(); } @@ -10287,12 +10533,12 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (stat("util_test.copy.c", &out_st) != 0) { - errp(160, __func__, "failed to stat util_test.copy.c"); + errp(130, __func__, "failed to stat util_test.copy.c"); not_reached(); } if ((out_st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) != (S_IRUSR|S_IWUSR)) { - err(161, __func__, "copyfile() failed to set S_IRUSR|S_IWUSR on util_test.copy.c"); + err(131, __func__, "copyfile() failed to set S_IRUSR|S_IWUSR on util_test.copy.c"); not_reached(); } else { fdbg(stderr, DBG_MED, "copyfile() successfully set S_IRUSR|S_IWUSR on util_test.copy.c"); @@ -10302,7 +10548,7 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (unlink("util_test.copy.c") != 0) { - errp(162, __func__, "unable to delete file util_test.copy.c"); + errp(132, __func__, "unable to delete file util_test.copy.c"); not_reached(); } else { fdbg(stderr, DBG_MED, "successfully deleted copied file util_test.copy.c"); @@ -10311,7 +10557,7 @@ main(int argc, char **argv) * now check that the size is empty */ if (!is_empty("util_test.copy.c")) { - errp(163, __func__, "just deleted file util_test.copy.c is not empty"); + errp(133, __func__, "just deleted file util_test.copy.c is not empty"); not_reached(); } @@ -10334,7 +10580,7 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (stat("util.o", &in_st) != 0) { - errp(164, __func__, "failed to stat util.o"); + errp(134, __func__, "failed to stat util.o"); not_reached(); } /* @@ -10342,12 +10588,12 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (stat("util.copy.o", &out_st) != 0) { - errp(165, __func__, "failed to stat util.copy.o"); + errp(135, __func__, "failed to stat util.copy.o"); not_reached(); } if (!is_mode("util.copy.o", in_st.st_mode)) { - err(166, __func__, "util.o st_mode != util.copy.o st_mode: %04o != %04o", + err(136, __func__, "util.o st_mode != util.copy.o st_mode: %04o != %04o", in_st.st_mode & ~S_IFMT, out_st.st_mode & ~S_IFMT); not_reached(); } else { @@ -10359,7 +10605,7 @@ main(int argc, char **argv) */ errno = 0; /* pre-clear errno for errp() */ if (unlink("util.copy.o") != 0) { - errp(167, __func__, "unable to delete file util.copy.o"); + errp(137, __func__, "unable to delete file util.copy.o"); not_reached(); } else { fdbg(stderr, DBG_MED, "successfully deleted copied file util_test.copy.c"); @@ -10368,7 +10614,7 @@ main(int argc, char **argv) * now check that the size is empty */ if (!is_empty("util.copy.o")) { - errp(168, __func__, "just deleted file util.copy.o is not empty"); + errp(138, __func__, "just deleted file util.copy.o is not empty"); not_reached(); } @@ -10388,10 +10634,10 @@ main(int argc, char **argv) dir_exists = is_dir(relpath); mkdirs(-1, relpath, 0755); if (!exists(relpath)) { - err(169, __func__, "%s does not exist", relpath); + err(139, __func__, "%s does not exist", relpath); not_reached(); } else if (!is_dir(relpath)) { - err(170, __func__, "%s is not a directory", relpath); + err(140, __func__, "%s is not a directory", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is a directory", relpath); @@ -10402,7 +10648,7 @@ main(int argc, char **argv) */ if (!dir_exists) { if (!is_mode(relpath, 0755)) { - err(171, __func__, "failed to set mode of %s to %o", relpath, 0755); + err(141, __func__, "failed to set mode of %s to %o", relpath, 0755); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is mode 07555", relpath); @@ -10421,10 +10667,10 @@ main(int argc, char **argv) dir_exists = is_dir(relpath); mkdirs(-1, relpath, 0755); if (!exists(relpath)) { - err(172, __func__, "%s does not exist", relpath); + err(142, __func__, "%s does not exist", relpath); not_reached(); } else if (!is_dir(relpath)) { - err(173, __func__, "%s is not a directory", relpath); + err(143, __func__, "%s is not a directory", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is a directory", relpath); @@ -10435,7 +10681,7 @@ main(int argc, char **argv) */ if (!dir_exists) { if (!is_mode(relpath, 0755)) { - err(174, __func__, "failed to set mode of %s to %o", relpath, 0755); + err(144, __func__, "failed to set mode of %s to %o", relpath, 0755); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is mode 07555", relpath); @@ -10445,7 +10691,7 @@ main(int argc, char **argv) * also check that has_mode() works with the 0755 mode we set */ if (!has_mode(relpath, 0755)){ - err(175, __func__, "%s does not have bits %o set", relpath, 0755); + err(145, __func__, "%s does not have bits %o set", relpath, 0755); not_reached(); } else { fdbg(stderr, DBG_MED, "%s has bits %o in stat.st_mode", @@ -10456,7 +10702,7 @@ main(int argc, char **argv) * also check specific bits */ if (!has_mode(relpath, S_IRWXU)) { - err(176, __func__, "%s does not have bits %o set", relpath, S_IRWXU); + err(146, __func__, "%s does not have bits %o set", relpath, S_IRWXU); not_reached(); } else { fdbg(stderr, DBG_MED, "%s has bits %o in stat.st_mode", relpath, S_IRWXU); @@ -10466,7 +10712,7 @@ main(int argc, char **argv) * check bits not set */ if (has_mode(relpath, S_ISUID)) { - err(177, __func__, "%s has set user id on execution", relpath); + err(147, __func__, "%s has set user id on execution", relpath); not_reached(); } else { fdbg(stderr, DBG_MED, "%s does not have set user id on execution", relpath); @@ -10508,13 +10754,13 @@ main(int argc, char **argv) fts.logical = true; ent = read_fts("test_jparse", -1, &cwd, &fts); if (ent == NULL) { - err(178, __func__, "read_fts() returned a NULL pointer on \"test_jparse\""); + err(148, __func__, "read_fts() returned a NULL pointer on \"test_jparse\""); not_reached(); } else { do { char *p = fts_path(ent); if (p == NULL) { - err(179, __func__, "fts_path(ent) returned NULL"); + err(149, __func__, "fts_path(ent) returned NULL"); not_reached(); } switch (ent->fts_info) { @@ -10523,7 +10769,7 @@ main(int argc, char **argv) if (is_file(p)) { fdbg(stderr, DBG_VVVHIGH, "FTS_F %s: is_file(\"%s\") == true", p, p); } else { - err(180, __func__, "%s reported as FTS_FILE !is_file(\"%s\")", p, p); + err(150, __func__, "%s reported as FTS_FILE !is_file(\"%s\")", p, p); not_reached(); } break; @@ -10532,7 +10778,7 @@ main(int argc, char **argv) if (is_dir(p)) { fdbg(stderr, DBG_VVVHIGH, "FTS_D %s: is_dir(\"%s\") == true", p, p); } else { - err(181, __func__, "%s reported as FTS_D !is_dir(\"%s\")", p, p); + err(151, __func__, "%s reported as FTS_D !is_dir(\"%s\")", p, p); not_reached(); } break; @@ -10541,7 +10787,7 @@ main(int argc, char **argv) if (is_symlink(p)) { fdbg(stderr, DBG_VVVHIGH, "FTS_D %s: is_symlink(\"%s\") == true", p, p); } else { - err(182, __func__, "%s reported as FTS_SL !is_symlink(\"%s\")", p, p); + err(152, __func__, "%s reported as FTS_SL !is_symlink(\"%s\")", p, p); not_reached(); } break; @@ -10549,11 +10795,11 @@ main(int argc, char **argv) fdbg(stderr, DBG_VVHIGH, "%s (broken symlink)", p); break; case FTS_NS: - err(183, __func__, "no stat(2) info available for path %s in tree", p); + err(153, __func__, "no stat(2) info available for path %s in tree", p); not_reached(); break; case FTS_NSOK: - err(184, __func__, "encountered FTS_NSOK for path %s in tree: FTS_NOSTAT set!", p); + err(154, __func__, "encountered FTS_NSOK for path %s in tree: FTS_NOSTAT set!", p); not_reached(); break; } @@ -10578,17 +10824,17 @@ main(int argc, char **argv) fts.type = FTS_TYPE_DIR; ent = read_fts("test_jparse", -1, &cwd, &fts); if (ent == NULL) { - err(185, __func__, "read_fts() returned a NULL pointer on \"test_jparse\" for directories"); + err(155, __func__, "read_fts() returned a NULL pointer on \"test_jparse\" for directories"); not_reached(); } else { do { char *p = fts_path(ent); if (p == NULL) { - err(186, __func__, "fts_path(ent) returned NULL"); + err(156, __func__, "fts_path(ent) returned NULL"); not_reached(); } if (ent->fts_info != FTS_D && ent->fts_info != FTS_DP) { - err(187, __func__, "%s is not a directory", p); + err(157, __func__, "%s is not a directory", p); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is a directory", p); @@ -10620,20 +10866,20 @@ main(int argc, char **argv) append_path(&(fts.ignore), "test_jparse/test_JSON/bad_loc", true, false, true); ent = read_fts("test_jparse", -1, &cwd, &fts); if (ent == NULL) { - err(188, __func__, "read_fts() returned a NULL pointer on \"test_jparse\" for directories"); + err(158, __func__, "read_fts() returned a NULL pointer on \"test_jparse\" for directories"); not_reached(); } else { do { char *p = fts_path(ent); if (p == NULL) { - err(189, __func__, "fts_path(ent) returned NULL"); + err(159, __func__, "fts_path(ent) returned NULL"); not_reached(); } if (ent->fts_info != FTS_D && ent->fts_info != FTS_DP) { - err(190, __func__, "%s is not a directory", p); + err(160, __func__, "%s is not a directory", p); not_reached(); } else if (!strcmp(p, "good") || !strcmp(p, "bad") || !strcmp(p, "bad_loc")) { - err(191, __func__, "found directory meant to be ignored: %s", p); + err(161, __func__, "found directory meant to be ignored: %s", p); not_reached(); } else { fdbg(stderr, DBG_MED, "%s is a non-ignored directory", p); @@ -10673,13 +10919,13 @@ main(int argc, char **argv) */ ent = read_fts("test_jparse", -1, &cwd, &fts); if (ent == NULL) { - err(192, __func__, "read_fts() returned a NULL pointer on \"test_jparse\""); + err(162, __func__, "read_fts() returned a NULL pointer on \"test_jparse\""); not_reached(); } else { do { char *p = fts_path(ent); if (ent == NULL) { - err(193, __func__, "fts_path(ent) returned NULL"); + err(163, __func__, "fts_path(ent) returned NULL"); not_reached(); } switch (ent->fts_info) { @@ -10696,11 +10942,11 @@ main(int argc, char **argv) fdbg(stderr, DBG_VVHIGH, "%s (symlink with non-existent target)", p); break; case FTS_NS: - err(194, __func__, "no stat(2) info available"); + err(164, __func__, "no stat(2) info available"); not_reached(); break; case FTS_NSOK: - err(195, __func__, "encountered FTS_NSOK for path %s in tree: FTS_NOSTAT set!", p); + err(165, __func__, "encountered FTS_NSOK for path %s in tree: FTS_NOSTAT set!", p); not_reached(); break; } @@ -10822,7 +11068,7 @@ main(int argc, char **argv) */ fname = find_path("bad", NULL, -1, &cwd, false, &fts); if (fname == NULL) { - err(196, __func__, "unable to find directory \"bad\""); + err(166, __func__, "unable to find directory \"bad\""); not_reached(); } else { fdbg(stderr, DBG_MED, "successfully ignored directories in ignore list"); @@ -10846,7 +11092,7 @@ main(int argc, char **argv) */ fname = find_path("bad", NULL, -1, &cwd, false, &fts); if (fname != NULL) { - err(197, __func__, "found ignored directory \"bad\""); + err(167, __func__, "found ignored directory \"bad\""); not_reached(); } else { fdbg(stderr, DBG_MED, "successfully ignored directories in ignore list"); @@ -10866,7 +11112,7 @@ main(int argc, char **argv) fts.depth = 0; fname = find_path("bad", "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(198, __func__, "found paths when none should have been found"); + err(168, __func__, "found paths when none should have been found"); not_reached(); } @@ -10892,7 +11138,7 @@ main(int argc, char **argv) fts.match_case = true; fname = find_path("test_jparse", NULL, -1, &cwd, false, &fts); if (paths_found != NULL) { - err(199, __func__, "found paths when none should have been found"); + err(169, __func__, "found paths when none should have been found"); not_reached(); } @@ -10950,7 +11196,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(200, __func__, "didn't find any paths in the paths array"); + err(170, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -10962,7 +11208,7 @@ main(int argc, char **argv) /* * "test_jparse" must exist */ - err(201, __func__, "didn't find \"test_jparse\" in paths array"); + err(171, __func__, "didn't find \"test_jparse\" in paths array"); not_reached(); } else { fdbg(stderr, DBG_MED, "found test_jparse at paths[%ju]", (uintmax_t)idx); @@ -10977,7 +11223,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(202, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(172, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11027,7 +11273,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(203, __func__, "didn't find any paths in the paths array"); + err(173, __func__, "didn't find any paths in the paths array"); not_reached(); } else { /* @@ -11037,7 +11283,7 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { char *u = dyn_array_value(paths_found, char *, j); if (u == NULL) { - err(204, __func__, "NULL found in paths_found[%ju]", (uintmax_t)j); + err(174, __func__, "NULL found in paths_found[%ju]", (uintmax_t)j); not_reached(); } } @@ -11067,7 +11313,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(205, __func__, "didn't find any paths in the paths array"); + err(175, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -11080,7 +11326,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(206, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(176, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11129,7 +11375,7 @@ main(int argc, char **argv) fts.match_case = false; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(207, __func__, "didn't find any files in the paths array"); + err(177, __func__, "didn't find any files in the paths array"); not_reached(); } @@ -11142,7 +11388,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(208, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(178, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11190,7 +11436,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(209, __func__, "didn't find any files in the paths array"); + err(179, __func__, "didn't find any files in the paths array"); not_reached(); } @@ -11203,7 +11449,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(210, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(180, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11254,7 +11500,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found == NULL) { - err(211, __func__, "didn't find any files in the paths array"); + err(181, __func__, "didn't find any files in the paths array"); not_reached(); } @@ -11267,7 +11513,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(212, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(182, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11326,7 +11572,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found != NULL) { - err(213, __func__, "found paths when none should have been found"); + err(183, __func__, "found paths when none should have been found"); not_reached(); } @@ -11350,7 +11596,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, NULL, -1, &cwd, false, &fts); if (paths_found == NULL) { - err(214, __func__, "unable to find any path in the directory"); + err(184, __func__, "unable to find any path in the directory"); not_reached(); } @@ -11372,7 +11618,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found == NULL) { - err(215, __func__, "didn't find any paths in the paths array"); + err(185, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -11393,7 +11639,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(216, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(186, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11452,7 +11698,7 @@ main(int argc, char **argv) fts.max_depth = 5; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found == NULL) { - err(217, __func__, "didn't find any paths in the paths array"); + err(187, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -11466,7 +11712,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(218, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(188, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11513,7 +11759,7 @@ main(int argc, char **argv) fts.max_depth = 3; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found == NULL) { - err(219, __func__, "didn't find any paths in the paths array"); + err(189, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -11527,7 +11773,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(220, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(190, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11576,7 +11822,7 @@ main(int argc, char **argv) fts.max_depth = 0; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found == NULL) { - err(221, __func__, "didn't find any paths in the paths array"); + err(191, __func__, "didn't find any paths in the paths array"); not_reached(); } @@ -11590,7 +11836,7 @@ main(int argc, char **argv) /* get next string pointer */ name = dyn_array_value(paths_found, char *, j); if (name == NULL) { /* paranoia */ - err(222, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); + err(192, __func__, "found NULL pointer at paths_found[%ju]", (uintmax_t)j); not_reached(); } @@ -11641,7 +11887,7 @@ main(int argc, char **argv) fts.max_depth = 3; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(223, __func__, "bogus range of min/max directories found directories"); + err(193, __func__, "bogus range of min/max directories found directories"); not_reached(); } @@ -11670,7 +11916,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(224, __func__, "found unexpected socket under test_jparse/"); + err(194, __func__, "found unexpected socket under test_jparse/"); not_reached(); } @@ -11702,7 +11948,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(225, __func__, "found unexpected character device under test_jparse/"); + err(195, __func__, "found unexpected character device under test_jparse/"); not_reached(); } @@ -11735,7 +11981,7 @@ main(int argc, char **argv) fts.match_case = true; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(226, __func__, "found unexpected block device under test_jparse/"); + err(196, __func__, "found unexpected block device under test_jparse/"); not_reached(); } @@ -11762,7 +12008,7 @@ main(int argc, char **argv) fts.match_case = false; paths_found = find_paths(paths, "test_jparse", -1, &cwd, false, &fts); if (paths_found != NULL) { - err(227, __func__, "found unexpected FIFO under test_jparse/"); + err(197, __func__, "found unexpected FIFO under test_jparse/"); not_reached(); } @@ -11802,7 +12048,7 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { name = dyn_array_value(paths_found, char *, j); if (name == NULL) { - err(228, __func__, "found NULL pointer in paths_found (not file, directory or symlink) array"); + err(198, __func__, "found NULL pointer in paths_found (not file, directory or symlink) array"); not_reached(); } warn(__func__, "path is not a file, directory or symlink: %s", name); @@ -11810,7 +12056,7 @@ main(int argc, char **argv) /* * make it an error */ - err(229, __func__, "found unexpected file type under test_jparse/"); + err(199, __func__, "found unexpected file type under test_jparse/"); not_reached(); } @@ -11850,7 +12096,7 @@ main(int argc, char **argv) relpath = "foobar"; touch(relpath, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (!exists(relpath)) { - err(230, __func__, "file %s does not exist after touch()", relpath); + err(200, __func__, "file %s does not exist after touch()", relpath); not_reached(); } @@ -11874,17 +12120,17 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { name = dyn_array_value(paths_found, char *, j); if (name == NULL) { - err(231, __func__, "found NULL pointer in paths_found (any) array"); + err(201, __func__, "found NULL pointer in paths_found (any) array"); not_reached(); } if (strcmp(relpath, name) != 0) { - err(232, __func__, "found non-matching file in list: %s != %s", name, relpath); + err(202, __func__, "found non-matching file in list: %s != %s", name, relpath); not_reached(); } fdbg(stderr, DBG_MED, "found file %s as case-sensitive search", name); } } else { - err(233, __func__, "couldn't find any file called \"%s\" as case-sensitive search", relpath); + err(203, __func__, "couldn't find any file called \"%s\" as case-sensitive search", relpath); not_reached(); } @@ -11923,18 +12169,18 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { name = dyn_array_value(paths_found, char *, j); if (name == NULL) { - err(234, __func__, "found NULL pointer in paths_found (any) array"); + err(204, __func__, "found NULL pointer in paths_found (any) array"); not_reached(); } if (strcasecmp(relpath, name) != 0) { - err(235, __func__, "found non-matching file in list: %s != %s", name, relpath); + err(205, __func__, "found non-matching file in list: %s != %s", name, relpath); not_reached(); } fdbg(stderr, DBG_MED, "found %s by case-insensitive search", name); } } else { - err(236, __func__, "couldn't find any file called \"%s\" by case-insensitive search", relpath); + err(206, __func__, "couldn't find any file called \"%s\" by case-insensitive search", relpath); not_reached(); } @@ -11944,7 +12190,7 @@ main(int argc, char **argv) errno = 0; /* pre-clear errno for errp() */ if (unlink(relpath) != 0) { if (errno != ENOENT) { - errp(237, __func__, "unable to delete file %s", relpath); + errp(207, __func__, "unable to delete file %s", relpath); not_reached(); } } else { @@ -11954,7 +12200,7 @@ main(int argc, char **argv) * now check that the size is empty */ if (!is_empty(relpath)) { - errp(238, __func__, "just deleted file %s is not empty", relpath); + errp(208, __func__, "just deleted file %s is not empty", relpath); not_reached(); } @@ -11995,7 +12241,7 @@ main(int argc, char **argv) * make sure it exists */ if (!exists(relpath)) { - err(239, __func__, "file %s does not exist", relpath); + err(209, __func__, "file %s does not exist", relpath); not_reached(); } @@ -12033,7 +12279,7 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { name = dyn_array_value(paths_found, char *, j); if (name == NULL) { - err(240, __func__, "found NULL pointer in paths_found (any) array"); + err(210, __func__, "found NULL pointer in paths_found (any) array"); not_reached(); } fdbg(stderr, DBG_MED, "found file %s as case-sensitive search", name); @@ -12082,11 +12328,11 @@ main(int argc, char **argv) for (j = 0; j < len; ++j) { name = dyn_array_value(paths_found, char *, j); if (name == NULL) { - err(241, __func__, "found NULL pointer in paths_found array"); + err(211, __func__, "found NULL pointer in paths_found array"); not_reached(); } if (strcasecmp(relpath, name) != 0) { - err(242, __func__, "found non-matching file: %s != %s", name, relpath); + err(212, __func__, "found non-matching file: %s != %s", name, relpath); not_reached(); } fdbg(stderr, DBG_MED, "found %s by case-insensitive search", name); @@ -12095,7 +12341,7 @@ main(int argc, char **argv) /* * as it is a case-insensitive it should always succeed */ - err(243, __func__, "couldn't find any file called %s by case-insensitive search", relpath); + err(213, __func__, "couldn't find any file called %s by case-insensitive search", relpath); not_reached(); } @@ -12125,7 +12371,7 @@ main(int argc, char **argv) free(fname); fname = NULL; } else { - err(244, __func__, "couldn't find %s in tree", relpath); + err(214, __func__, "couldn't find %s in tree", relpath); not_reached(); } @@ -12136,7 +12382,7 @@ main(int argc, char **argv) errno = 0; /* pre-clear errno for errp() */ if (unlink(relpath) != 0) { if (errno != ENOENT) { - errp(245, __func__, "unable to delete file %s", relpath); + errp(215, __func__, "unable to delete file %s", relpath); not_reached(); } } else { @@ -12146,12 +12392,10 @@ main(int argc, char **argv) * now check that the size is empty */ if (!is_empty(relpath)) { - errp(246, __func__, "just deleted file %s is not empty", relpath); + errp(216, __func__, "just deleted file %s is not empty", relpath); not_reached(); } - - /* * free paths_found array */ @@ -12169,6 +12413,16 @@ main(int argc, char **argv) */ reset_fts(&fts, true); + /* + * test resolve_path() + */ + name = resolve_path("ls"); + if (name != NULL) { + fdbg(stderr, DBG_MED, "resolved ls as: %s", name); + free(name); + name = NULL; + } + /* * All Done!!! All Done!!! -- Jessica Noll, Age 2 */ diff --git a/jparse/util.h b/jparse/util.h index fead74cb..ed709938 100644 --- a/jparse/util.h +++ b/jparse/util.h @@ -319,6 +319,7 @@ extern off_t file_size(char const *path); extern bool is_empty(char const *path); extern char *cmdprintf(char const *format, ...); extern char *vcmdprintf(char const *format, va_list ap); +extern char *resolve_path(char const *cmd); extern int shell_cmd(char const *name, bool flush_stdin, bool abort_on_error, char const *format, ...); extern FILE *pipe_open(char const *name, bool write_mode, bool abort_on_error, char const *format, ...); extern void para(char const *line, ...); diff --git a/jparse/verge.c b/jparse/verge.c index d005c429..ef6f4465 100644 --- a/jparse/verge.c +++ b/jparse/verge.c @@ -57,11 +57,6 @@ -/* - * definitions - */ -#define REQUIRED_ARGS (2) /* number of required arguments on the command line */ - /* * vercmp - compare two version strings * diff --git a/jparse/version.h b/jparse/version.h index 757b6a26..d5b44415 100644 --- a/jparse/version.h +++ b/jparse/version.h @@ -55,7 +55,7 @@ * * NOTE: this should match the latest Release string in CHANGES.md */ -#define JPARSE_REPO_VERSION "2.3.3 2025-03-07" /* format: major.minor YYYY-MM-DD */ +#define JPARSE_REPO_VERSION "2.3.5 2025-03-10" /* format: major.minor YYYY-MM-DD */ /* * official jparse version @@ -70,7 +70,7 @@ /* * official utility functions (util.c) version */ -#define JPARSE_UTILS_VERSION "2.0.3 2025-03-07" /* format: major.minor YYYY-MM-DD */ +#define JPARSE_UTILS_VERSION "2.0.5 2025-03-10" /* format: major.minor YYYY-MM-DD */ #endif /* INCLUDE_JPARSE_VERSION_H */ diff --git a/mkiocccentry.c b/mkiocccentry.c index a5125ad6..45cfd732 100644 --- a/mkiocccentry.c +++ b/mkiocccentry.c @@ -92,7 +92,6 @@ #include /* for WEXITSTATUS() */ #include /* for open() */ #include -#include /* PATH_MAX */ /* * mkiocccentry - form IOCCC entry compressed tarball @@ -142,8 +141,12 @@ static const char * const usage_msg3 = "\t-A answers\twrite answers file even if it already exists\n" "\t-i answers\tread answers from file previously written by -a|-A answers\n" "\t\t\t NOTE: One cannot use both -a/-A answers and -i answers.\n" - "\t-u uuid\t\tread UUID from a file (def: prompt for UUID)\n" + "\t-u uuidfile\tread UUID from a file (def: prompt for UUID)\n" "\t\t\t NOTE: if an invalid UUID is in the file, it will try the usual way\n" + "\t\t\t NOTE: this option may not be used with -U UUID, -d, -s seed or -i answers\n" + "\t-U UUID\t\tset UUID to UUID\n" + "\t\t\t NOTE: if an invalid UUID is in the file, it will try the usual way\n" + "\t\t\t NOTE: this option may not be used with -u uuidfile, -d, -s seed or -i answers\n" "\t-s seed\t\tGenerate and use pseudo-random answers, seeding with\n" "\t\t\t seed & 0x%08u (def: do not)\n" "\t-d\t\tAlias for -s %u\n" @@ -153,6 +156,8 @@ static const char * const usage_msg3 = "\t-I path\t\tignore path (to file or directory) under topdir\n" "\t\t\t NOTE: you can ignore more than one file or directory with multiple -I args\n"; static const char * const usage_msg4 = + "\t-x\t\tforce delete submission directory if it already exists (def: don't)\n" + "\t-r rm\t\tset path to rm\n\n" "\tworkdir\t\tdirectory where the submission directory and tarball are formed\n" "\t\t\t NOTE: the submission directory under this directory must NOT exist\n" "\ttopdir\t\tdirectory with required, optional and extra files and/or directories\n" @@ -215,6 +220,7 @@ main(int argc, char *argv[]) char *remarks_md = NULL; /* path to remarks.md */ char **topdir = NULL; /* directory from which files are to be copied to the workdir */ char *tar = TAR_PATH_0; /* path to tar executable that supports the -J (xz) option */ + char *rm = RM_PATH_0; /* path to rm tool */ char *ls = LS_PATH_0; /* path to ls executable */ char *txzchk = TXZCHK_PATH_0; /* path to txzchk executable */ char *fnamchk = FNAMCHK_PATH_0; /* path to fnamchk executable */ @@ -222,24 +228,20 @@ main(int argc, char *argv[]) char *make = MAKE_PATH_0; /* path to make(1) executable */ char *answers = NULL; /* path to the answers file (recording input given on stdin) */ FILE *answersp = NULL; /* file pointer to the answers file */ - char *uuid = NULL; /* path to the UUID file */ - FILE *uuidp = NULL; /* file pointer to the UUID file */ + char *uuidfile = NULL; /* path to the UUID file */ + char *uuidstr = NULL; /* -U UUID option or UUID environmental var */ char *submission_dir = NULL; /* submission directory from which to form a compressed tarball */ char *tarball_path = NULL; /* path of the compressed tarball to form */ struct info info; /* data to form .info.json */ struct auth auth; /* data to form .auth.json */ int author_count = 0; /* number of authors */ struct author *author_set = NULL; /* list of authors */ - bool tar_flag_used = false; /* true ==> -t /path/to/tar was given */ - bool ls_flag_used = false; /* true ==> -l /path/to/ls was given */ - bool make_flag_used = false; /* true ==> -m /path/to/make was given */ bool answers_flag_used = false; /* true ==> -a write answers to answers file */ - bool read_uuid_flag_used = false; /* true ==> -u uuid used */ + bool read_uuid_flag_used = false; /* true ==> -u uuidfile used */ + bool uuid_flag_used = false; /* true ==> -U uuid used */ bool overwrite_answers_flag_used = false; /* true ==> don't prompt to overwrite answers if it already exists */ - bool txzchk_flag_used = false; /* true ==> -T /path/to/txzchk was given */ - bool fnamchk_flag_used = false; /* true ==> -F /path/to/fnamchk was given */ - bool chkentry_flag_used = false; /* true ==> -C /path/to/chkentry was given */ - bool overwrite_answers = true; /* true ==> overwrite answers file even if it already exists */ + bool overwrite_answers = false; /* true ==> overwrite answers file even if it already exists */ + bool force_delete = false; /* true ==> force delete workdir/slot directory if it exists */ RuleCount size; /* rule_count() processing results */ int ret; /* libc return code */ int i; @@ -253,6 +255,7 @@ main(int argc, char *argv[]) */ memset(&auth, 0, sizeof(auth)); + /* * even though these stat structs are in file scope, make sure they are * zeroed out @@ -265,7 +268,7 @@ main(int argc, char *argv[]) */ input_stream = stdin; /* default to reading from standard in */ program = argv[0]; - while ((i = getopt(argc, argv, ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yYds:m:I:u:")) != -1) { + while ((i = getopt(argc, argv, ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yYds:m:I:u:U:xr:")) != -1) { switch (i) { case 'h': /* -h - print help to stderr and exit 2 */ usage(2, program, ""); /*ooo*/ @@ -305,11 +308,9 @@ main(int argc, char *argv[]) break; case 't': /* -t /path/to/tar */ tar = optarg; - tar_flag_used = true; break; case 'l': /* -l /path/to/ls */ ls = optarg; - ls_flag_used = true; break; case 'A': /* -A answers overwrite answers file */ answers = optarg; @@ -344,7 +345,6 @@ main(int argc, char *argv[]) abort_on_warning = true; break; case 'T': - txzchk_flag_used = true; txzchk = optarg; break; case 'e': @@ -357,11 +357,9 @@ main(int argc, char *argv[]) } break; case 'F': - fnamchk_flag_used = true; fnamchk = optarg; break; case 'C': - chkentry_flag_used = true; chkentry = optarg; break; case 'y': @@ -412,16 +410,25 @@ main(int argc, char *argv[]) } break; case 'm': /* set path to make(1) */ - make_flag_used = true; make = optarg; break; case 'I': /* ignore a path */ append_path(&info.ignore_paths, optarg, true, false, false); break; case 'u': - uuid = optarg; + uuidfile = optarg; read_uuid_flag_used = true; break; + case 'U': + uuidstr = optarg; + uuid_flag_used = true; + break; + case 'x': + force_delete = true; + break; + case 'r': + rm = optarg; + break; case ':': /* option requires an argument */ case '?': /* illegal option */ default: /* anything else but should not actually happen */ @@ -449,9 +456,8 @@ main(int argc, char *argv[]) * On some systems where /usr/bin != /bin, the distribution made the mistake of * moving historic critical applications, look to see if the alternate path works instead. */ - find_utils(tar_flag_used, &tar, ls_flag_used, &ls, - txzchk_flag_used, &txzchk, fnamchk_flag_used, &fnamchk, - chkentry_flag_used, &chkentry, make_flag_used, &make); + find_utils(&tar, &ls, &txzchk, &fnamchk, &chkentry, &make, &rm); + /* * check that conflicting answers file options are not used together @@ -477,7 +483,23 @@ main(int argc, char *argv[]) not_reached(); } if (seed_used && read_uuid_flag_used) { - err(3, __func__, "-u uuid cannot be used with either -d or -s seed");/*ooo*/ + err(3, __func__, "-u uuidfile cannot be used with either -d or -s seed");/*ooo*/ + not_reached(); + } + if (seed_used && uuidstr != NULL) { + err(3, __func__, "-U UUID cannot be used with -d or -s seed");/*ooo*/ + not_reached(); + } + if (read_uuid_flag_used && uuid_flag_used) { + err(3, __func__, "-u uuidfile and -U UUID cannot be used together");/*ooo*/ + not_reached(); + } + if ((read_uuid_flag_used || uuid_flag_used) && seed_used) { + err(3, __func__, "-U UUID or -u uuidfile cannot be used with -d or -s seed");/*ooo*/ + not_reached(); + } + if ((read_uuid_flag_used || uuid_flag_used) && read_answers_flag_used) { + err(3, __func__, "-U UUID or -u uuidfile cannot be used with -i answers");/*ooo*/ not_reached(); } if (ignore_warnings && abort_on_warning) { @@ -543,6 +565,7 @@ main(int argc, char *argv[]) dbg(DBG_MED, "tar: %s", tar); dbg(DBG_MED, "ls: %s", ls); + dbg(DBG_MED, "rm: %s", rm); workdir = argv[optind]; if (workdir == NULL || *workdir == '\0') { err(3, __func__, "workdir is NULL or empty string");/*ooo*/ @@ -685,7 +708,7 @@ main(int argc, char *argv[]) if (!quiet) { para("", "Performing sanity checks on your environment ...", NULL); } - mkiocccentry_sanity_chks(&info, workdir, tar, ls, txzchk, fnamchk, chkentry, make); + mkiocccentry_sanity_chks(&info, workdir, tar, ls, txzchk, fnamchk, chkentry, make, rm); if (!quiet) { para("... environment looks OK", "", NULL); } @@ -725,26 +748,10 @@ main(int argc, char *argv[]) input_stream = answersp; } - /* - * check if we should read input from UUID file - */ - if (read_uuid_flag_used && uuid != NULL && strlen(uuid) > 0) { - if (!is_read(uuid)) { - warn(__func__, "cannot read UUID file, will prompt for UUID"); - } else { - errno = 0; /* pre-clear errno for errp() */ - uuidp = fopen(uuid, "r"); - if (uuidp == NULL) { - warnp(__func__, "cannot open UUID file, will prompt for UUID"); - } - } - } - - /* * obtain the IOCCC contest ID */ - info.ioccc_id = get_contest_id(&info.test_mode, uuidp); + info.ioccc_id = get_contest_id(&info.test_mode, uuidfile, uuidstr); dbg(DBG_LOW, "Submission: IOCCC contest ID: %s", info.ioccc_id); /* @@ -763,7 +770,8 @@ main(int argc, char *argv[]) /* * create submission directory */ - submission_dir = mk_submission_dir(workdir, info.ioccc_id, info.submit_slot, &tarball_path, info.tstamp, info.test_mode); + submission_dir = mk_submission_dir(workdir, info.ioccc_id, info.submit_slot, &tarball_path, info.tstamp, info.test_mode, + force_delete, rm); errno = 0; info.tarball = strdup(tarball_path); if (info.tarball == NULL) { @@ -1075,11 +1083,35 @@ main(int argc, char *argv[]) } /* - * if uuid file is open, close it + * we need to free the paths to the tools too */ - if (uuidp != NULL && is_open_file_stream(uuidp)) { - fclose(uuidp); - uuidp = NULL; + if (tar != NULL) { + free(tar); + tar = NULL; + } + if (ls != NULL) { + free(ls); + ls = NULL; + } + if (txzchk != NULL) { + free(txzchk); + txzchk = NULL; + } + if (fnamchk != NULL) { + free(fnamchk); + fnamchk = NULL; + } + if (chkentry != NULL) { + free(chkentry); + chkentry = NULL; + } + if (make != NULL) { + free(make); + make = NULL; + } + if (rm != NULL) { + free(rm); + rm = NULL; } /* @@ -3779,20 +3811,20 @@ usage(int exitcode, char const *prog, char const *str) * txzchk - path to txzchk tool * fnamchk - path to fnamchk tool * chkentry - path to chkentry tool - * make - path to make tool + * make - path to make + * rm - path to rm * * NOTE: This function does not return on error or if things are not sane. */ static void -mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *tar, - char const *ls, char const *txzchk, char const *fnamchk, char const *chkentry, - char const *make) +mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char *tar, char *ls, char *txzchk, char *fnamchk, + char *chkentry, char *make, char *rm) { /* * firewall */ - if (infop == NULL || workdir == NULL || tar == NULL || ls == NULL || - txzchk == NULL || fnamchk == NULL || chkentry == NULL || make == NULL) { + if (infop == NULL || workdir == NULL || tar == NULL || ls == NULL || txzchk == NULL || fnamchk == NULL || + chkentry == NULL || make == NULL || rm == NULL) { err(116, __func__, "called with NULL arg(s)"); not_reached(); } @@ -4133,7 +4165,60 @@ mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *ta not_reached(); } - + /* + * rm must be executable + */ + if (!exists(rm)) { + fpara(stderr, + "", + "We cannot find the rm program.", + "", + "Perhaps you need to use:", + "", + " mkiocccentry -r /path/to/rm ...", + "", + "and/or install a rm program? You can find the source for rm in core utilities:", + "", + " https://www.gnu.org/software/coreutils/", + "", + NULL); + err(136, __func__, "rm does not exist: %s", rm); + not_reached(); + } + if (!is_file(rm)) { + fpara(stderr, + "", + "The rm path, while it exists, is not a regular file.", + "", + "Perhaps you need to use another path:", + "", + " mkiocccentry -r /path/to/rm ...", + "", + "and/or install a rm program? You can find the source for rm in core utilities:", + "", + " https://www.gnu.org/software/coreutils/", + "", + NULL); + err(137, __func__, "rm is not a regular file: %s", rm); + not_reached(); + } + if (!is_exec(rm)) { + fpara(stderr, + "", + "The rm path, while it is a file, is not an executable.", + "", + "We suggest you check the permissions on the rm program, or use another path:", + "", + " mkiocccentry -r /path/to/rm ...", + "", + "and/or install a rm program? You can find the source for rm in core utilities:", + "", + " https://www.gnu.org/software/coreutils/", + "", + NULL); + err(138, __func__, "rm is not an executable program: %s", rm); + not_reached(); + } /* * workdir must be a writable directory @@ -4146,7 +4231,7 @@ mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *ta "You should either create workdir, or use a different workdir directory path on the command line.", "", NULL); - err(136, __func__, "workdir does not exist: %s", workdir); + err(139, __func__, "workdir does not exist: %s", workdir); not_reached(); } if (!is_dir(workdir)) { @@ -4158,7 +4243,7 @@ mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *ta "workdir directory path on the command line.", "", NULL); - err(137, __func__, "workdir is not a directory: %s", workdir); + err(140, __func__, "workdir is not a directory: %s", workdir); not_reached(); } if (!is_write(workdir)) { @@ -4170,7 +4255,7 @@ mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *ta "create a new writable directory, or use a different workdir directory path on the command line.", "", NULL); - err(138, __func__, "workdir is not a writable directory: %s", workdir); + err(141, __func__, "workdir is not a writable directory: %s", workdir); not_reached(); } @@ -4221,7 +4306,7 @@ prompt(char const *str, size_t *lenp) * NOTE: As noted above, lenp can be NULL. */ if (str == NULL) { - err(139, __func__, "called with NULL str"); + err(142, __func__, "called with NULL str"); not_reached(); } @@ -4241,13 +4326,13 @@ prompt(char const *str, size_t *lenp) ret = fputs(str, stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(140, __func__, "error printing prompt string"); + errp(143, __func__, "error printing prompt string"); not_reached(); } else if (feof(stdout)) { - err(141, __func__, "EOF while printing prompt string"); + err(144, __func__, "EOF while printing prompt string"); not_reached(); } else { - errp(142, __func__, "unexpected fputs error printing prompt string"); + errp(145, __func__, "unexpected fputs error printing prompt string"); not_reached(); } } @@ -4256,13 +4341,13 @@ prompt(char const *str, size_t *lenp) ret = fputs(": ", stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(143, __func__, "error printing :"); + errp(146, __func__, "error printing :"); not_reached(); } else if (feof(stdout)) { - err(144, __func__, "EOF while writing :"); + err(147, __func__, "EOF while writing :"); not_reached(); } else { - errp(145, __func__, "unexpected fputs error printing :"); + errp(148, __func__, "unexpected fputs error printing :"); not_reached(); } } @@ -4271,13 +4356,13 @@ prompt(char const *str, size_t *lenp) ret = fflush(stdout); if (ret == EOF) { if (ferror(stdout)) { - errp(146, __func__, "error flushing prompt to stdout"); + errp(149, __func__, "error flushing prompt to stdout"); not_reached(); } else if (feof(stdout)) { - err(147, __func__, "EOF while flushing prompt to stdout"); + err(150, __func__, "EOF while flushing prompt to stdout"); not_reached(); } else { - errp(148, __func__, "unexpected fflush error while flushing prompt to stdout"); + errp(151, __func__, "unexpected fflush error while flushing prompt to stdout"); not_reached(); } } @@ -4288,7 +4373,7 @@ prompt(char const *str, size_t *lenp) */ buf = readline_dup(&linep, true, &len, stream); if (buf == NULL) { - err(149, __func__, "EOF while reading prompt input"); + err(152, __func__, "EOF while reading prompt input"); not_reached(); } dbg(DBG_VHIGH, "received a %ju byte response", (uintmax_t)len); @@ -4323,7 +4408,9 @@ prompt(char const *str, size_t *lenp) * *testp will be set to true, otherwise it will be set to false. * * given: - * testp - pointer to boolean (in struct info) for test mode + * testp - pointer to boolean (in struct info) for test mode + * uuidfile - -u uuidfile option - path to file which if not NULL and is open can have a UUID + * uuidstr - -U UUID option (only used if -u uuidfile not used or is invalid) * * returns: * allocated contest ID string @@ -4332,34 +4419,83 @@ prompt(char const *str, size_t *lenp) * This function does not return on error or if the contest ID is malformed. */ static char * -get_contest_id(bool *testp, FILE *uuidp) +get_contest_id(bool *testp, char const *uuidfile, char *uuidstr) { char *malloc_ret = NULL; /* allocated return string */ char *linep = NULL; /* when reading from file */ size_t len; /* input string length */ bool valid = false; /* true ==> IOCCC_contest_id is valid */ bool seen_answers_header = false; + FILE *uuidfp = NULL; /* if -u uuidfile */ /* * firewall */ if (testp == NULL) { - err(150, __func__, "called with NULL testp"); + err(153, __func__, "called with NULL testp"); not_reached(); } /* - * explain contest ID unless uuidp != NULL + * if -U UUID not used check if -u uuidfile was used */ - if (uuidp != NULL && is_open_file_stream(uuidp)) { - malloc_ret = readline_dup(&linep, true, NULL, uuidp); - if (malloc_ret != NULL) { - if (valid_contest_id(malloc_ret)) { - return malloc_ret; + if (uuidfile != NULL) { + if (is_read(uuidfile)) { + errno = 0; /* pre-clear errno for warnp() */ + uuidfp = fopen(uuidfile, "r"); + if (uuidfp == NULL) { + warnp(__func__, "failed to open uuidfile, will prompt instead"); + } else { + uuidstr = readline_dup(&linep, true, NULL, uuidfp); + errno = 0; /* pre-clear errno for warnp() */ + if (fclose(uuidfp) != 0) { + warnp(__func__, "failed to fclose(uuidfp)"); + } + if (uuidstr != NULL) { + if (valid_contest_id(uuidstr)) { + if (strcmp(uuidstr, "test") == 0) { + + /* + * report test mode + */ + para("", + "IOCCC contest ID is test, entering test mode.", + NULL); + *testp = true; + } else { + *testp = false; + } + return uuidstr; + } + free(uuidstr); + uuidstr = NULL; + /* + * we will have to prompt the user instead + */ + } + } + } else { + warn(__func__, "-u uuidfile not readable, will prompt instead"); } - free(malloc_ret); - malloc_ret = NULL; - } + } + if (uuidstr != NULL && valid_contest_id(uuidstr)) { + /* + * case: IOCCC contest ID is test, quick return + */ + if (strcmp(uuidstr, "test") == 0) { + + /* + * report test mode + */ + para("", + "IOCCC contest ID is test, entering test mode.", + NULL); + *testp = true; + return uuidstr; + } else { + *testp = false; + return uuidstr; + } } /* * if we get here then the user has to input their uuid manually @@ -4397,7 +4533,7 @@ get_contest_id(bool *testp, FILE *uuidp) malloc_ret = prompt("", &len); } if (read_answers_flag_used && !seen_answers_header) { - err(151, __func__, "didn't find the correct answers file header"); + err(154, __func__, "didn't find the correct answers file header"); not_reached(); } @@ -4495,7 +4631,7 @@ get_submit_slot(struct info *infop) * firewall */ if (infop == NULL) { - err(152, __func__, "called with NULL arg(s)"); + err(155, __func__, "called with NULL arg(s)"); not_reached(); } @@ -4506,7 +4642,7 @@ get_submit_slot(struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = printf("\nYou are allowed to submit up to %d submissions to a given IOCCC.\n", MAX_SUBMIT_SLOT + 1); if (ret <= 0) { - errp(153, __func__, "printf error printing number of submissions allowed"); + errp(156, __func__, "printf error printing number of submissions allowed"); not_reached(); } para("", @@ -4540,7 +4676,7 @@ get_submit_slot(struct info *infop) ret = fprintf(stderr, "\nThe submit slot number must be a number from 0 through %d; please re-enter.\n", MAX_SUBMIT_SLOT); if (ret <= 0) { - errp(154, __func__, "fprintf error while informing about the valid submit slot number range"); + errp(157, __func__, "fprintf error while informing about the valid submit slot number range"); not_reached(); } /* @@ -4560,7 +4696,7 @@ get_submit_slot(struct info *infop) ret = printf("\nThe slot number you entered is: %d\n", submit_slot); if (ret <= 0) { - errp(155, __func__, "fprintf error writing slot number"); + errp(158, __func__, "fprintf error writing slot number"); not_reached(); } yorn = yes_or_no("\nIs that slot number correct? [Yn]", true); @@ -4602,6 +4738,8 @@ get_submit_slot(struct info *infop) * tarball_path - pointer to the allocated path to where the compressed tarball will be formed * tstamp - now as a timestamp * test_mode - true ==> test mode, do not upload + * force_delete - true ==> delete workdir/slot directory if it exists + * rm - path to rm command for -x option * * returns: * the path of the working directory @@ -4610,23 +4748,25 @@ get_submit_slot(struct info *infop) */ static char * mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, - char **tarball_path, time_t tstamp, bool test_mode) + char **tarball_path, time_t tstamp, bool test_mode, bool force_remove, + char const *rm) { size_t submission_dir_len; /* length of submission directory */ char *submission_dir = NULL; /* allocated submission directory path */ bool test = false; /* test result */ int ret; /* libc function return */ + int exit_code; /* exit code from shell_cmd() */ /* * firewall */ - if (workdir == NULL || ioccc_id == NULL || tarball_path == NULL) { - err(156, __func__, "called with NULL arg(s)"); + if (workdir == NULL || ioccc_id == NULL || tarball_path == NULL || (force_remove && rm == NULL)) { + err(159, __func__, "called with NULL arg(s)"); not_reached(); } test = test_submit_slot(submit_slot); if (test == false) { - err(157, __func__, "submit slot number: %d must >= 0 and <= %d", submit_slot, MAX_SUBMIT_SLOT); + err(160, __func__, "submit slot number: %d must >= 0 and <= %d", submit_slot, MAX_SUBMIT_SLOT); not_reached(); } @@ -4640,13 +4780,13 @@ mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, errno = 0; /* pre-clear errno for errp() */ submission_dir = (char *)malloc(submission_dir_len + 1); if (submission_dir == NULL) { - errp(158, __func__, "malloc #0 of %ju bytes failed", (uintmax_t)(submission_dir_len + 1)); + errp(161, __func__, "malloc #0 of %ju bytes failed", (uintmax_t)(submission_dir_len + 1)); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = snprintf(submission_dir, submission_dir_len + 1, "%s/%s-%d", workdir, ioccc_id, submit_slot); if (ret <= 0) { - errp(159, __func__, "snprintf to form submission directory failed"); + errp(162, __func__, "snprintf to form submission directory failed"); not_reached(); } dbg(DBG_HIGH, "submission directory path: %s", submission_dir); @@ -4655,19 +4795,35 @@ mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, * verify that the submission directory does not exist */ if (exists(submission_dir)) { - errno = 0; /* pre-clear errno for errp() */ - ret = fprintf(stderr, "\nsubmission directory already exists: %s\n", submission_dir); - if (ret <= 0) { - errp(160, __func__, "fprintf error while informing that the submission directory already exists"); + if (!force_remove) { + errno = 0; /* pre-clear errno for errp() */ + ret = fprintf(stderr, "\nsubmission directory already exists: %s\n", submission_dir); + if (ret <= 0) { + errp(163, __func__, "fprintf error while informing that the submission directory already exists"); + not_reached(); + } + fpara(stderr, + "", + "You need to move that directory, or remove it, use the -x option", + "or use a different workdir.", + "", + NULL); + err(164, __func__, "submission directory exists: %s", submission_dir); not_reached(); - } - fpara(stderr, - "", - "You need to move that directory, or remove it, or use a different workdir.", - "", - NULL); - err(161, __func__, "submission directory exists: %s", submission_dir); - not_reached(); + } else { + /* + * delete or try and delete directory + */ + dbg(DBG_HIGH, "about to perform: %s -rf %s", rm, submission_dir); + exit_code = shell_cmd(__func__, false, true, "% -rf %", rm, submission_dir); + if (exit_code != 0) { + err(165, __func__, "%s -rf %s failed with exit code: %d", + submission_dir, rm, WEXITSTATUS(exit_code)); + not_reached(); + } + + + } } dbg(DBG_HIGH, "submission directory path: %s", submission_dir); @@ -4683,13 +4839,13 @@ mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, */ ret = mkdir(submission_dir, 0); if (ret < 0) { - errp(162, __func__, "cannot mkdir %s", submission_dir); + errp(166, __func__, "cannot mkdir %s", submission_dir); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = chmod(submission_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ret < 0) { - errp(163, __func__, "cannot chmod directory %s to mode 0755", submission_dir); + errp(167, __func__, "cannot chmod directory %s to mode 0755", submission_dir); not_reached(); } @@ -4701,7 +4857,7 @@ mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, */ *tarball_path = form_tar_filename(ioccc_id, submit_slot, test_mode, tstamp); if (*tarball_path == NULL) { - errp(164, __func__, "failed to form compressed tarball path"); + errp(168, __func__, "failed to form compressed tarball path"); not_reached(); } dbg(DBG_HIGH, "compressed tarball path: %s", *tarball_path); @@ -4746,7 +4902,7 @@ warn_empty_prog(void) } yorn = yes_or_no("Are you sure you want to submit an empty prog.c file? [Ny]", false); if (!yorn) { - err(165, __func__, "please fix your prog.c file"); + err(169, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that their empty prog.c is OK"); @@ -4775,7 +4931,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) * firewall */ if (infop == NULL) { - err(166, __func__, "called with NULL infop"); + err(170, __func__, "called with NULL infop"); not_reached(); } @@ -4789,7 +4945,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) ret = fprintf(stderr, "\nWARNING: The prog.c size: %jd > Rule 2a maximum: %jd\n", (intmax_t)infop->rule_2a_size, (intmax_t)RULE_2A_SIZE); if (ret <= 0) { - errp(167, __func__, "fprintf error when printing prog.c Rule 2a warning"); + errp(171, __func__, "fprintf error when printing prog.c Rule 2a warning"); not_reached(); } if (abort_on_warning || (need_confirm && !ignore_warnings && !answer_yes)) { @@ -4806,7 +4962,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) } yorn = yes_or_no("Are you sure you want to submit such a large prog.c file? [Ny]", false); if (!yorn) { - err(168, __func__, "please fix your prog.c file"); + err(172, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that their prog.c size: %jd > Rule 2a max size: %jd is OK", @@ -4824,7 +4980,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) "YOUR remarks.md FILE!\n\n", (intmax_t)infop->rule_2a_size, (intmax_t)size.rule_2a_size); if (ret <= 0) { - errp(169, __func__, "fprintf error when printing prog.c file size and Rule 2a mismatch"); + errp(173, __func__, "fprintf error when printing prog.c file size and Rule 2a mismatch"); not_reached(); } if (abort_on_warning) { @@ -4832,7 +4988,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) } yorn = yes_or_no("Are you sure you want to proceed? [Ny]", false); if (!yorn) { - err(170, __func__, "please fix your prog.c file"); + err(174, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that prog.c size: %jd != rule_count function size: %jd is OK", @@ -4843,7 +4999,7 @@ warn_rule_2a_size(struct info *infop, int mode, RuleCount size) * invalid mode */ } else { - err(171, __func__, "invalid mode passed to function: %d", mode); + err(175, __func__, "invalid mode passed to function: %d", mode); not_reached(); } return; @@ -4871,7 +5027,7 @@ warn_nul_chars(void) ret = fprintf(stderr, "\nprog.c has NUL character(s)!\n" "Be careful you don't violate rule 13!\n\n"); if (ret <= 0) { - errp(172, __func__, "fprintf error when printing prog.c nul_warning"); + errp(176, __func__, "fprintf error when printing prog.c nul_warning"); not_reached(); } if (abort_on_warning) { @@ -4880,7 +5036,7 @@ warn_nul_chars(void) } yorn = yes_or_no("Are you sure you want to proceed? [Ny]", false); if (!yorn) { - err(173, __func__, "please fix your prog.c file"); + err(177, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that prog.c having NUL character(s) is OK"); @@ -4909,7 +5065,7 @@ warn_trigraph(void) ret = fprintf(stderr, "\nprog.c has unknown or invalid trigraph(s) found!\n" "Is that a bug in, or a feature of your code?\n\n"); if (ret <= 0) { - errp(174, __func__, "fprintf error when printing prog.c trigraph_warning"); + errp(178, __func__, "fprintf error when printing prog.c trigraph_warning"); not_reached(); } if (abort_on_warning) { @@ -4918,7 +5074,7 @@ warn_trigraph(void) } yorn = yes_or_no("Are you sure you want to proceed? [Ny]", false); if (!yorn) { - err(175, __func__, "please fix your prog.c file"); + err(179, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that prog.c having unknown or invalid trigraph(s) is OK"); @@ -4966,7 +5122,7 @@ warn_ungetc(void) "In order to avoid a possible Rule 2b violation, BE SURE TO CLEARLY MENTION THIS IN\n" "YOUR remarks.md FILE!\n\n"); if (ret <= 0) { - errp(176, __func__, "fprintf error when printing prog.c ungetc_warning"); + errp(180, __func__, "fprintf error when printing prog.c ungetc_warning"); not_reached(); } if (abort_on_warning) { @@ -4975,7 +5131,7 @@ warn_ungetc(void) } yorn = yes_or_no("Are you sure you want to proceed? [Ny]", false); if (!yorn) { - err(177, __func__, "please fix your prog.c file"); + err(181, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that prog.c triggering an ungetc warning OK"); @@ -4999,7 +5155,7 @@ warn_rule_2b_size(struct info *infop) * firewall */ if (infop == NULL) { - err(178, __func__, "called with NULL infop"); + err(182, __func__, "called with NULL infop"); not_reached(); } @@ -5011,7 +5167,7 @@ warn_rule_2b_size(struct info *infop) ret = fprintf(stderr, "\nWARNING: The prog.c size: %ju > Rule 2b maximum: %ju\n", (uintmax_t)infop->rule_2b_size, (uintmax_t)RULE_2B_SIZE); if (ret <= 0) { - errp(179, __func__, "printf error printing prog.c size > Rule 2b maximum"); + errp(183, __func__, "printf error printing prog.c size > Rule 2b maximum"); not_reached(); } @@ -5028,7 +5184,7 @@ warn_rule_2b_size(struct info *infop) } yorn = yes_or_no("Are you sure you want to submit such a large prog.c file? [Ny]", false); if (!yorn) { - err(180, __func__, "please fix your prog.c file"); + err(184, __func__, "please fix your prog.c file"); not_reached(); } dbg(DBG_MED, "user says that their prog.c size: %ju > Rule 2B max size: %ju is OK", @@ -5065,7 +5221,7 @@ check_prog_c(struct info *infop, char const *prog_c) * firewall */ if (infop == NULL || prog_c == NULL) { - err(181, __func__, "called with NULL arg(s)"); + err(185, __func__, "called with NULL arg(s)"); not_reached(); } /* @@ -5077,7 +5233,7 @@ check_prog_c(struct info *infop, char const *prog_c) "We cannot find the prog.c file.", "", NULL); - err(182, __func__, "prog.c does not exist: %s", prog_c); + err(186, __func__, "prog.c does not exist: %s", prog_c); not_reached(); } if (!is_file(prog_c)) { @@ -5086,7 +5242,7 @@ check_prog_c(struct info *infop, char const *prog_c) "The prog.c path, while it exists, is not a regular file.", "", NULL); - err(183, __func__, "prog.c is not a regular file: %s", prog_c); + err(187, __func__, "prog.c is not a regular file: %s", prog_c); not_reached(); } if (!is_read(prog_c)) { @@ -5095,7 +5251,7 @@ check_prog_c(struct info *infop, char const *prog_c) "The prog.c path, while it is a file, is not readable.", "", NULL); - err(184, __func__, "prog.c is not a readable file: %s", prog_c); + err(188, __func__, "prog.c is not a readable file: %s", prog_c); not_reached(); } @@ -5109,7 +5265,7 @@ check_prog_c(struct info *infop, char const *prog_c) errno = 0; /* pre-clear errno for errp() */ prog_stream = fopen(prog_c, "r"); if (prog_stream == NULL) { - errp(185, __func__, "failed to fopen: %s", prog_c); + errp(189, __func__, "failed to fopen: %s", prog_c); not_reached(); } size = rule_count(prog_stream); @@ -5118,7 +5274,7 @@ check_prog_c(struct info *infop, char const *prog_c) errno = 0; /* pre-clear errno for errp() */ ret = fclose(prog_stream); if (ret != 0) { - errp(186, __func__, "failed to fclose: %s", prog_c); + errp(190, __func__, "failed to fclose: %s", prog_c); not_reached(); } @@ -5128,7 +5284,7 @@ check_prog_c(struct info *infop, char const *prog_c) infop->rule_2a_size = file_size(prog_c); dbg(DBG_MED, "Rule 2a size: %jd", (intmax_t)infop->rule_2a_size); if (infop->rule_2a_size < 0) { - err(187, __func__, "file_size error: %jd on prog.c: %s", (intmax_t)infop->rule_2a_size, prog_c); + err(191, __func__, "file_size error: %jd on prog.c: %s", (intmax_t)infop->rule_2a_size, prog_c); not_reached(); } else if (infop->rule_2a_size == 0 || infop->rule_2b_size == 0) { warn_empty_prog(); @@ -5255,7 +5411,7 @@ inspect_Makefile(char const *Makefile, struct info *infop) * firewall */ if (Makefile == NULL || infop == NULL) { - err(188, __func__, "called with NULL arg(s)"); + err(192, __func__, "called with NULL arg(s)"); not_reached(); } @@ -5265,7 +5421,7 @@ inspect_Makefile(char const *Makefile, struct info *infop) errno = 0; /* pre-clear errno for errp() */ stream = fopen(Makefile, "r"); if (stream == NULL) { - errp(189, __func__, "cannot open Makefile: %s", Makefile); + errp(193, __func__, "cannot open Makefile: %s", Makefile); not_reached(); } @@ -5457,7 +5613,7 @@ inspect_Makefile(char const *Makefile, struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = fclose(stream); if (ret < 0) { - errp(190, __func__, "fclose error"); + errp(194, __func__, "fclose error"); not_reached(); } @@ -5500,7 +5656,7 @@ warn_Makefile(struct info *infop) * firewall */ if (infop == NULL) { - err(191, __func__, "called with NULL infop"); + err(195, __func__, "called with NULL infop"); not_reached(); } if (need_confirm && (!answer_yes || seed_used)) { @@ -5575,7 +5731,7 @@ warn_Makefile(struct info *infop) if (!answer_yes) { yorn = yes_or_no("Do you still want to submit this Makefile in the hopes that it is OK? [Ny]", false); if (!yorn) { - err(192, __func__, "Use a different Makefile or modify your Makefile"); + err(196, __func__, "Use a different Makefile or modify your Makefile"); not_reached(); } } @@ -5604,7 +5760,7 @@ check_Makefile(struct info *infop, char const *Makefile) * firewall */ if (infop == NULL || Makefile == NULL) { - err(193, __func__, "called with NULL arg(s)"); + err(197, __func__, "called with NULL arg(s)"); not_reached(); } @@ -5617,7 +5773,7 @@ check_Makefile(struct info *infop, char const *Makefile) "We cannot find the Makefile.", "", NULL); - err(194, __func__, "Makefile does not exist: %s", Makefile); + err(198, __func__, "Makefile does not exist: %s", Makefile); not_reached(); } if (!is_file(Makefile)) { @@ -5626,7 +5782,7 @@ check_Makefile(struct info *infop, char const *Makefile) "The Makefile path, while it exists, is not a regular file.", "", NULL); - err(195, __func__, "Makefile is not a regular file: %s", Makefile); + err(199, __func__, "Makefile is not a regular file: %s", Makefile); not_reached(); } if (!is_read(Makefile)) { @@ -5635,15 +5791,15 @@ check_Makefile(struct info *infop, char const *Makefile) "The Makefile path, while it is a file, is not readable.", "", NULL); - err(196, __func__, "Makefile is not readable file: %s", Makefile); + err(200, __func__, "Makefile is not readable file: %s", Makefile); not_reached(); } filesize = file_size(Makefile); if (filesize < 0) { - err(197, __func__, "file_size error: %jd on Makefile %s", (intmax_t)filesize, Makefile); + err(201, __func__, "file_size error: %jd on Makefile %s", (intmax_t)filesize, Makefile); not_reached(); } else if (filesize == 0) { - err(198, __func__, "Makefile cannot be empty: %s", Makefile); + err(202, __func__, "Makefile cannot be empty: %s", Makefile); not_reached(); } @@ -5681,7 +5837,7 @@ check_remarks_md(struct info *infop, char const *remarks_md) * firewall */ if (infop == NULL || remarks_md == NULL) { - err(199, __func__, "called with NULL arg(s)"); + err(203, __func__, "called with NULL arg(s)"); not_reached(); } @@ -5694,7 +5850,7 @@ check_remarks_md(struct info *infop, char const *remarks_md) "We cannot find the remarks.md file.", "", NULL); - err(200, __func__, "remarks.md does not exist: %s", remarks_md); + err(204, __func__, "remarks.md does not exist: %s", remarks_md); not_reached(); } if (!is_file(remarks_md)) { @@ -5702,7 +5858,7 @@ check_remarks_md(struct info *infop, char const *remarks_md) "The remarks.md path, while it exists, is not a regular file.", "", NULL); - err(201, __func__, "remarks.md is not a regular file: %s", remarks_md); + err(205, __func__, "remarks.md is not a regular file: %s", remarks_md); not_reached(); } if (!is_read(remarks_md)) { @@ -5711,15 +5867,15 @@ check_remarks_md(struct info *infop, char const *remarks_md) "The remarks.md path, while it is a file, is not readable.", "", NULL); - err(202, __func__, "remarks.md is not readable file: %s", remarks_md); + err(206, __func__, "remarks.md is not readable file: %s", remarks_md); not_reached(); } filesize = file_size(remarks_md); if (filesize < 0) { - err(203, __func__, "file_size error: %jd on remarks.md %s", (intmax_t)filesize, remarks_md); + err(207, __func__, "file_size error: %jd on remarks.md %s", (intmax_t)filesize, remarks_md); not_reached(); } else if (filesize == 0) { - err(204, __func__, "remarks.md cannot be empty: %s", remarks_md); + err(208, __func__, "remarks.md cannot be empty: %s", remarks_md); not_reached(); } @@ -5749,7 +5905,7 @@ yes_or_no(char const *question, bool def_answer) * firewall */ if (question == NULL) { - err(205, __func__, "called with NULL question"); + err(209, __func__, "called with NULL question"); not_reached(); } @@ -5868,7 +6024,7 @@ get_title(struct info *infop) * firewall */ if (infop == NULL) { - err(206, __func__, "called with NULL infop"); + err(210, __func__, "called with NULL infop"); not_reached(); } @@ -5888,7 +6044,7 @@ get_title(struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "Your title must be between 1 and %d ASCII characters long.\n\n", MAX_TITLE_LEN); if (ret <= 0) { - errp(207, __func__, "fprintf #0 error: %d", ret); + errp(211, __func__, "fprintf #0 error: %d", ret); not_reached(); } } @@ -5946,7 +6102,7 @@ get_title(struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "Your title must be between 1 and %d ASCII characters long.\n\n", MAX_TITLE_LEN); if (ret <= 0) { - errp(208, __func__, "fprintf #1 error: %d", ret); + errp(212, __func__, "fprintf #1 error: %d", ret); not_reached(); } if (abort_on_warning) { @@ -6005,7 +6161,7 @@ get_title(struct info *infop) ret = printf("\nThe title you entered is: %s\n", title); if (ret <= 0) { - errp(209, __func__, "fprintf title"); + errp(213, __func__, "fprintf title"); not_reached(); } yorn = yes_or_no("\nIs that title correct? [Yn]", true); @@ -6056,7 +6212,7 @@ get_abstract(struct info *infop) * firewall */ if (infop == NULL) { - err(210, __func__, "called with NULL infp"); + err(214, __func__, "called with NULL infp"); not_reached(); } @@ -6123,7 +6279,7 @@ get_abstract(struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "Your abstract must be between 1 and %d characters long.\n\n", MAX_ABSTRACT_LEN); if (ret <= 0) { - errp(211, __func__, "fprintf error: %d", ret); + errp(215, __func__, "fprintf error: %d", ret); not_reached(); } if (abort_on_warning) { @@ -6149,7 +6305,7 @@ get_abstract(struct info *infop) ret = printf("\nThe abstract you entered is: %s\n", abstract); if (ret <= 0) { - errp(212, __func__, "fprintf abstract"); + errp(216, __func__, "fprintf abstract"); not_reached(); } yorn = yes_or_no("\nIs that abstract correct? [Yn]", true); @@ -6352,7 +6508,7 @@ get_author_info(struct author **author_set_p) * firewall */ if (author_set_p == NULL) { - err(213, __func__, "called with NULL author_set_p"); + err(217, __func__, "called with NULL author_set_p"); not_reached(); } @@ -6374,20 +6530,20 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nThe number of authors must be a number from 1 through %d;\nplease re-enter.\n", MAX_AUTHORS); if (ret <= 0) { - errp(214, __func__, "fprintf error #0 while printing author number range"); + errp(218, __func__, "fprintf error #0 while printing author number range"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nIf you happen to have more than %d authors, we ask that you pick\n", MAX_AUTHORS); if (ret <= 0) { - errp(215, __func__, "fprintf error #1 while printing author number range"); + errp(219, __func__, "fprintf error #1 while printing author number range"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "just %d authors and mention the remaining NUMBER of the authors in\nthe remarks file.\n", MAX_AUTHORS); if (ret <= 0) { - errp(216, __func__, "fprintf error #2 while printing author number range"); + errp(220, __func__, "fprintf error #2 while printing author number range"); not_reached(); } author_count = -1; /* invalidate input */ @@ -6415,7 +6571,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ author_set = (struct author *) malloc(sizeof(struct author) * (size_t)author_count); if (author_set == NULL) { - errp(217, __func__, "malloc a struct author array of length: %d failed", author_count); + errp(221, __func__, "malloc a struct author array of length: %d failed", author_count); not_reached(); } @@ -6451,31 +6607,31 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = puts(ISO_3166_1_CODE_URL0); if (ret < 0) { - errp(218, __func__, "puts error printing ISO 3166-1 URL0"); + errp(222, __func__, "puts error printing ISO 3166-1 URL0"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = puts(ISO_3166_1_CODE_URL1); if (ret < 0) { - errp(219, __func__, "puts error printing ISO 3166-1 URL1"); + errp(223, __func__, "puts error printing ISO 3166-1 URL1"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = puts(ISO_3166_1_CODE_URL2); if (ret < 0) { - errp(220, __func__, "puts error printing ISO 3166-1 URL2"); + errp(224, __func__, "puts error printing ISO 3166-1 URL2"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = puts(ISO_3166_1_CODE_URL3); if (ret < 0) { - errp(221, __func__, "puts error printing ISO 3166-1 URL3"); + errp(225, __func__, "puts error printing ISO 3166-1 URL3"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = puts(ISO_3166_1_CODE_URL4); if (ret < 0) { - errp(222, __func__, "puts error printing ISO 3166-1 URL4"); + errp(226, __func__, "puts error printing ISO 3166-1 URL4"); not_reached(); } para("", @@ -6507,7 +6663,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = printf("\nEnter information for author #%d\n\n", i); if (ret <= 0) { - errp(223, __func__, "printf error printing author number"); + errp(227, __func__, "printf error printing author number"); not_reached(); } author_set[i].author_num = i; @@ -6560,7 +6716,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit names to %d characters\n\n", MAX_NAME_LEN); if (ret <= 0) { - errp(224, __func__, "fprintf error while reject name that is too long"); + errp(228, __func__, "fprintf error while reject name that is too long"); not_reached(); } if (abort_on_warning) { @@ -6589,7 +6745,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nauthor #%d name duplicates previous author #%d name", i, j); if (ret <= 0) { - errp(225, __func__, "fprintf error while reject duplicate name"); + errp(229, __func__, "fprintf error while reject duplicate name"); not_reached(); } if (abort_on_warning) { @@ -6643,7 +6799,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "%s\n\n", ISO_3166_1_CODE_URL0); if (ret <= 0) { - errp(226, __func__, "fprintf while printing ISO 3166-1 CODE URL #0"); + errp(230, __func__, "fprintf while printing ISO 3166-1 CODE URL #0"); not_reached(); } fpara(stderr, @@ -6653,19 +6809,19 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "%s\n", ISO_3166_1_CODE_URL1); if (ret <= 0) { - errp(227, __func__, "fprintf while printing ISO 3166-1 CODE URL #1"); + errp(231, __func__, "fprintf while printing ISO 3166-1 CODE URL #1"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n", ISO_3166_1_CODE_URL2); if (ret <= 0) { - errp(228, __func__, "fprintf while printing ISO 3166-1 CODE URL #2"); + errp(232, __func__, "fprintf while printing ISO 3166-1 CODE URL #2"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n\n", ISO_3166_1_CODE_URL3); if (ret <= 0) { - errp(229, __func__, "fprintf while printing ISO 3166-1 CODE URL #3"); + errp(233, __func__, "fprintf while printing ISO 3166-1 CODE URL #3"); not_reached(); } if (abort_on_warning) { @@ -6714,7 +6870,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n\n", ISO_3166_1_CODE_URL0); if (ret <= 0) { - errp(230, __func__, "fprintf when printing ISO 3166-1 CODE URL #0"); + errp(234, __func__, "fprintf when printing ISO 3166-1 CODE URL #0"); not_reached(); } fpara(stderr, @@ -6724,19 +6880,19 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n", ISO_3166_1_CODE_URL1); if (ret <= 0) { - errp(231, __func__, "fprintf when printing ISO 3166-1 CODE URL #1"); + errp(235, __func__, "fprintf when printing ISO 3166-1 CODE URL #1"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n", ISO_3166_1_CODE_URL2); if (ret <= 0) { - errp(232, __func__, "fprintf when printing ISO 3166-1 CODE URL #2"); + errp(236, __func__, "fprintf when printing ISO 3166-1 CODE URL #2"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, " %s\n\n", ISO_3166_1_CODE_URL3); if (ret <= 0) { - errp(233, __func__, "fprintf when printing ISO 3166-1 CODE URL #3"); + errp(237, __func__, "fprintf when printing ISO 3166-1 CODE URL #3"); not_reached(); } if (abort_on_warning) { @@ -6771,7 +6927,7 @@ get_author_info(struct author **author_set_p) ret = printf("\nThe location/country code you entered is assigned to: %s (%s)\n", author_set[i].location_name, author_set[i].common_name); if (ret <= 0) { - errp(234, __func__, "fprintf location/country code assignment"); + errp(238, __func__, "fprintf location/country code assignment"); not_reached(); } yorn = yes_or_no("\nIs that location/country code correct? [Yn]", true); @@ -6826,7 +6982,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit email address to %d characters\n", MAX_EMAIL_LEN); if (ret <= 0) { - errp(235, __func__, "fprintf error while printing Email address length limit"); + errp(239, __func__, "fprintf error while printing Email address length limit"); not_reached(); } fpara(stderr, @@ -6884,7 +7040,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit URLs to %d characters.\n\n", MAX_URL_LEN); if (ret <= 0) { - errp(236, __func__, "fprintf error while printing URL length limit"); + errp(240, __func__, "fprintf error while printing URL length limit"); not_reached(); } if (abort_on_warning) { @@ -6980,7 +7136,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit URLs to %d characters\n\n", MAX_URL_LEN); if (ret <= 0) { - errp(237, __func__, "fprintf error while printing URL length limit"); + errp(241, __func__, "fprintf error while printing URL length limit"); not_reached(); } if (abort_on_warning) { @@ -7076,7 +7232,7 @@ get_author_info(struct author **author_set_p) ret = fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit Mastodon handles to %d " "characters, starting with the @\n\n", MAX_MASTODON_LEN); if (ret <= 0) { - errp(238, __func__, "fprintf error while printing mastodon handle length limit"); + errp(242, __func__, "fprintf error while printing mastodon handle length limit"); not_reached(); } if (abort_on_warning) { @@ -7166,7 +7322,7 @@ get_author_info(struct author **author_set_p) "\nSorry ( tm Canada :-) ), we limit GitHub account names to %d characters after the 1st @.\n\n", MAX_GITHUB_LEN); if (ret <= 0) { - errp(239, __func__, "fprintf error while printing GitHub user length limit"); + errp(243, __func__, "fprintf error while printing GitHub user length limit"); not_reached(); } if (abort_on_warning) { @@ -7253,7 +7409,7 @@ get_author_info(struct author **author_set_p) fprintf(stderr, "\nSorry ( tm Canada :-) ), we limit affiliation names to %d characters\n\n", MAX_AFFILIATION_LEN); if (ret <= 0) { - errp(240, __func__, "fprintf error while printing affiliation length limit"); + errp(244, __func__, "fprintf error while printing affiliation length limit"); not_reached(); } if (abort_on_warning) { @@ -7330,7 +7486,7 @@ get_author_info(struct author **author_set_p) */ def_handle = default_handle(author_set[i].name); if (def_handle == NULL) { - err(241, __func__, "default_handle() returned NULL!"); + err(245, __func__, "default_handle() returned NULL!"); not_reached(); } dbg(DBG_VHIGH, "default IOCCC author handle: <%s>", def_handle); @@ -7338,7 +7494,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = printf("\nThe default IOCCC author handle for author #%d is:\n\n %s\n\n", i, def_handle); if (ret <= 0) { - errp(242, __func__, "fprintf error while printing default IOCCC author handle"); + errp(246, __func__, "fprintf error while printing default IOCCC author handle"); not_reached(); } } @@ -7401,7 +7557,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nThe IOCCC author handle is limited to %d characters\n\n", MAX_HANDLE); if (ret <= 0) { - errp(243, __func__, "fprintf error while printing IOCCC author handle length limit"); + errp(247, __func__, "fprintf error while printing IOCCC author handle length limit"); not_reached(); } if (abort_on_warning) { @@ -7432,7 +7588,7 @@ get_author_info(struct author **author_set_p) errno = 0; /* pre-clear errno for errp() */ ret = fprintf(stderr, "\nauthor #%d author_handle duplicates previous author #%d author_handle", i, j); if (ret <= 0) { - errp(244, __func__, "fprintf error while printing duplicate author_handle error"); + errp(248, __func__, "fprintf error while printing duplicate author_handle error"); not_reached(); } if (abort_on_warning) { @@ -7479,7 +7635,7 @@ get_author_info(struct author **author_set_p) printf("IOCCC author handle was manually entered\n")) <= 0 || ((author_set[i].author_handle[0] == '\0') ? printf("IOCCC author handle\n\n") : printf("IOCCC author handle: %s\n\n", author_set[i].author_handle)) <= 0) { - errp(245, __func__, "error while printing author #%d information\n", i); + errp(249, __func__, "error while printing author #%d information\n", i); not_reached(); } if (need_confirm) { @@ -7533,7 +7689,7 @@ verify_submission_dir(char const *submission_dir, char const *ls) * firewall */ if (submission_dir == NULL || ls == NULL) { - err(246, __func__, "called with NULL arg(s)"); + err(10, __func__, "called with NULL arg(s)"); not_reached(); } @@ -7546,7 +7702,7 @@ verify_submission_dir(char const *submission_dir, char const *ls) errno = 0; /* pre-clear errno for errp() */ ret = printf(" %s\n", submission_dir); if (ret <= 0) { - errp(247, __func__, "printf error code: %d", ret); + errp(11, __func__, "printf error code: %d", ret); not_reached(); } para("", @@ -7556,7 +7712,7 @@ verify_submission_dir(char const *submission_dir, char const *ls) dbg(DBG_HIGH, "about to perform: cd -- %s && %s -lakR .", submission_dir, ls); exit_code = shell_cmd(__func__, false, true, "cd -- % && % -lakR .", submission_dir, ls); if (exit_code != 0) { - err(248, __func__, "cd -- %s && %s -lakR . failed with exit code: %d", + err(12, __func__, "cd -- %s && %s -lakR . failed with exit code: %d", submission_dir, ls, WEXITSTATUS(exit_code)); not_reached(); } @@ -7567,7 +7723,7 @@ verify_submission_dir(char const *submission_dir, char const *ls) dbg(DBG_HIGH, "about to popen: cd -- %s && %s -lakR .", submission_dir, ls); ls_stream = pipe_open(__func__, false, true, "cd -- % && % -lakR .", submission_dir, ls); if (ls_stream == NULL) { - err(249, __func__, "popen filed for: cd -- %s && %s -lakR .", submission_dir, ls); + err(13, __func__, "popen filed for: cd -- %s && %s -lakR .", submission_dir, ls); not_reached(); } @@ -7599,18 +7755,18 @@ verify_submission_dir(char const *submission_dir, char const *ls) * no line was read at all */ if (readline_len < 0 && i == 0) { - err(10, __func__, "EOF while reading output of ls: %s", ls); + err(14, __func__, "EOF while reading output of ls: %s", ls); not_reached(); } /* * lines were read from ls but nothing correct was found */ if (i == 0) { - err(11, __func__, "found no k-block line in ls output"); + err(15, __func__, "found no k-block line in ls output"); not_reached(); } if (kdirsize <= 0) { - err(12, __func__, "ls k-block value: %d <= 0", kdirsize); + err(16, __func__, "ls k-block value: %d <= 0", kdirsize); not_reached(); } dbg(DBG_MED, "Directory %s size in kibibyte (1024 byte blocks): %d", submission_dir, kdirsize); @@ -7689,7 +7845,7 @@ form_info(struct info *infop) * firewall */ if (infop == NULL) { - err(13, __func__, "passed NULL infop"); + err(17, __func__, "passed NULL infop"); not_reached(); } /* @@ -7708,13 +7864,13 @@ form_info(struct info *infop) errno = 0; /* pre-clear errno for errp() */ ret = setenv("TZ", "UTC", 1); if (ret < 0) { - errp(14, __func__, "cannot set TZ=UTC"); + errp(18, __func__, "cannot set TZ=UTC"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ timeptr = gmtime(&(infop->tstamp)); if (timeptr == NULL) { - errp(15, __func__, "gmtime returned NULL"); + errp(19, __func__, "gmtime returned NULL"); not_reached(); } @@ -7725,7 +7881,7 @@ form_info(struct info *infop) errno = 0; /* pre-clear errno for errp() */ infop->utctime = (char *)calloc(utctime_len + 1, sizeof(char)); /* + 1 for paranoia padding */ if (infop->utctime == NULL) { - errp(16, __func__, "calloc of %ju bytes failed", (uintmax_t)utctime_len + 1); + errp(20, __func__, "calloc of %ju bytes failed", (uintmax_t)utctime_len + 1); not_reached(); } @@ -7740,7 +7896,7 @@ form_info(struct info *infop) errno = 0; /* pre-clear errno for errp() */ strftime_ret = strftime(infop->utctime, utctime_len, "%a %b %d %H:%M:%S %Y UTC", timeptr); if (strftime_ret == 0) { - errp(17, __func__, "strftime returned 0"); + errp(21, __func__, "strftime returned 0"); not_reached(); } dbg(DBG_VHIGH, "infop->utctime: %s", infop->utctime); @@ -7782,7 +7938,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ * firewall */ if (infop == NULL || authp == NULL || submission_dir == NULL || chkentry == NULL) { - err(18, __func__, "called with NULL arg(s)"); + err(22, __func__, "called with NULL arg(s)"); not_reached(); } @@ -7790,10 +7946,10 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ * first write .auth.json */ if (authp->author_count <= 0) { - err(19, __func__, "author_count %d <= 0", authp->author_count); + err(23, __func__, "author_count %d <= 0", authp->author_count); not_reached(); } else if (authp->author_count > MAX_AUTHORS) { - err(20, __func__, "author count %d > max authors %d", authp->author_count, MAX_AUTHORS); + err(24, __func__, "author count %d > max authors %d", authp->author_count, MAX_AUTHORS); not_reached(); } @@ -7804,27 +7960,27 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ auth_path = (char *)malloc(auth_path_len + 1); if (auth_path == NULL) { - errp(21, __func__, "malloc of %ju bytes failed", (uintmax_t)auth_path_len + 1); + errp(25, __func__, "malloc of %ju bytes failed", (uintmax_t)auth_path_len + 1); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = snprintf(auth_path, auth_path_len, "%s/%s", submission_dir, AUTH_JSON_FILENAME); if (ret <= 0) { - errp(22, __func__, "snprintf #0 error: %d", ret); + errp(26, __func__, "snprintf #0 error: %d", ret); not_reached(); } dbg(DBG_HIGH, ".auth.json path: %s", auth_path); errno = 0; /* pre-clear errno for errp() */ auth_stream = fopen(auth_path, "w"); if (auth_stream == NULL) { - errp(23, __func__, "failed to open for writing: %s", auth_path); + errp(27, __func__, "failed to open for writing: %s", auth_path); not_reached(); } errno = 0; /* pre-clear errno for errp() */ fd = open(auth_path, O_WRONLY|O_CLOEXEC, S_IRWXU); if (fd < 0) { - err(24, __func__, "failed to obtain file descriptor for: %s", auth_path); + err(28, __func__, "failed to obtain file descriptor for: %s", auth_path); not_reached(); } @@ -7847,7 +8003,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_bool(auth_stream, " ", "test_mode", " : ", authp->test_mode, ",\n") && fprintf(auth_stream, " \"authors\" : [\n") > 0; if (!ret) { - errp(25, __func__, "fprintf error writing leading part of authorship to %s", auth_path); + errp(29, __func__, "fprintf error writing leading part of authorship to %s", auth_path); not_reached(); } @@ -7874,7 +8030,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_long(auth_stream, " ", "author_number", " : ", ap->author_num, "\n") && fprintf(auth_stream, " }%s\n", (((i + 1) < authp->author_count) ? "," : "")) > 0; if (ret == false) { - errp(26, __func__, "fprintf error writing author %d info to %s", i, auth_path); + errp(30, __func__, "fprintf error writing author %d info to %s", i, auth_path); not_reached(); } } @@ -7890,7 +8046,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_long(auth_stream, " ", "min_timestamp", " : ", MIN_TIMESTAMP, "\n") && fprintf(auth_stream, "}\n") > 0; if (!ret) { - errp(27, __func__, "fprintf error writing trailing part of authorship to %s", auth_path); + errp(31, __func__, "fprintf error writing trailing part of authorship to %s", auth_path); not_reached(); } @@ -7900,7 +8056,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ ret = fclose(auth_stream); if (ret < 0) { - errp(28, __func__, "fclose error"); + errp(32, __func__, "fclose error"); not_reached(); } @@ -7910,7 +8066,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ ret = fchmod(fd, S_IRUSR | S_IRGRP | S_IROTH); if (ret != 0) { - err(29, __func__, "chmod(2) failed to set user, group and other read-only on %s", auth_path); + err(33, __func__, "chmod(2) failed to set user, group and other read-only on %s", auth_path); not_reached(); } @@ -7920,7 +8076,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear for errp() */ ret = close(fd); if (ret < 0) { - errp(30, __func__, "close(fd) failed"); + errp(34, __func__, "close(fd) failed"); not_reached(); } @@ -7928,7 +8084,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ * now write .info.json */ if (infop->required_files == NULL) { - err(31, __func__, "called with NULL files list"); + err(35, __func__, "called with NULL files list"); not_reached(); } @@ -7939,20 +8095,20 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ info_path = (char *)malloc(info_path_len + 1); if (info_path == NULL) { - errp(32, __func__, "malloc of %ju bytes failed", (uintmax_t)info_path_len + 1); + errp(36, __func__, "malloc of %ju bytes failed", (uintmax_t)info_path_len + 1); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = snprintf(info_path, info_path_len, "%s/%s", submission_dir, INFO_JSON_FILENAME); if (ret <= 0) { - errp(33, __func__, "snprintf #0 error: %d", ret); + errp(37, __func__, "snprintf #0 error: %d", ret); not_reached(); } dbg(DBG_HIGH, ".info.json path: %s", info_path); errno = 0; /* pre-clear errno for errp() */ info_stream = fopen(info_path, "w"); if (info_stream == NULL) { - errp(34, __func__, "failed to open for writing: %s", info_path); + errp(38, __func__, "failed to open for writing: %s", info_path); not_reached(); } @@ -7962,7 +8118,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ fd = open(info_path, O_WRONLY|O_CLOEXEC, S_IRWXU); if (fd < 0) { - errp(35, __func__, "failed to obtain file descriptor for: %s", info_path); + errp(39, __func__, "failed to obtain file descriptor for: %s", info_path); not_reached(); } @@ -8005,7 +8161,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_bool(info_stream, " ", "test_mode", " : ", infop->test_mode, ",\n") && fprintf(info_stream, " \"manifest\" : [\n") > 0; if (!ret) { - errp(36, __func__, "fprintf error writing leading part of info to %s", info_path); + errp(40, __func__, "fprintf error writing leading part of info to %s", info_path); not_reached(); } @@ -8038,7 +8194,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_string(info_stream, " ", "remarks", " : ", "remarks.md", "\n") && fprintf(info_stream, " }%s\n", (infop->extra_count > 0) ? "," : "") > 0; if (!ret) { - errp(37, __func__, "fprintf error writing mandatory filename to %s", info_path); + errp(41, __func__, "fprintf error writing mandatory filename to %s", info_path); not_reached(); } @@ -8049,14 +8205,14 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ for (j = 0; j < infop->extra_count; ++j) { p = dyn_array_value(infop->extra_files, char *, j); if (p == NULL) { - err(38, __func__, "found NULL pointer in files list, element: %ju", (uintmax_t)j); + err(42, __func__, "found NULL pointer in files list, element: %ju", (uintmax_t)j); not_reached(); } ret = fprintf(info_stream, " {\n") > 0 && json_fprintf_value_string(info_stream, " ", "extra_file", " : ", p, "\n") && fprintf(info_stream, " }%s\n", ((j+1) < infop->extra_count) ? "," : "") > 0; if (!ret) { - errp(39, __func__, "fprintf error writing extra filename[%ju] to %s", (uintmax_t)j, info_path); + errp(43, __func__, "fprintf error writing extra filename[%ju] to %s", (uintmax_t)j, info_path); not_reached(); } } @@ -8072,7 +8228,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ json_fprintf_value_long(info_stream, " ", "min_timestamp", " : ", MIN_TIMESTAMP, "\n") && fprintf(info_stream, "}\n") > 0; if (!ret) { - errp(40, __func__, "fprintf error writing trailing part of info to %s", info_path); + errp(44, __func__, "fprintf error writing trailing part of info to %s", info_path); not_reached(); } @@ -8082,7 +8238,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ ret = fclose(info_stream); if (ret < 0) { - errp(41, __func__, "fclose error"); + errp(45, __func__, "fclose error"); not_reached(); } @@ -8093,7 +8249,7 @@ write_json_files(struct auth *authp, struct info *infop, char const *submission_ errno = 0; /* pre-clear errno for errp() */ ret = fchmod(fd, S_IRUSR | S_IRGRP | S_IROTH); if (ret != 0) { - err(42, __func__, "chmod(2) failed to set user, group and other read-only on %s", info_path); + err(46, __func__, "chmod(2) failed to set user, group and other read-only on %s", info_path); not_reached(); } @@ -8145,19 +8301,19 @@ form_auth(struct auth *authp, struct info *infop, int author_count, struct autho * firewall */ if (authp == NULL || infop == NULL || authorp == NULL) { - err(43, __func__, "called with NULL arg(s)"); + err(47, __func__, "called with NULL arg(s)"); not_reached(); } if (infop->ioccc_id == NULL) { - err(44, __func__, "infop->ioccc_id is NULL"); + err(48, __func__, "infop->ioccc_id is NULL"); not_reached(); } if (infop->tarball == NULL) { - err(45, __func__, "infop->tarball is NULL"); + err(49, __func__, "infop->tarball is NULL"); not_reached(); } if (infop->utctime == NULL) { - err(46, __func__, "infop->utctime is NULL"); + err(50, __func__, "infop->utctime is NULL"); not_reached(); } memset(authp, 0, sizeof(*authp)); @@ -8181,14 +8337,14 @@ form_auth(struct auth *authp, struct info *infop, int author_count, struct autho errno = 0; /* pre-clear errno for errp() */ authp->ioccc_id = strdup(infop->ioccc_id); if (authp->ioccc_id == NULL) { - errp(47, __func__, "strdup() ioccc_id path %s failed", infop->ioccc_id); + errp(51, __func__, "strdup() ioccc_id path %s failed", infop->ioccc_id); not_reached(); } authp->submit_slot = infop->submit_slot; errno = 0; /* pre-clear errno for errp() */ authp->tarball = strdup(infop->tarball); if (authp->tarball == NULL) { - errp(48, __func__, "strdup() tarball path %s failed", infop->tarball); + errp(52, __func__, "strdup() tarball path %s failed", infop->tarball); not_reached(); } /* copy over test or non-test mode */ @@ -8210,7 +8366,7 @@ form_auth(struct auth *authp, struct info *infop, int author_count, struct autho errno = 0; /* pre-clear errno for errp() */ authp->utctime = strdup(infop->utctime); if (authp->utctime == NULL) { - errp(49, __func__, "strdup() utctime path %s failed", infop->utctime); + errp(53, __func__, "strdup() utctime path %s failed", infop->utctime); not_reached(); } return; @@ -8253,7 +8409,7 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal */ if (workdir == NULL || submission_dir == NULL || tarball_path == NULL || tar == NULL || ls == NULL || txzchk == NULL || fnamchk == NULL) { - err(50, __func__, "called with NULL arg(s)"); + err(54, __func__, "called with NULL arg(s)"); not_reached(); } @@ -8269,7 +8425,7 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal errno = 0; /* pre-clear errno for errp() */ cwd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC); if (cwd < 0) { - errp(51, __func__, "cannot open ."); + errp(55, __func__, "cannot open ."); not_reached(); } @@ -8279,7 +8435,7 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal errno = 0; /* pre-clear errno for errp() */ ret = chdir(workdir); if (ret < 0) { - errp(52, __func__, "cannot cd %s", workdir); + errp(56, __func__, "cannot cd %s", workdir); not_reached(); } @@ -8304,10 +8460,10 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal basename_tarball_path = base_name(tarball_path); dbg(DBG_HIGH, "about to perform: %s --format=v7 -cJf %s -- %s", tar, basename_tarball_path, basename_submission_dir); - exit_code = shell_cmd(__func__, false, true, "% --format=v7 -cJf % -- %", - tar, basename_tarball_path, basename_submission_dir); + exit_code = shell_cmd(__func__, false, true, "tar --format=v7 -cJf % -- %", + basename_tarball_path, basename_submission_dir); if (exit_code != 0) { - err(53, __func__, "%s --format=v7 -cJf %s -- %s failed with exit code: %d", + err(57, __func__, "%s --format=v7 -cJf %s -- %s failed with exit code: %d", tar, basename_tarball_path, basename_submission_dir, WEXITSTATUS(exit_code)); not_reached(); } @@ -8318,7 +8474,7 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal errno = 0; /* pre-clear errno for errp() */ ret = stat(basename_tarball_path, &buf); if (ret != 0) { - errp(54, __func__, "stat of the compressed tarball failed: %s", basename_tarball_path); + errp(58, __func__, "stat of the compressed tarball failed: %s", basename_tarball_path); not_reached(); } if (buf.st_size > MAX_TARBALL_LEN) { @@ -8327,7 +8483,7 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal "The compressed tarball exceeds the maximum allowed size, sorry.", "", NULL); - err(55, __func__, "The compressed tarball: %s size: %ju > %jd", + err(59, __func__, "The compressed tarball: %s size: %ju > %jd", basename_tarball_path, (uintmax_t)buf.st_size, (intmax_t)MAX_TARBALL_LEN); not_reached(); } @@ -8338,13 +8494,13 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal errno = 0; /* pre-clear errno for errp() */ ret = fchdir(cwd); if (ret < 0) { - errp(56, __func__, "cannot fchdir to the previous current directory"); + errp(60, __func__, "cannot fchdir to the previous current directory"); not_reached(); } errno = 0; /* pre-clear errno for errp() */ ret = close(cwd); if (ret < 0) { - errp(57, __func__, "close of previous current directory failed"); + errp(61, __func__, "close of previous current directory failed"); not_reached(); } @@ -8365,10 +8521,10 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal } if (exit_code != 0) { if (test_mode) { - err(58, __func__, "%s -x -e -f %ju -w -v 1 -F %s -- %s/../%s failed with exit code: %d", + err(62, __func__, "%s -x -e -f %ju -w -v 1 -F %s -- %s/../%s failed with exit code: %d", txzchk, feathery, fnamchk, submission_dir, basename_tarball_path, WEXITSTATUS(exit_code)); } else { - err(59, __func__, "%s -e -f %ju -w -v 1 -F %s -- %s/../%s failed with exit code: %d", + err(63, __func__, "%s -e -f %ju -w -v 1 -F %s -- %s/../%s failed with exit code: %d", txzchk, feathery, fnamchk, submission_dir, basename_tarball_path, WEXITSTATUS(exit_code)); } not_reached(); @@ -8388,10 +8544,10 @@ form_tarball(char const *workdir, char const *submission_dir, char const *tarbal } if (exit_code != 0) { if (test_mode) { - err(60, __func__, "%s -x -w -v 1 -F %s -- %s/../%s failed with exit code: %d", + err(64, __func__, "%s -x -w -v 1 -F %s -- %s/../%s failed with exit code: %d", txzchk, fnamchk, submission_dir, basename_tarball_path, WEXITSTATUS(exit_code)); } else { - err(61, __func__, "%s -w -v 1 -F %s -- %s/../%s failed with exit code: %d", + err(65, __func__, "%s -w -v 1 -F %s -- %s/../%s failed with exit code: %d", txzchk, fnamchk, submission_dir, basename_tarball_path, WEXITSTATUS(exit_code)); } not_reached(); @@ -8442,13 +8598,13 @@ remind_user(char const *workdir, char const *submission_dir, char const *tar, ch * firewall */ if (workdir == NULL || submission_dir == NULL || tar == NULL || tarball_path == NULL) { - err(62, __func__, "called with NULL arg(s)"); + err(66, __func__, "called with NULL arg(s)"); not_reached(); } submission_dir_esc = cmdprintf("%", submission_dir); if (submission_dir_esc == NULL) { - err(63, __func__, "failed to cmdprintf: submission_dir"); + err(67, __func__, "failed to cmdprintf: submission_dir"); not_reached(); } @@ -8461,14 +8617,14 @@ remind_user(char const *workdir, char const *submission_dir, char const *tar, ch NULL); ret = printf(" rm -rf %s%s\n", submission_dir[0] == '-' ? "-- " : "", submission_dir_esc); if (ret <= 0) { - errp(64, __func__, "printf #0 error"); + errp(68, __func__, "printf #0 error"); not_reached(); } free(submission_dir_esc); workdir_esc = cmdprintf("%", workdir); if (workdir_esc == NULL) { - err(65, __func__, "failed to cmdprintf: workdir"); + err(69, __func__, "failed to cmdprintf: workdir"); not_reached(); } @@ -8479,7 +8635,7 @@ remind_user(char const *workdir, char const *submission_dir, char const *tar, ch NULL); ret = printf(" %s -Jtvf %s%s/%s\n", tar, workdir[0] == '-' ? "./" : "", workdir_esc, tarball_path); if (ret <= 0) { - errp(66, __func__, "printf #2 error"); + errp(70, __func__, "printf #2 error"); not_reached(); } free(workdir_esc); @@ -8551,7 +8707,7 @@ show_registration_url(void) errno = 0; /* pre-clear errno for errp() */ ret = printf(" %s\n", IOCCC_REGISTER_URL); if (ret <= 0) { - errp(67, __func__, "printf error printing IOCCC_REGISTER_URL"); + errp(71, __func__, "printf error printing IOCCC_REGISTER_URL"); not_reached(); } para("", @@ -8561,7 +8717,7 @@ show_registration_url(void) errno = 0; /* pre-clear errno for errp() */ ret = printf(" %s\n", IOCCC_REGISTER_FAQ_URL); if (ret <= 0) { - errp(68, __func__, "printf error printing IOCCC register FAQ URL"); + errp(72, __func__, "printf error printing IOCCC register FAQ URL"); not_reached(); } para("", @@ -8571,7 +8727,7 @@ show_registration_url(void) errno = 0; /* pre-clear errno for errp() */ ret = printf(" %s\n %s\n %s\n", IOCCC_REGISTER_INFO_URL, IOCCC_PW_CHANGE_INFO_URL, IOCCC_SUBMIT_INFO_URL); if (ret <= 0) { - errp(69, __func__, "printf error printing IOCCC_REGISTER_INFO_URL, IOCCC_PW_CHANGE_INFO_URL and IOCCC_SUBMIT_INFO_URL"); + errp(73, __func__, "printf error printing IOCCC_REGISTER_INFO_URL, IOCCC_PW_CHANGE_INFO_URL and IOCCC_SUBMIT_INFO_URL"); not_reached(); } @@ -8583,7 +8739,7 @@ show_registration_url(void) errno = 0; /* pre-clear errno for errp() */ ret = printf(" %s\n", IOCCC_STATUS_URL); if (ret < 0) { - errp(70, __func__, "printf error printing IOCCC status URL"); + errp(74, __func__, "printf error printing IOCCC status URL"); not_reached(); } @@ -8620,7 +8776,7 @@ show_submit_url(char const *workdir, char const *tarball_path, int slot_number) "after you have registered, you must upload into slot %d:\n\n\t%s/%s\n", slot_number, workdir, tarball_path); if (ret <= 0) { - errp(71, __func__, "printf error printing tarball path and slot number"); + errp(75, __func__, "printf error printing tarball path and slot number"); not_reached(); } para("", @@ -8630,7 +8786,7 @@ show_submit_url(char const *workdir, char const *tarball_path, int slot_number) ret = printf(" %s\n", IOCCC_SUBMIT_URL); if (ret < 0) { - errp(72, __func__, "printf error printing IOCCC submit URL"); + errp(76, __func__, "printf error printing IOCCC submit URL"); not_reached(); } @@ -8641,7 +8797,7 @@ show_submit_url(char const *workdir, char const *tarball_path, int slot_number) ret = printf(" %s\n", IOCCC_ENTER_FAQ_URL); if (ret < 0) { - errp(73, __func__, "printf error printing IOCCC enter FAQ URL"); + errp(77, __func__, "printf error printing IOCCC enter FAQ URL"); not_reached(); } } diff --git a/mkiocccentry.h b/mkiocccentry.h index a11a3e70..93e78e41 100644 --- a/mkiocccentry.h +++ b/mkiocccentry.h @@ -177,14 +177,15 @@ static void copy_topdir(struct info *infop, char const *make, char const *submis char *submit_path, int topdir, int cwd, RuleCount *size); static void check_submission_dir(struct info *infop, char *submit_path, char *topdir_path, char const *make, RuleCount *size, int cwd); -static void mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char const *tar, - char const *ls, char const *txzchk, char const *fnamchk, char const *chkentry, - char const *make); +static void mkiocccentry_sanity_chks(struct info *infop, char const *workdir, char *tar, + char *ls, char *txzchk, char *fnamchk, char *chkentry, + char *make, char *rm); static char *prompt(char const *str, size_t *lenp); -static char *get_contest_id(bool *testp, FILE *uuidp); +static char *get_contest_id(bool *testp, char const *uuidf, char *uuidstr); static int get_submit_slot(struct info *infop); static char *mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot, - char **tarball_path, time_t tstamp, bool test_mode); + char **tarball_path, time_t tstamp, bool test_mode, bool force_remove, + char const *rm); static bool inspect_Makefile(char const *Makefile, struct info *infop); static void warn_Makefile(struct info *infop); static void check_Makefile(struct info *infop, char const *Makefile); diff --git a/soup/man/man1/mkiocccentry.1 b/soup/man/man1/mkiocccentry.1 index 256d5d71..397649e1 100644 --- a/soup/man/man1/mkiocccentry.1 +++ b/soup/man/man1/mkiocccentry.1 @@ -9,7 +9,7 @@ .\" "Share and Enjoy!" .\" -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-) .\" -.TH mkiocccentry 1 "08 March 2025" "mkiocccentry" "IOCCC tools" +.TH mkiocccentry 1 "10 March 2025" "mkiocccentry" "IOCCC tools" .SH NAME .B mkiocccentry \- make an IOCCC compressed tarball for an IOCCC entry @@ -220,7 +220,8 @@ if this option is not specified. Pass .B \-e to -.BR txzchk (1). +.BR txzchk (1) +(entertainment mode). .TP .BI \-f\ feathers Pass @@ -297,11 +298,34 @@ This option implies and disables some messages as well. However you will still be prompted to verify files and directories are okay. .TP -.BI \-u\ uuid +.BI \-u\ uuidfile Read UUID from a text file. -If this file cannot be read or does not have a valid UUID +If this file cannot be read or does not have a valid UUID by itself, +.BR mkiocccentry (1) +will prompt you as usual. +This option cannot be used with +.BI \-U\ UUID +or +.BI \-s\ seed +or +.BI \-i\ answers +or +.BR \-d . +.TP +.BI \-U\ UUID +Set UUID to +.IR UUID . +If this an invalid UUID .BR mkiocccentry (1) will prompt you as usual. +This option cannot be used with +.BI \-u\ uuidfile +or +.BI \-s\ seed +or +.BI \-i\ answers +or +.BR \-d . .TP .BI \-s\ seed Generate pseudo-random answers to the questions @@ -361,6 +385,18 @@ option. If the path is a directory .BR mkiocccentry (1) will not traverse it. +.TP +.BI \-r\ rm +Set path to +.BR rm (1) +if +.B \-x +used. +.TP +.B \-x +Force delete submission directory if it already exists. +Use with +.BR CARE ! .SH EXIT STATUS .TP 0 diff --git a/soup/sanity.c b/soup/sanity.c index 3746ec36..740978ea 100644 --- a/soup/sanity.c +++ b/soup/sanity.c @@ -55,6 +55,56 @@ */ const char *const soup_version = SOUP_VERSION; /* library version format: major.minor YYYY-MM-DD */ +char *tar_paths[] = +{ + TAR_PATH_0, + TAR_PATH_0, + TAR_PATH_2, + NULL /* MUST BE LAST!! */ +}; +char *ls_paths[] = +{ + LS_PATH_0, + LS_PATH_1, + LS_PATH_2, + NULL /* MUST BE LAST!! */ +}; +char *fnamchk_paths[] = +{ + FNAMCHK_PATH_0, + FNAMCHK_PATH_1, + FNAMCHK_PATH_2, + NULL /* MUST BE LAST!! */ +}; +char *txzchk_paths[] = +{ + TXZCHK_PATH_0, + TXZCHK_PATH_1, + TXZCHK_PATH_2, + NULL /* MUST BE LAST!! */ +}; +char *chkentry_paths[] = +{ + CHKENTRY_PATH_0, + CHKENTRY_PATH_1, + CHKENTRY_PATH_2, + NULL /* MUST BE LAST!! */ +}; +char *make_paths[] = +{ + MAKE_PATH_0, + MAKE_PATH_1, + MAKE_PATH_2, + MAKE_PATH_3, + NULL /* MUST BE LAST!! */ +}; +char *rm_paths[] = +{ + RM_PATH_0, + RM_PATH_1, + RM_PATH_1, + NULL /* MUST BE LAST!! */ +}; /* * ioccc_sanity_chks - perform IOCCC sanity checks @@ -86,65 +136,337 @@ ioccc_sanity_chks(void) /* - * find_utils - find tar, ls, txzchk and fnamchk, chkentry utilities + * find_utils - find tools used by various tools * * given: * - * tar_flag_used - true ==> -t tar was used - * tar - if -t tar was not used and tar != NULL set *tar to to tar path - * ls_flag_used - true ==> -l ls was used - * ls - if -l ls was not used and ls != NULL set *ls to ls path - * txzchk_flag_used - true ==> -T flag used - * txzchk - if -T txzchk was used and txzchk != NULL set *txzchk to path - * fnamchk_flag_used - true ==> if fnamchk flag was used - * fnamchk - if fnamchk option used and fnamchk ! NULL set *fnamchk to path - * chkentry_flag_used - true ==> -C chkentry was used - - * chkentry - if -C chkentry was used and chkentry != NULL set *chkentry to path - * make_flag_used - true ==> -m make was used - * make - if -m make was used and make != NULL set *make to path + * tar - if tar != NULL set *tar to to tar path + * ls - if ls != NULL set *ls to ls path + * txzchk - if txzchk != NULL set *txzchk to path + * fnamchk - if fnamchk ! NULL set *fnamchk to path + * chkentry - if chkentry != NULL set *chkentry to path + * make - if make != NULL set *make to path + * rm - if rm != NULL set *rm to path */ void -find_utils(bool tar_flag_used, char **tar, bool ls_flag_used, - char **ls, bool txzchk_flag_used, char **txzchk, bool fnamchk_flag_used, char **fnamchk, - bool chkentry_flag_used, char **chkentry, bool make_flag_used, char **make) +find_utils(char **tar, char **ls, char **txzchk, char **fnamchk, char **chkentry, char **make, char **rm) { + size_t i = 0; /* for iterating through paths arrays */ + bool tar_found = false; + bool ls_found = false; + bool txzchk_found = false; + bool fnamchk_found = false; + bool chkentry_found = false; + bool make_found = false; + bool rm_found = false; + /* - * guess where tar and ls utilities are located + * guess where tools are * - * If the user did not give a -t, -c and/or -l /path/to/x path, then look at - * the historic location for the utility. If the historic location of the utility - * isn't executable, look for an executable in the alternate location. + * First we will try resolving paths by just name. Then if that fails we'll + * try traditional locations and then if that fails, try alternate locations + * until we find a match. * - * On some systems where /usr/bin != /bin, the distribution made the mistake of - * moving historic critical applications, look to see if the alternate path works instead. + * On some systems where /usr/bin != /bin, the distribution made the mistake + * of moving (pre-)historic critical applications, look to see if the + * alternate path works instead. */ - if (tar != NULL && !tar_flag_used && !is_exec(TAR_PATH_0) && is_exec(TAR_PATH_1)) { - *tar = TAR_PATH_1; - dbg(DBG_MED, "tar is not in historic location: %s : will use alternate location: %s", TAR_PATH_0, *tar); + + if (tar != NULL && *tar != NULL && is_file(*tar) && is_exec(*tar)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *tar = strdup(*tar); + if (*tar == NULL) { + errp(55, __func__, "strdup(tar) failed"); + not_reached(); + } + tar_found = true; + } + if (!tar_found && tar != NULL) { + for (i = 0; tar_paths[i] != NULL; ++i) { + if (is_file(tar_paths[i]) && is_exec(tar_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *tar = strdup(tar_paths[i]); + if (*tar == NULL) { + errp(56, __func__, "strdup(\"%s\") failed", tar_paths[i]); + not_reached(); + } + tar_found = true; + break; + } else { + /* + * try resolving the path + */ + *tar = resolve_path(tar_paths[i]); + if (*tar != NULL) { + tar_found = true; + break; + } + } + } + } + + if (tar_found) { + dbg(DBG_MED, "found tar at: %s", *tar); + } + if (ls != NULL && *ls != NULL && is_file(*ls) && is_exec(*ls)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *ls = strdup(*ls); + if (*ls == NULL) { + errp(57, __func__, "strdup(ls) failed"); + not_reached(); + } + ls_found = true; + } + if (!ls_found && ls != NULL) { + for (i = 0; ls_paths[i] != NULL; ++i) { + if (is_file(ls_paths[i]) && is_exec(ls_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *ls = strdup(ls_paths[i]); + if (*ls == NULL) { + errp(58, __func__, "strdup(\"%s\") failed", ls_paths[i]); + not_reached(); + } + ls_found = true; + break; + } else { + /* + * try resolving the path + */ + *ls = resolve_path(ls_paths[i]); + if (*ls != NULL) { + ls_found = true; + break; + } + } + } + } + + if (ls_found) { + dbg(DBG_MED, "found ls at: %s", *ls); + } + if (txzchk != NULL && *txzchk != NULL && is_file(*txzchk) && is_exec(*txzchk)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *txzchk = strdup(*txzchk); + if (*txzchk == NULL) { + errp(59, __func__, "strdup(txzchk) failed"); + not_reached(); + } + txzchk_found = true; } - if (ls != NULL && !ls_flag_used && !is_exec(LS_PATH_0) && is_exec(LS_PATH_1)) { - *ls = LS_PATH_1; - dbg(DBG_MED, "ls is not in historic location: %s : will use alternate location: %s", LS_PATH_0, *ls); + if (!txzchk_found && txzchk != NULL) { + for (i = 0; txzchk_paths[i] != NULL; ++i) { + if (is_file(txzchk_paths[i]) && is_exec(txzchk_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *txzchk = strdup(txzchk_paths[i]); + if (*txzchk == NULL) { + errp(60, __func__, "strdup(\"%s\") failed", txzchk_paths[i]); + not_reached(); + } + txzchk_found = true; + break; + } else { + /* + * try resolving the path + */ + *txzchk = resolve_path(txzchk_paths[i]); + if (*txzchk != NULL) { + txzchk_found = true; + break; + } + } + } } - /* now do the same for our utilities: txzchk, fnamchk, and chkentry */ - if (txzchk != NULL && !txzchk_flag_used && !is_exec(TXZCHK_PATH_0) && is_exec(TXZCHK_PATH_1)) { - *txzchk = TXZCHK_PATH_1; - dbg(DBG_MED, "using default txzchk path: %s", TXZCHK_PATH_1); + if (txzchk_found) { + dbg(DBG_MED, "found txzchk at: %s", *txzchk); } - if (fnamchk != NULL && !fnamchk_flag_used && !is_exec(FNAMCHK_PATH_0) && is_exec(FNAMCHK_PATH_1)) { - *fnamchk = FNAMCHK_PATH_1; - dbg(DBG_MED, "using default fnamchk path: %s", FNAMCHK_PATH_1); + if (fnamchk != NULL && *fnamchk != NULL && is_file(*fnamchk) && is_exec(*fnamchk)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *fnamchk = strdup(*fnamchk); + if (*fnamchk == NULL) { + errp(61, __func__, "strdup(fnamchk)"); + not_reached(); + } + fnamchk_found = true; } - if (chkentry != NULL && !chkentry_flag_used && !is_exec(CHKENTRY_PATH_0) && is_exec(CHKENTRY_PATH_1)) { - *chkentry = CHKENTRY_PATH_1; - dbg(DBG_MED, "using default chkentry path: %s", CHKENTRY_PATH_1); + if (!fnamchk_found && fnamchk != NULL) { + for (i = 0; fnamchk_paths[i] != NULL; ++i) { + if (is_file(fnamchk_paths[i]) && is_exec(fnamchk_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *fnamchk = strdup(fnamchk_paths[i]); + if (*fnamchk == NULL) { + errp(62, __func__, "strdup(\"%s\") failed", fnamchk_paths[i]); + not_reached(); + } + fnamchk_found = true; + break; + } else { + /* + * try resolving the path + */ + *fnamchk = resolve_path(fnamchk_paths[i]); + if (*fnamchk != NULL) { + fnamchk_found = true; + break; + } + } + } } - if (make != NULL && !make_flag_used && !is_exec(MAKE_PATH_0) && is_exec(MAKE_PATH_1)) { - *make = MAKE_PATH_1; - dbg(DBG_MED, "using default make path: %s", MAKE_PATH_1); + + if (fnamchk_found) { + dbg(DBG_MED, "found fnamchk at: %s", *fnamchk); } + if (chkentry != NULL && *chkentry != NULL && is_file(*chkentry) && is_exec(*chkentry)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *chkentry = strdup(*chkentry); + if (*chkentry == NULL) { + errp(63, __func__, "strdup(chkentry) failed"); + not_reached(); + } + chkentry_found = true; + } + if (!chkentry_found && chkentry != NULL) { + for (i = 0; chkentry_paths[i] != NULL; ++i) { + if (is_file(chkentry_paths[i]) && is_exec(chkentry_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *chkentry = strdup(chkentry_paths[i]); + if (*chkentry == NULL) { + errp(64, __func__, "strdup(\"%s\") failed", chkentry_paths[i]); + not_reached(); + } + chkentry_found = true; + break; + } else { + /* + * try resolving the path + */ + *chkentry = resolve_path(chkentry_paths[i]); + if (*chkentry != NULL) { + chkentry_found = true; + break; + } + } + } + } + if (chkentry_found) { + dbg(DBG_MED, "found chkentry at: %s", *chkentry); + } + if (make != NULL && *make != NULL && is_file(*make) && is_exec(*make)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *make = strdup(*make); + if (*make == NULL) { + errp(65, __func__, "strdup(make) failed"); + not_reached(); + } + make_found = true; + } + if (!make_found && make != NULL) { + for (i = 0; make_paths[i] != NULL; ++i) { + if (is_file(make_paths[i]) && is_exec(make_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *make = strdup(make_paths[i]); + if (*make == NULL) { + errp(66, __func__, "strdup(\"%s\") failed", make_paths[i]); + not_reached(); + } + make_found = true; + break; + } else { + /* + * try resolving the path + */ + *make = resolve_path(make_paths[i]); + if (*make != NULL) { + make_found = true; + break; + } + } + } + } + + if (make_found) { + dbg(DBG_MED, "found make at: %s", *make); + } + + if (rm != NULL && *rm != NULL && is_file(*rm) && is_exec(*rm)) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp */ + *rm = strdup(*rm); + if (*rm == NULL) { + errp(67, __func__, "strdup(rm) failed"); + not_reached(); + } + rm_found = true; + } + if (!rm_found && rm != NULL) { + for (i = 0; rm_paths[i] != NULL; ++i) { + if (is_file(rm_paths[i]) && is_exec(rm_paths[i])) { + /* + * we have to strdup() it + */ + errno = 0; /* pre-clear errno for errp() */ + *rm = strdup(rm_paths[i]); + if (*rm == NULL) { + errp(68, __func__, "strdup(\"%s\") failed", rm_paths[i]); + not_reached(); + } + rm_found = true; + break; + } else { + /* + * try resolving the path + */ + *rm = resolve_path(rm_paths[i]); + if (*rm != NULL) { + rm_found = true; + break; + } + } + } + } + + if (rm_found) { + dbg(DBG_MED, "found rm at: %s", *rm); + } return; } diff --git a/soup/sanity.h b/soup/sanity.h index b195000d..c7c9c869 100644 --- a/soup/sanity.h +++ b/soup/sanity.h @@ -73,10 +73,6 @@ * function prototypes */ extern void ioccc_sanity_chks(void); /* all *_sanity_chks() functions should call this */ -extern void find_utils(bool tar_flag_used, char **tar, bool ls_flag_used, - char **ls, bool txzchk_flag_used, char **txzchk, bool fnamchk_flag_used, char **fnamchk, - bool chkentry_flag_used, char **chkentry, bool make_flag_used, char **make); - - +extern void find_utils(char **tar, char **ls, char **txzchk, char **fnamchk, char **chkentry, char **make, char **rm); #endif /* INCLUDE_SANITY_H */ diff --git a/soup/soup.h b/soup/soup.h index 6cb0d8e2..8d7dc078 100644 --- a/soup/soup.h +++ b/soup/soup.h @@ -102,20 +102,36 @@ * paths to utilities the IOCCC tools use (including our own tools fnamchk, * txzchk, chkentry, etc.) */ -#define TAR_PATH_0 "/usr/bin/tar" /* historic path for tar */ -#define TAR_PATH_1 "/bin/tar" /* alternate tar path for some systems where /usr/bin/tar != /bin/tar */ -#define LS_PATH_0 "/bin/ls" /* historic path for ls */ -#define LS_PATH_1 "/usr/bin/ls" /* alternate ls path for some systems where /bin/ls != /usr/bin/ls */ +#define TAR_PATH_0 "tar" /* for $PATH search */ +#define TAR_PATH_1 "/usr/bin/tar" /* historic path for tar */ +#define TAR_PATH_2 "/bin/tar" /* alternate tar path for some systems where /usr/bin/tar != /bin/tar */ +#define LS_PATH_0 "ls" /* for $PATH search */ +#define LS_PATH_1 "/bin/ls" /* historic path for ls */ +#define LS_PATH_2 "/usr/bin/ls" /* alternate ls path for some systems where /bin/ls != /usr/bin/ls */ #define FNAMCHK_PATH_0 "./test_ioccc/fnamchk" /* path to fnamchk tool if not installed */ -#define FNAMCHK_PATH_1 "/usr/local/bin/fnamchk" /* default path to fnamchk tool if installed */ +#define FNAMCHK_PATH_1 "fnamchk" /* for $PATH search */ +#define FNAMCHK_PATH_2 "/usr/local/bin/fnamchk" /* default path to fnamchk tool if installed */ #define TXZCHK_PATH_0 "./txzchk" /* path to txzchk tool if not installed */ -#define TXZCHK_PATH_1 "/usr/local/bin/txzchk" /* default path to txzchk tool if installed */ +#define TXZCHK_PATH_1 "txzchk" /* for $PATH search */ +#define TXZCHK_PATH_2 "/usr/local/bin/txzchk" /* default path to txzchk tool if installed */ #define CHKENTRY_PATH_0 "./chkentry" /* path to chkentry tool if not installed */ -#define CHKENTRY_PATH_1 "/usr/local/bin/chkentry" /* default path to chkentry tool if installed */ -#define JPARSE_PATH_0 "./jparse/jparse" /* path to jparse if not installed */ -#define JPARSE_PATH_1 "/usr/local/bin/jparse" /* default path to jparse tool if installed */ -#define MAKE_PATH_0 "/usr/bin/make" /* default path to make tool */ -#define MAKE_PATH_1 "/bin/make" /* in case /usr/bin/make doesn't work */ +#define CHKENTRY_PATH_1 "chkentry" /* for $PATH search */ +#define CHKENTRY_PATH_2 "/usr/local/bin/chkentry" /* default path to chkentry tool if installed */ +#define MAKE_PATH_0 "gmake" /* for $PATH search */ +#define MAKE_PATH_1 "make" /* for $PATH search */ +#define MAKE_PATH_2 "/usr/bin/make" /* default path to make tool */ +#define MAKE_PATH_3 "/bin/make" /* in case /usr/bin/make doesn't work */ +#define RM_PATH_0 "rm" /* for $PATH search */ +#define RM_PATH_1 "/bin/rm" /* default path to rm tool */ +#define RM_PATH_2 "/usr/bin/rm" /* in case /bin/rm doesn't work */ + +extern char *tar_paths[]; +extern char *ls_paths[]; +extern char *fnamchk_paths[]; +extern char *txzchk_paths[]; +extern char *chkentry_paths[]; +extern char *make_paths[]; +extern char *rm_paths[]; /* diff --git a/soup/version.h b/soup/version.h index 2dfc652f..501dfc75 100644 --- a/soup/version.h +++ b/soup/version.h @@ -83,7 +83,7 @@ * * NOTE: This should match the latest Release string in CHANGES.md */ -#define MKIOCCCENTRY_REPO_VERSION "2.4.4 2025-03-09" /* special release format: major.minor[.patch] YYYY-MM-DD */ +#define MKIOCCCENTRY_REPO_VERSION "2.4.5 2025-03-10" /* special release format: major.minor[.patch] YYYY-MM-DD */ /* diff --git a/test_ioccc/mkiocccentry_test.sh b/test_ioccc/mkiocccentry_test.sh index eb9e04cb..b10658b1 100755 --- a/test_ioccc/mkiocccentry_test.sh +++ b/test_ioccc/mkiocccentry_test.sh @@ -76,7 +76,7 @@ MAKE="$(type -P make 2>/dev/null)" export TXZCHK="./txzchk" export FNAMCHK="./test_ioccc/fnamchk" -export MKIOCCCENTRY_TEST_VERSION="2.0.0 2025-02-28" +export MKIOCCCENTRY_TEST_VERSION="2.0.1 2025-03-10" export USAGE="usage: $0 [-h] [-V] [-v level] [-J level] [-t tar] [-T txzchk] [-l ls] [-F fnamchk] [-m make] [-Z topdir] -h print help and exit @@ -264,7 +264,7 @@ LONG_FILENAME="fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff workdir_esc="${workdir}" test "${workdir:0:1}" = "-" && workdir_esc=./"${workdir}" find "${workdir_esc}" -mindepth 1 -depth -delete -rm -f "${topdir}"/ +mkdir -p "${topdir}" # Answers as of mkiocccentry version: v0.40 2022-03-15 answers() diff --git a/txzchk.c b/txzchk.c index 034fd235..434d6884 100644 --- a/txzchk.c +++ b/txzchk.c @@ -159,8 +159,6 @@ main(int argc, char **argv) extern int optind; /* argv index of the next arg */ char *tar = TAR_PATH_0; /* path to tar executable that supports the -J (xz) option */ char *fnamchk = FNAMCHK_PATH_0; /* path to fnamchk tool */ - bool fnamchk_flag_used = false; /* if -F option used */ - bool tar_flag_used = false; /* true ==> -t /path/to/tar was given */ int i; /* @@ -195,12 +193,10 @@ main(int argc, char **argv) not_reached(); break; case 'F': /* -F fnamchk - specify path to fnamchk tool */ - fnamchk_flag_used = true; fnamchk = optarg; break; case 't': /* -t tar - specify path to tar (perhaps to tar and feather :-) ) */ tar = optarg; - tar_flag_used = true; break; case 'T': /* -T - text (test) file mode - don't rely on tar: just read file as if it was a text file */ read_from_text_file = true; @@ -278,11 +274,9 @@ main(int argc, char **argv) */ if (!read_from_text_file) { - find_utils(tar_flag_used, &tar, false, NULL, false, NULL, - fnamchk_flag_used, &fnamchk, false, NULL, false, NULL); + find_utils(&tar, NULL, NULL, &fnamchk, NULL, NULL, NULL); } else { - find_utils(false, NULL, false, NULL, false, NULL, - fnamchk_flag_used, &fnamchk, false, NULL, false, NULL); + find_utils(&tar, NULL, NULL, &fnamchk, NULL, NULL, NULL); } /* additional sanity checks */ @@ -311,6 +305,18 @@ main(int argc, char **argv) } show_tarball_info(tarball_path); + /* + * we need to free the paths to the tools + */ + if (tar != NULL) { + free(tar); + tar = NULL; + } + if (fnamchk != NULL) { + free(fnamchk); + fnamchk = NULL; + } + /* * All Done!!! All Done!!! -- Jessica Noll, Age 2 */