# # # patch "tester.cc" # from [f96149cc40286220a17e2c8713fdb94aa0f35118] # to [63b8b9e0640a53a158e4e17caaeb34a6fd4ec8a8] # # patch "unix/fs.cc" # from [93ee1436d888601196b81264f2c4fe3304c4bd64] # to [3ac44d5422ba63f337ce62cd611cc56f5d0050bc] # # patch "unix/process.cc" # from [28d73bfc23b693e7d6297c32295c5e13935a7455] # to [f5e86b9953d044ec811c0aac4f099cefd5ee3cbb] # ============================================================ --- tester.cc f96149cc40286220a17e2c8713fdb94aa0f35118 +++ tester.cc 63b8b9e0640a53a158e4e17caaeb34a6fd4ec8a8 @@ -78,16 +78,23 @@ void make_accessible(string const &name) #else struct stat st; - E(stat(name.c_str(), &st) == 0, - F("stat(%s) failed: %s") % name % os_strerror(errno)); + if (stat(name.c_str(), &st) != 0) + { + const int err = errno; + E(false, F("stat(%s) failed: %s") % name % os_strerror(err)); + } mode_t new_mode = st.st_mode; if (S_ISDIR(st.st_mode)) new_mode |= S_IEXEC; new_mode |= S_IREAD | S_IWRITE; - E(chmod(name.c_str(), new_mode) == 0, - F("chmod(%s) failed: %s") % name % os_strerror(errno)); + if (chmod(name.c_str(), new_mode) != 0) + { + const int err = errno; + E(false, F("chmod(%s) failed: %s") % name % os_strerror(err)); + + } #endif } @@ -118,8 +125,11 @@ time_t get_last_write_time(string const #else struct stat st; - E(stat(name.c_str(), &st) == 0, - F("stat(%s) failed: %s") % name % os_strerror(errno)); + if (stat(name.c_str(), &st) != 0) + { + const int err = errno; + E(false, F("stat(%s) failed: %s") % name % os_strerror(err)); + } return st.st_mtime; @@ -137,15 +147,17 @@ void do_copy_file(string const & from, s char buf[32768]; int ifd, ofd; ifd = open(from.c_str(), O_RDONLY); - E(ifd >= 0, F("open %s: %s") % from % os_strerror(errno)); + const int err = errno; + E(ifd >= 0, F("open %s: %s") % from % os_strerror(err)); struct stat st; st.st_mode = 0666; // sane default if fstat fails fstat(ifd, &st); ofd = open(to.c_str(), O_WRONLY|O_CREAT|O_EXCL, st.st_mode); if (ofd < 0) { + const int err = errno; close(ifd); - E(false, F("open %s: %s") % to % os_strerror(errno)); + E(false, F("open %s: %s") % to % os_strerror(err)); } ssize_t nread, nwrite; @@ -299,9 +311,10 @@ char * do_mkdtemp(char const * parent) strcat(tmpdir, "/mtXXXXXX"); char * result = mkdtemp(tmpdir); + const int err = errno; E(result != 0, - F("mkdtemp(%s) failed: %s") % tmpdir % os_strerror(errno)); + F("mkdtemp(%s) failed: %s") % tmpdir % os_strerror(err)); I(result == tmpdir); return tmpdir; } ============================================================ --- unix/fs.cc 93ee1436d888601196b81264f2c4fe3304c4bd64 +++ unix/fs.cc 3ac44d5422ba63f337ce62cd611cc56f5d0050bc @@ -29,16 +29,22 @@ get_current_working_dir() get_current_working_dir() { char buffer[4096]; - E(getcwd(buffer, 4096), - F("cannot get working directory: %s") % os_strerror(errno)); + if (!getcwd(buffer, 4096)) + { + const int err = errno; + E(false, F("cannot get working directory: %s") % os_strerror(err)); + } return string(buffer); } void change_current_working_dir(string const & to) { - E(!chdir(to.c_str()), - F("cannot change to directory %s: %s") % to % os_strerror(errno)); + if (chdir(to.c_str())) + { + const int err = errno; + E(false, F("cannot change to directory %s: %s") % to % os_strerror(err)); + } } string @@ -104,10 +110,11 @@ get_path_status(string const & path) res = stat(path.c_str(), &buf); if (res < 0) { - if (errno == ENOENT) + const int err = errno; + if (err == ENOENT) return path::nonexistent; else - E(false, F("error accessing file %s: %s") % path % os_strerror(errno)); + E(false, F("error accessing file %s: %s") % path % os_strerror(err)); } if (S_ISREG(buf.st_mode)) return path::file; @@ -125,9 +132,14 @@ namespace // RAII object for DIRs. struct dirhandle { - dirhandle(string const & path) : d(opendir(path.c_str())) + dirhandle(string const & path) { - E(d, F("could not open directory '%s': %s") % path % os_strerror(errno)); + d = opendir(path.c_str()); + if (!d) + { + const int err = errno; + E(false, F("could not open directory '%s': %s") % path % os_strerror(err)); + } } // technically closedir can fail, but there's nothing we could do about it. ~dirhandle() { closedir(d); } @@ -218,8 +230,11 @@ rename_clobberingly(string const & from, void rename_clobberingly(string const & from, string const & to) { - E(!rename(from.c_str(), to.c_str()), - F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(errno)); + if (rename(from.c_str(), to.c_str())) + { + const int err = errno; + E(false, F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(err)); + } } // the C90 remove() function is guaranteed to work for both files and @@ -227,8 +242,11 @@ do_remove(string const & path) void do_remove(string const & path) { - E(!remove(path.c_str()), - F("could not remove '%s': %s") % path % os_strerror(errno)); + if (remove(path.c_str())) + { + const int err = errno; + E(false, F("could not remove '%s': %s") % path % os_strerror(err)); + } } // Create the directory DIR. It will be world-accessible modulo umask. @@ -236,8 +254,11 @@ do_mkdir(string const & path) void do_mkdir(string const & path) { - E(!mkdir(path.c_str(), 0777), - F("could not create directory '%s': %s") % path % os_strerror(errno)); + if (mkdir(path.c_str(), 0777)) + { + const int err = errno; + E(false, F("could not create directory '%s': %s") % path % os_strerror(err)); + } } // Create a temporary file in directory DIR, writing its name to NAME and @@ -287,6 +308,7 @@ make_temp_file(string const & dir, strin v /= base; int fd = open(tmp.c_str(), O_RDWR|O_CREAT|O_EXCL, mode); + int err = errno; if (fd >= 0) { @@ -300,8 +322,8 @@ make_temp_file(string const & dir, strin // fact a directory to which we can write - but we get better // diagnostics from this E() than we would from an I().) - E(errno == EEXIST, - F("cannot create temp file %s: %s") % tmp % os_strerror(errno)); + E(err == EEXIST, + F("cannot create temp file %s: %s") % tmp % os_strerror(err)); // This increment is relatively prime to 'limit', therefore 'value' // will visit every number in its range. @@ -349,8 +371,9 @@ write_data_worker(string const & fname, do { ssize_t written = write(fd, ptr, remaining); + const int err = errno; E(written >= 0, - F("error writing to temp file %s: %s") % tmp % os_strerror(errno)); + F("error writing to temp file %s: %s") % tmp % os_strerror(err)); if (written == 0) { deadcycles++; ============================================================ --- unix/process.cc 28d73bfc23b693e7d6297c32295c5e13935a7455 +++ unix/process.cc f5e86b9953d044ec811c0aac4f099cefd5ee3cbb @@ -52,7 +52,11 @@ bool is_executable(const char *path) struct stat s; int rc = stat(path, &s); - N(rc != -1, F("error getting status of file %s: %s") % path % os_strerror(errno)); + if (rc == -1) + { + const int err = errno; + N(false, F("error getting status of file %s: %s") % path % os_strerror(err)); + } return (s.st_mode & S_IXUSR) && !(s.st_mode & S_IFDIR); } @@ -71,13 +75,21 @@ int make_executable(const char *path) mode_t mode; struct stat s; int fd = open(path, O_RDONLY); - N(fd != -1, F("error opening file %s: %s") % path % os_strerror(errno)); + if (fd == -1) + { + const int err = errno; + N(false, F("error opening file %s: %s") % path % os_strerror(err)); + } if (fstat(fd, &s)) return -1; mode = s.st_mode; mode |= ((S_IXUSR|S_IXGRP|S_IXOTH) & ~read_umask()); int ret = fchmod(fd, mode); - N(close(fd) == 0, F("error closing file %s: %s") % path % os_strerror(errno)); + if (close(fd) != 0) + { + const int err = errno; + N(false, F("error closing file %s: %s") % path % os_strerror(err)); + } return ret; }