logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: a88f648b172aebe300717ac307caf62a021e5100
parent c93299119462a20d45bf30096fe56f4687e09b1b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 16 Dec 2024 22:46:04 +0100

Remove assert(errno == 0)

Hurts portability and general stability more than anything else,
better to set errno to a known state when needed.

Diffstat:

Mcmd/arch.c1-
Mcmd/base64.c7-------
Mcmd/cat.c3---
Mcmd/chmod.c8--------
Mcmd/chown.c8--------
Mcmd/cmp.c2--
Mcmd/date.c4----
Mcmd/df.c6------
Mcmd/head.c5-----
Mcmd/install.c14--------------
Mcmd/join.c1-
Mcmd/ln.c28+++++++++-------------------
Mcmd/mkdir.c4----
Mcmd/mkfifo.c3---
Mcmd/mknod.c5-----
Mcmd/mv.c3---
Mcmd/nice.c2--
Mcmd/nohup.c4----
Mcmd/nproc.c2++
Mcmd/pathchk.c2--
Mcmd/renice.c3---
Mcmd/rm.c8--------
Mcmd/sha1sum.c2--
Mcmd/sha256sum.c2--
Mcmd/sha512sum.c2--
Mcmd/strings.c4----
Mcmd/timeout.c7-------
Mcmd/touch.c1-
Mcmd/truncate.c4----
Mcmd/uniq.c6------
Mcmd/unlink.c2+-
Mcmd/wc.c4----
Mcmd/yes.c3---
Mlib/consent.c4----
Mlib/iso_parse.c4----
Mlib/lib_mkdir.c3---
Mlib/mode.c2--
Mlib/tr_str.c1-
Mlib/truncation.c2--
Mlib/user_group_parse.c3---
40 files changed, 12 insertions(+), 167 deletions(-)

diff --git a/cmd/arch.c b/cmd/arch.c @@ -4,7 +4,6 @@ #define _POSIX_C_SOURCE 200809L -#include <errno.h> #include <stdio.h> // fprintf #include <string.h> // strerror #include <sys/utsname.h> // uname diff --git a/cmd/base64.c b/cmd/base64.c @@ -23,7 +23,6 @@ const char *argv0 = "base64"; static int xputc(int c, FILE *stream) { - assert(errno == 0); if(fputc(c, stream) == EOF) { fprintf(stderr, "%s: error: Failed writing: %s\n", argv0, strerror(errno)); @@ -31,7 +30,6 @@ xputc(int c, FILE *stream) return 1; } - assert(errno == 0); int err = ferror(stream); if(err != 0) { @@ -82,7 +80,6 @@ encode(FILE *fin, const char *name) { return 0; }; - assert(errno == 0); if(ferror(fin)) { fprintf( @@ -111,7 +108,6 @@ encode(FILE *fin, const char *name) return 1; } c_out += 4; - assert(errno == 0); if(wrap_nl != 0 && (c_out + 4) > wrap_nl) { @@ -121,7 +117,6 @@ encode(FILE *fin, const char *name) if(feof(fin)) { - assert(errno == 0); if(fflush(stdout)) { fprintf(stderr, "%s: error: Failed writing: %s\n", argv0, strerror(errno)); @@ -240,14 +235,12 @@ decode(FILE *fin, const char *name) assert(c == EOF || state == 0); - assert(errno == 0); if(fflush(stdout)) { fprintf(stderr, "%s: error: Failed writing: %s\n", argv0, strerror(errno)); errno = 0; return 1; } - assert(errno == 0); int err = ferror(stdout); if(err != 0) { diff --git a/cmd/cat.c b/cmd/cat.c @@ -5,7 +5,6 @@ #define _POSIX_C_SOURCE 200809L #include "../lib/fs.h" -#include <assert.h> #include <errno.h> #include <fcntl.h> // open, O_RDONLY #include <limits.h> // SSIZE_MAX @@ -72,7 +71,6 @@ main(int argc, char *argv[]) } else { - assert(errno == 0); int fd = open(argv[argi], O_RDONLY); if(fd < 0) { @@ -95,7 +93,6 @@ main(int argc, char *argv[]) return 1; } - assert(errno == 0); if(close(fd) < 0) { fprintf(stderr, diff --git a/cmd/chmod.c b/cmd/chmod.c @@ -11,7 +11,6 @@ #include "../lib/mode.h" -#include <assert.h> #include <dirent.h> // fdopendir, readdir, closedir #include <errno.h> #include <fcntl.h> // AT_FDCWD @@ -34,7 +33,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) struct stat stats; int err = 0; - assert(errno == 0); if(fstatat(fd, name, &stats, AT_SYMLINK_NOFOLLOW) != 0) { fprintf(stderr, @@ -59,7 +57,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) if(mode != stats.st_mode) { - assert(errno == 0); if(fchmodat(fd, name, mode, 0) != 0) { fprintf(stderr, @@ -95,7 +92,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) if(recursive && S_ISDIR(stats.st_mode)) { - assert(errno == 0); int dir = openat(fd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if(dir == -1) { @@ -108,7 +104,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) return 1; } - assert(errno == 0); DIR *dirp = fdopendir(dir); if(dirp == NULL) { @@ -123,7 +118,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) while(true) { - assert(errno == 0); struct dirent *dp = readdir(dirp); if(dp == NULL) { @@ -142,7 +136,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) if(strcmp(dp->d_name, ".") == 0) continue; if(strcmp(dp->d_name, "..") == 0) continue; - assert(errno == 0); char new_path[PATH_MAX] = ""; if(snprintf(new_path, PATH_MAX, "%s/%s", acc_path, dp->d_name) < 0) { @@ -164,7 +157,6 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) } // fdopendir allocates memory for DIR, needs closedir - assert(errno == 0); if(closedir(dirp) != 0) { fprintf(stderr, diff --git a/cmd/chown.c b/cmd/chown.c @@ -12,7 +12,6 @@ #include "../lib/fs.h" #include "../lib/user_group_parse.h" -#include <assert.h> #include <dirent.h> // fdopendir, readdir, closedir #include <errno.h> #include <fcntl.h> // AT_FDCWD, fchownat @@ -51,7 +50,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo int stat_opts = (follow_symlinks == CHOWN_FOLLOW_NO_SYMLINK) ? AT_SYMLINK_NOFOLLOW : 0; int chown_opts = (follow_symlinks == CHOWN_FOLLOW_NO_SYMLINK) ? AT_SYMLINK_NOFOLLOW : 0; - assert(errno == 0); if(fstatat(fd, name, &stats, stat_opts) != 0) { fprintf(stderr, @@ -69,7 +67,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo if(change) { - assert(errno == 0); if(fchownat(fd, name, user, group, chown_opts) != 0) { fprintf(stderr, @@ -104,7 +101,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo if(opt_R && S_ISDIR(stats.st_mode)) { - assert(errno == 0); int dir = openat(fd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if(dir == -1) { @@ -117,7 +113,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo return 1; } - assert(errno == 0); DIR *dirp = fdopendir(dir); if(dirp == NULL) { @@ -132,7 +127,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo while(true) { - assert(errno == 0); struct dirent *dp = readdir(dirp); if(dp == NULL) { @@ -151,7 +145,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo if(strcmp(dp->d_name, ".") == 0) continue; if(strcmp(dp->d_name, "..") == 0) continue; - assert(errno == 0); char new_path[PATH_MAX] = ""; if(snprintf(new_path, PATH_MAX, "%s/%s", acc_path, dp->d_name) < 0) { @@ -175,7 +168,6 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo } // fdopendir allocates memory for DIR, needs closedir - assert(errno == 0); if(closedir(dirp) != 0) { fprintf(stderr, diff --git a/cmd/cmp.c b/cmd/cmp.c @@ -150,8 +150,6 @@ main(int argc, char *argv[]) if(strcmp(argv[0], argv[1]) == 0) return 0; - assert(errno == 0); - FILE *file1 = NULL; if(argv[0][0] == '-' && argv[0][1] == 0) file1 = stdin; diff --git a/cmd/date.c b/cmd/date.c @@ -8,7 +8,6 @@ #include "../lib/iso_parse.h" /* iso_parse */ -#include <assert.h> #include <errno.h> #include <locale.h> /* setlocale() */ #include <stdbool.h> @@ -98,7 +97,6 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - assert(errno == 0); tp.tv_sec = mktime_tz(&tm); if(tp.tv_sec == (time_t)-1) { @@ -207,7 +205,6 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - assert(errno == 0); tp.tv_sec = mktime_tz(&tm); tp.tv_nsec = 0; if(tp.tv_sec == (time_t)-1) @@ -260,7 +257,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); tp.tv_sec = mktime(&tm); tp.tv_nsec = 0; if(tp.tv_sec == (time_t)-1) diff --git a/cmd/df.c b/cmd/df.c @@ -7,7 +7,6 @@ #include "../lib/humanize.h" -#include <assert.h> #include <ctype.h> // iscntrl, isspace #include <errno.h> // errno #include <mntent.h> @@ -129,8 +128,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); - for(int i = 0; i < argc; i++) { struct stat file_stats; @@ -178,7 +175,6 @@ main(int argc, char *argv[]) } // End: Print header - assert(errno == 0); FILE *mounted = setmntent(MOUNTED, "r"); if(mounted == NULL) { @@ -241,7 +237,6 @@ main(int argc, char *argv[]) if(remote) continue; } - assert(errno == 0); struct stat file_stats; if(!opt_a || argc > 0) { @@ -294,7 +289,6 @@ main(int argc, char *argv[]) // Note: musl prior to 1.2.5 has broken getmntent when octal sequences and carriage return is used // https://git.musl-libc.org/cgit/musl/commit/src/misc/mntent.c?id=f314e133929b6379eccc632bef32eaebb66a7335 // https://git.musl-libc.org/cgit/musl/commit/src/misc/mntent.c?id=ee1d39bc1573c1ae49ee6b658938b56bbef95a6c - assert(errno == 0); struct statvfs stats; if(statvfs(mntent->mnt_dir, &stats) != 0) { diff --git a/cmd/head.c b/cmd/head.c @@ -7,7 +7,6 @@ #include "../lib/fs.h" // auto_fd_copy #include "../lib/truncation.h" // apply_size_suffix -#include <assert.h> #include <ctype.h> // isdigit #include <errno.h> #include <fcntl.h> // open @@ -92,7 +91,6 @@ copy_lines(const char *filename) for(size_t i = 0; i < lines; i++) { - assert(errno == 0); ssize_t nread = getdelim(&buf, &buflen, delim, in); if(nread < 0) { @@ -152,7 +150,6 @@ main(int argc, char *argv[]) */ if(argv[optind] && argv[optind][0] == '-' && isdigit(argv[optind][1])) { - assert(errno == 0); char *arg = argv[optind] + 1; char *endptr = NULL; @@ -184,7 +181,6 @@ main(int argc, char *argv[]) break; case 'c': { - assert(errno == 0); char *endptr = NULL; unsigned long size = strtoul(optarg, &endptr, 0); if(errno != 0) @@ -206,7 +202,6 @@ main(int argc, char *argv[]) } case 'n': { - assert(errno == 0); char *endptr = NULL; lines = strtoul(optarg, &endptr, 0); if(!(errno == 0 && endptr != NULL && *endptr == '\0')) diff --git a/cmd/install.c b/cmd/install.c @@ -41,7 +41,6 @@ bool opt_v = false; static int do_install(char *src, char *dest, bool is_dir) { - assert(errno == 0); int src_fd = open(src, O_RDONLY); if(src_fd < 0) { @@ -66,7 +65,6 @@ do_install(char *src, char *dest, bool is_dir) if(!is_dir) { - assert(errno == 0); struct stat dest_stat; if(stat(dest, &dest_stat) < 0) { @@ -103,8 +101,6 @@ do_install(char *src, char *dest, bool is_dir) } } - assert(errno == 0); - char *dest_path = dest; if(is_dir) @@ -125,8 +121,6 @@ do_install(char *src, char *dest, bool is_dir) dest_path = target; } - assert(errno == 0); - int dest_fd = open(dest_path, O_CREAT | O_WRONLY | O_TRUNC, mode); if(dest_fd < 0) { @@ -151,8 +145,6 @@ do_install(char *src, char *dest, bool is_dir) return -1; } - assert(errno == 0); - if(user != (uid_t)-1 || group != (gid_t)-1) if(fchown(dest_fd, user, group) < 0) { @@ -164,8 +156,6 @@ do_install(char *src, char *dest, bool is_dir) return -1; } - assert(errno == 0); - if(preserve_times) { struct timespec src_times[2] = {src_stat.st_atim, src_stat.st_mtim}; @@ -192,8 +182,6 @@ do_install(char *src, char *dest, bool is_dir) return -1; } - assert(errno == 0); - return 0; } @@ -294,8 +282,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); - argc -= optind; argv += optind; diff --git a/cmd/join.c b/cmd/join.c @@ -37,7 +37,6 @@ #include "../lib/err.h" -#include <errno.h> #include <limits.h> #include <locale.h> #include <stdio.h> // fgetln diff --git a/cmd/ln.c b/cmd/ln.c @@ -11,7 +11,6 @@ #define _XOPEN_SOURCE 700 #endif -#include <assert.h> #include <errno.h> #include <fcntl.h> // linkat, AT_SYMLINK_FOLLOW #include <libgen.h> // basename @@ -29,7 +28,6 @@ static int open_dir_flags = O_RDONLY | O_DIRECTORY; static int do_link(char *src, char *dest) { - assert(errno == 0); if(opt_s) { if(symlinkat(src, AT_FDCWD, dest) == 0) return 0; @@ -55,15 +53,10 @@ do_link(char *src, char *dest) } } - // Fallback - assert(errno == EEXIST); errno = 0; - int dirfd = open(dest, open_dir_flags); if(dirfd < 0) { - assert(errno != 0); - // ENOTDIR: Found but not a directory // ELOOP: POSIX return code when O_NOFOLLOW encounters a symbolic link // EMLINK: Same as ELOOP but FreeBSD *sigh* @@ -88,15 +81,14 @@ do_link(char *src, char *dest) return -1; } } - } - - if(errno != 0) - { - fprintf(stderr, - "ln: error: Failed opening destination as directory '%s': %s\n", - dest, - strerror(errno)); - return -1; + else + { + fprintf(stderr, + "ln: error: Failed opening destination as directory '%s': %s\n", + dest, + strerror(errno)); + return -1; + } } if(opt_s) @@ -174,8 +166,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); - argc -= optind; argv += optind; @@ -186,6 +176,7 @@ main(int argc, char *argv[]) } else if(argc == 2) { + errno = 0; struct stat dest_status; int ret_stat = fstatat(AT_FDCWD, argv[1], &dest_status, AT_SYMLINK_NOFOLLOW); if(argc == 2 && (errno == ENOENT || (ret_stat == 0 && !S_ISDIR(dest_status.st_mode)))) @@ -195,7 +186,6 @@ main(int argc, char *argv[]) return ret < 0 ? 1 : 0; } - errno = 0; } char *dest = argv[argc - 1]; diff --git a/cmd/mkdir.c b/cmd/mkdir.c @@ -7,7 +7,6 @@ #include "../lib/lib_mkdir.h" #include "../lib/mode.h" -#include <assert.h> #include <errno.h> #include <stdbool.h> #include <stdio.h> // fprintf @@ -24,7 +23,6 @@ mode_t mkdir_parents_filemask; static int mkdir_simple(char *path, mode_t mode) { - assert(errno == 0); if(mkdir(path, mode) < 0) { fprintf(stderr, "%s: error: Failed making directory '%s': %s\n", argv0, path, strerror(errno)); @@ -90,8 +88,6 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - assert(errno == 0); - if(argc < 1) { fprintf(stderr, "%s: error: Missing operand\n", argv0); diff --git a/cmd/mkfifo.c b/cmd/mkfifo.c @@ -6,7 +6,6 @@ #include "../lib/mode.h" -#include <assert.h> #include <errno.h> #include <stdio.h> // fprintf #include <stdlib.h> // abort @@ -58,8 +57,6 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - assert(errno == 0); - if(argc < 1) { fprintf(stderr, "mkfifo: error: Missing file argument\n"); diff --git a/cmd/mknod.c b/cmd/mknod.c @@ -7,7 +7,6 @@ #include "../lib/mode.h" -#include <assert.h> #include <errno.h> #include <stdio.h> // fprintf #include <stdlib.h> // abort, exit @@ -28,7 +27,6 @@ static unsigned int strtodev(char *arg) { char *endptr = NULL; - assert(errno == 0); long dev = strtol(arg, &endptr, 0); if(errno != 0) { @@ -83,8 +81,6 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - assert(errno == 0); - if(argc < 2) { fprintf(stderr, "mknod: error: Missing operands\n"); @@ -102,7 +98,6 @@ main(int argc, char *argv[]) return 1; } - assert(errno == 0); if(type[0] == 'p') { if(mknod(file, mode | S_IFIFO, 0) != 0) diff --git a/cmd/mv.c b/cmd/mv.c @@ -14,7 +14,6 @@ #include "../lib/consent.h" #include "../lib/fs.h" -#include <assert.h> #include <dirent.h> // fdopendir #include <errno.h> #include <fcntl.h> // open @@ -129,7 +128,6 @@ rename_dir_entries(struct named_fd srcdir, struct named_fd destdir) while(true) { - assert(errno == 0); errno = 0; struct dirent *dirsrc_ent = readdir(dirsrc); if(dirsrc_ent == NULL) @@ -250,7 +248,6 @@ do_renameat(struct named_fd srcdir, } } - assert(errno == 0); if(renameat(srcdir.fd, src, destdir.fd, dest) < 0) { switch(errno) diff --git a/cmd/nice.c b/cmd/nice.c @@ -33,7 +33,6 @@ main(int argc, char *argv[]) switch(c) { case 'n': - assert(errno == 0); incr = strtol(optarg, &endptr, 10); if(endptr && *endptr != 0) errno = EINVAL; @@ -86,7 +85,6 @@ main(int argc, char *argv[]) } assert(argv[0]); - assert(errno == 0); if(execvp(argv[0], argv) < 0) { fprintf(stderr, "%s: error: Failed executing '%s': %s\n", argv0, argv[0], strerror(errno)); diff --git a/cmd/nohup.c b/cmd/nohup.c @@ -41,10 +41,8 @@ main(int argc, char *argv[]) return 127; } - assert(errno == 0); if(isatty(1)) { - assert(errno == 0); nohup_fd = open("nohup.out", O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); if(nohup_fd < 0) { @@ -92,7 +90,6 @@ main(int argc, char *argv[]) if(isatty(2)) { - assert(errno == 0); if(dup2(1, 2)) { fprintf( @@ -111,7 +108,6 @@ main(int argc, char *argv[]) (void)argc; assert(argv[0]); - assert(errno == 0); if(execvp(argv[0], argv) < 0) { fprintf(stderr, "%s: error: Failed executing '%s': %s\n", argv0, argv[0], strerror(errno)); diff --git a/cmd/nproc.c b/cmd/nproc.c @@ -5,8 +5,10 @@ // _SC_NPROCESSORS_CONF &_SC_NPROCESSORS_ONLN got added in POSIX.1-2024 // https://www.austingroupbugs.net/view.php?id=339 #define _DEFAULT_SOURCE + // Sadly {Free,Net}BSD hides _SC_NPROCESSORS_{CONF,ONLN} if _POSIX_C_SOURCE is defined *sigh* // #define _POSIX_C_SOURCE 202405L + #include <errno.h> #include <stdio.h> // printf #include <string.h> // strerror diff --git a/cmd/pathchk.c b/cmd/pathchk.c @@ -4,7 +4,6 @@ #define _POSIX_C_SOURCE 200809L -#include <assert.h> #include <errno.h> #include <limits.h> // PATH_MAX #include <stdbool.h> @@ -126,7 +125,6 @@ main(int argc, char *argv[]) if(!opt_p) { - assert(errno == 0); if(access(path, F_OK) < 0 && errno != ENOENT) { fprintf(stderr, diff --git a/cmd/renice.c b/cmd/renice.c @@ -5,7 +5,6 @@ #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 // getpriority, setpriority -#include <assert.h> #include <errno.h> #include <stdio.h> // fprintf #include <stdlib.h> // abort @@ -89,8 +88,6 @@ main(int argc, char *argv[]) which = PRIO_USER; break; case 'n': - assert(errno == 0); - adj = strtol(optarg, &endptr, 10); if(endptr && *endptr != 0) errno = EINVAL; diff --git a/cmd/rm.c b/cmd/rm.c @@ -11,7 +11,6 @@ #include "../lib/consent.h" -#include <assert.h> #include <ctype.h> // isprint #include <dirent.h> // fdopendir, readdir, closedir #include <errno.h> // errno @@ -35,7 +34,6 @@ do_unlinkat(int fd, char *name, char *acc_path) struct stat stats; int err = 0; - assert(errno == 0); if(fstatat(fd, name, &stats, AT_SYMLINK_NOFOLLOW) != 0) { if(force && errno == ENOENT) @@ -62,7 +60,6 @@ do_unlinkat(int fd, char *name, char *acc_path) if(!force && opt_i) if(!consentf("rm: Recurse into '%s' ? [y/N] ", acc_path)) return 0; - assert(errno == 0); int dir = openat(fd, name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if(dir == -1) { @@ -72,7 +69,6 @@ do_unlinkat(int fd, char *name, char *acc_path) return 1; } - assert(errno == 0); DIR *dirp = fdopendir(dir); if(dirp == NULL) { @@ -86,7 +82,6 @@ do_unlinkat(int fd, char *name, char *acc_path) while(true) { - assert(errno == 0); struct dirent *dp = readdir(dirp); if(dp == NULL) { @@ -103,7 +98,6 @@ do_unlinkat(int fd, char *name, char *acc_path) if(strcmp(dp->d_name, "..") == 0) continue; char new_path[PATH_MAX] = ""; - assert(errno == 0); if(snprintf(new_path, PATH_MAX, "%s/%s", acc_path, dp->d_name) < 0) { fprintf(stderr, @@ -122,7 +116,6 @@ do_unlinkat(int fd, char *name, char *acc_path) } // fdopendir allocates memory for DIR, needs closedir - assert(errno == 0); if(closedir(dirp) != 0) { fprintf(stderr, @@ -153,7 +146,6 @@ do_unlinkat(int fd, char *name, char *acc_path) } } - assert(errno == 0); if(unlinkat(fd, name, is_dir ? AT_REMOVEDIR : 0) != 0) { fprintf(stderr, "rm: error: Couldn't remove '%s': %s\n", acc_path, strerror(errno)); diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c @@ -6,7 +6,6 @@ #include "../lib/sha1.h" // sha1_* #include "../lib/strconv.h" // bytes2hex -#include <assert.h> #include <ctype.h> // isxdigit #include <errno.h> #include <fcntl.h> // open, O_* @@ -65,7 +64,6 @@ check(FILE *file, const char *filename) errno = 0; while((nread = getline(&line, &len, file)) > 0) { - assert(errno == 0); if(line[nread - 1] == '\n') line[nread - 1] = '\0'; ssize_t i = 0; diff --git a/cmd/sha256sum.c b/cmd/sha256sum.c @@ -6,7 +6,6 @@ #include "../lib/sha256.h" // sha256_* #include "../lib/strconv.h" // bytes2hex -#include <assert.h> #include <ctype.h> // isxdigit #include <errno.h> #include <fcntl.h> // open, O_* @@ -65,7 +64,6 @@ check(FILE *file, const char *filename) errno = 0; while((nread = getline(&line, &len, file)) > 0) { - assert(errno == 0); if(line[nread - 1] == '\n') line[nread - 1] = '\0'; ssize_t i = 0; diff --git a/cmd/sha512sum.c b/cmd/sha512sum.c @@ -6,7 +6,6 @@ #include "../lib/sha512.h" // sha512_* #include "../lib/strconv.h" // bytes2hex -#include <assert.h> #include <ctype.h> // isxdigit #include <errno.h> #include <fcntl.h> // open, O_* @@ -65,7 +64,6 @@ check(FILE *file, const char *filename) errno = 0; while((nread = getline(&line, &len, file)) > 0) { - assert(errno == 0); if(line[nread - 1] == '\n') line[nread - 1] = '\0'; ssize_t i = 0; diff --git a/cmd/strings.c b/cmd/strings.c @@ -3,7 +3,6 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L -#include <assert.h> #include <ctype.h> /* isprint() */ #include <errno.h> /* errno */ #include <fcntl.h> /* open(), O_RDONLY */ @@ -112,7 +111,6 @@ main(int argc, char *argv[]) /* Structure is always ignored */ break; case 'n': - assert(errno == 0); char *endptr = NULL; opt_min_strlen = strtol(optarg, &endptr, 10); if(endptr && *endptr != 0) @@ -198,7 +196,6 @@ main(int argc, char *argv[]) } else { - assert(errno == 0); int fd = open(argv[argi], O_RDONLY); if(fd <= 0) { @@ -211,7 +208,6 @@ main(int argc, char *argv[]) return 1; } - assert(errno == 0); if(close(fd) < 0) { fprintf(stderr, "strings: error: Failed closing ā€˜%sā€™: %s\n", argv[argi], strerror(errno)); diff --git a/cmd/timeout.c b/cmd/timeout.c @@ -7,7 +7,6 @@ #include "../lib/strtodur.h" #include "../lib/sys_signame.h" -#include <assert.h> #include <ctype.h> #include <errno.h> #include <signal.h> // kill @@ -84,7 +83,6 @@ main(int argc, char *argv[]) case 's': if(isdigit(optarg[0])) { - assert(errno == 0); char *endptr = NULL; unsigned long optoul = strtoul(optarg, &endptr, 10); @@ -150,8 +148,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); - argv += optind; argc -= optind; @@ -167,7 +163,6 @@ main(int argc, char *argv[]) argv++; argc--; - assert(errno == 0); if(signal(SIGCHLD, handle_sigchld) == SIG_ERR) { fprintf( @@ -198,7 +193,6 @@ main(int argc, char *argv[]) return cmd_exit_timeout; } - assert(errno == 0); if(kill(child, term_sig) != 0) { fprintf(stderr, @@ -223,7 +217,6 @@ main(int argc, char *argv[]) } } - assert(errno == 0); if(kill(child, SIGKILL) != 0) { fprintf(stderr, diff --git a/cmd/touch.c b/cmd/touch.c @@ -254,7 +254,6 @@ main(int argc, char *argv[]) for(int i = 0; i < argc; i++) { const char *file = argv[i]; - assert(errno == 0); int fd = open(file, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if(fd == -1) { diff --git a/cmd/truncate.c b/cmd/truncate.c @@ -7,7 +7,6 @@ #include "../lib/bitmasks.h" // FIELD_CLR #include "../lib/truncation.h" // parse_size -#include <assert.h> #include <errno.h> #include <fcntl.h> // open #include <stdbool.h> @@ -96,7 +95,6 @@ main(int argc, char *argv[]) if(ref_file != NULL) { - assert(errno == 0); struct stat ref_stats; if(stat(optarg, &ref_stats) < 0) { @@ -113,7 +111,6 @@ main(int argc, char *argv[]) for(int argi = 0; argi < argc; argi++) { - assert(errno == 0); char *arg = argv[argi]; // same flags to open as touch(1) @@ -123,7 +120,6 @@ main(int argc, char *argv[]) fprintf(stderr, "truncate: error: Failed to open '%s': %s\n", arg, strerror(errno)); return 1; } - assert(errno == 0); if(apply_truncation(fd, tr, arg) < 0) return 1; diff --git a/cmd/uniq.c b/cmd/uniq.c @@ -4,7 +4,6 @@ #define _POSIX_C_SOURCE 200809L -#include <assert.h> #include <ctype.h> // isblank #include <errno.h> #include <stdbool.h> @@ -111,8 +110,6 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - assert(errno == 0); - FILE *input = stdin; char *input_name = NULL; FILE *output = stdout; @@ -162,8 +159,6 @@ main(int argc, char *argv[]) return 1; } - assert(errno == 0); - char *first = NULL; ssize_t first_len = 0; size_t first_shift = 0; @@ -172,7 +167,6 @@ main(int argc, char *argv[]) errno = 0; while(true) { - assert(errno == 0); char *cur = NULL; size_t cur_size = 0; ssize_t cur_len = getline(&cur, &cur_size, input); diff --git a/cmd/unlink.c b/cmd/unlink.c @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> // SPDX-License-Identifier: 0BSD -#include <errno.h> // errno +#include <errno.h> #include <stdio.h> // fprintf #include <string.h> // strerror #include <unistd.h> // unlink diff --git a/cmd/wc.c b/cmd/wc.c @@ -5,7 +5,6 @@ #define _POSIX_C_SOURCE 200809L #include "../lib/bitmasks.h" -#include <assert.h> #include <ctype.h> // isspace #include <errno.h> #include <fcntl.h> // posix_fadvise @@ -163,7 +162,6 @@ wc_file_chars(int fd, char *filename) while(true) { - assert(errno == 0); wint_t c = getwc(file); if(c == WEOF) { @@ -270,8 +268,6 @@ main(int argc, char *argv[]) } if(wc_opts == 0) wc_opts = WC_OPT_ALL; - assert(errno == 0); - argc -= optind; argv += optind; diff --git a/cmd/yes.c b/cmd/yes.c @@ -3,7 +3,6 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L -#include <assert.h> #include <errno.h> #include <limits.h> // PAGESIZE #include <stdio.h> // perror @@ -74,8 +73,6 @@ main(int argc, char *argv[]) buflen = i; } - assert(errno == 0); - while(write(STDOUT_FILENO, buf, buflen) >= 1) ; diff --git a/lib/consent.c b/lib/consent.c @@ -39,7 +39,6 @@ consent_init(void) yesexpr_ret = regcomp(&consent_yesexpr_r, "^[Yy]", REG_EXTENDED | REG_NOSUB); assert(yesexpr_ret == 0); } - assert(errno == 0); char *noexpr = nl_langinfo(NOEXPR); int noexpr_ret = regcomp(&consent_noexpr_r, noexpr, REG_EXTENDED | REG_NOSUB); @@ -58,7 +57,6 @@ consent_init(void) noexpr_ret = regcomp(&consent_noexpr_r, "^[Nn]", REG_EXTENDED | REG_NOSUB); assert(noexpr_ret == 0); } - assert(errno == 0); } void @@ -78,7 +76,6 @@ consentf(const char *restrict fmt, ...) va_list ap; - assert(errno == 0); va_start(ap, fmt); int ret = vfprintf(stderr, fmt, ap); va_end(ap); @@ -90,7 +87,6 @@ consentf(const char *restrict fmt, ...) goto end; } - assert(errno == 0); ssize_t nread = getline(&line, &len, stdin); if(nread < 0) { diff --git a/lib/iso_parse.c b/lib/iso_parse.c @@ -28,7 +28,6 @@ iso_parse(char *arg, struct tm *time, long *nsec, const char **errstr) { arg++; - assert(errno == 0); char *endptr = NULL; time_t now = strtol(arg, &endptr, 10); if(errno != 0) @@ -76,7 +75,6 @@ iso_parse(char *arg, struct tm *time, long *nsec, const char **errstr) if(s[0] == ',') s[0] = '.'; - assert(errno == 0); if(sscanf(s, "%10lf%n", &fraction, &parsed) < 1) { if(errno == 0) @@ -160,8 +158,6 @@ iso_parse(char *arg, struct tm *time, long *nsec, const char **errstr) } } - assert(errno == 0); - return s; } diff --git a/lib/lib_mkdir.c b/lib/lib_mkdir.c @@ -6,7 +6,6 @@ #include "./lib_mkdir.h" -#include <assert.h> #include <errno.h> #include <limits.h> // PATH_MAX #include <stdio.h> // fprintf @@ -16,7 +15,6 @@ int mkdir_parents(char *path, mode_t mode) { - assert(errno == 0); for(int i = strlen(path) - 1; i >= 0; i--) { @@ -41,7 +39,6 @@ mkdir_parents(char *path, mode_t mode) if(mkdir_parents(parent, parent_mode) < 0) return -1; - assert(errno == 0); if(mkdir(path, mode) < 0) { if(errno == EEXIST) diff --git a/lib/mode.c b/lib/mode.c @@ -8,7 +8,6 @@ #include "bitmasks.h" -#include <assert.h> #include <errno.h> #include <stdbool.h> #include <stdint.h> // int8_t @@ -131,7 +130,6 @@ new_mode(const char *mode, mode_t old, const char **errstr) { char *endptr = NULL; - assert(errno == 0); long new = strtol(mode, &endptr, 8); if(errno != 0) diff --git a/lib/tr_str.c b/lib/tr_str.c @@ -39,7 +39,6 @@ #include <assert.h> #include <ctype.h> -#include <errno.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> diff --git a/lib/truncation.c b/lib/truncation.c @@ -22,7 +22,6 @@ apply_truncation(int fd, struct truncation tr, char *arg) if(tr.op != OP_SET) { struct stat stats; - assert(errno == 0); if(fstat(fd, &stats) < 0) { fprintf( @@ -141,7 +140,6 @@ parse_size(const char *arg, struct truncation *buf) // no default case intended } - assert(errno == 0); char *endptr = NULL; unsigned long size = strtoul(arg, &endptr, 10); if(errno != 0) diff --git a/lib/user_group_parse.c b/lib/user_group_parse.c @@ -6,7 +6,6 @@ #include "./user_group_parse.h" -#include <assert.h> #include <errno.h> #include <grp.h> // getgrnam #include <pwd.h> // getpwnam @@ -20,7 +19,6 @@ parse_user(char *str, uid_t *user) if(str == NULL) return -1; if(str[0] == 0) return 0; - assert(errno == 0); char *endptr = NULL; unsigned long id = strtoul(str, &endptr, 0); if(errno == 0 && endptr != NULL && *endptr == '\0') @@ -53,7 +51,6 @@ parse_group(char *str, gid_t *group) if(str == NULL) return -1; if(str[0] == 0) return 0; - assert(errno == 0); char *endptr = NULL; unsigned int id = strtoul(str, &endptr, 0); if(errno == 0 && endptr != NULL && *endptr == '\0')