From: J. Ali Harlow Date: Fri, 9 Jan 2009 12:32:57 +0000 (+0000) Subject: Avoid use of non-standard %m printf conversion code. X-Git-Tag: 0.1~39 X-Git-Url: http://project.juiblex.co.uk/git/?a=commitdiff_plain;h=b94da3c31f62a60780607d3443b7081546556cbb;p=razor.git Avoid use of non-standard %m printf conversion code. Also switch to the more conventional ": " format allowing us to use perror() in more places. --- diff --git a/librazor/rpm.c b/librazor/rpm.c index 6143469..740eaf3 100644 --- a/librazor/rpm.c +++ b/librazor/rpm.c @@ -373,7 +373,8 @@ razor_rpm_open(const char *filename) rpm->map = razor_file_get_contents(filename, &rpm->size); if (!rpm->map) { - fprintf(stderr, "couldn't get contents of %s (%m)\n", filename); + fprintf(stderr, "couldn't get contents of %s (%s)\n", filename, + strerror(errno)); return NULL; } @@ -459,7 +460,8 @@ installer_inflate(struct installer *installer) installer->stream.avail_out = length; err = inflate(&installer->stream, Z_SYNC_FLUSH); if (err != Z_OK && err != Z_STREAM_END) { - fprintf(stderr, "inflate error: %d (%m)\n", err); + fprintf(stderr, "inflate error: %d (%s)\n", err, + strerror(errno)); return -1; } @@ -484,7 +486,8 @@ installer_align(struct installer *installer, size_t size) err = inflate(&installer->stream, Z_SYNC_FLUSH); if (err != Z_OK && err != Z_STREAM_END) { - fprintf(stderr, "inflate error: %d (%m)\n", err); + fprintf(stderr, "inflate error: %d (%s)\n", err, + strerror(errno)); return -1; } @@ -523,7 +526,8 @@ create_path(struct installer *installer, const char *path, unsigned int mode) } } if (close(fd) < 0) { - fprintf(stderr, "failed to close %s: %m\n", buffer); + fprintf(stderr, "failed to close %s: %s\n", buffer, + strerror(errno)); return -1; } return 0; @@ -550,7 +554,7 @@ create_path(struct installer *installer, const char *path, unsigned int mode) } installer->buffer[installer->length] = '\0'; if (symlink((const char *) installer->buffer, buffer)) { - fprintf(stderr, "failed to create symlink, %m\n"); + perror("failed to create symlink"); return -1; } return 0; @@ -606,38 +610,39 @@ run_script(struct installer *installer, } pid = fork(); if (pid < 0) { - fprintf(stderr, "failed to fork, %m\n"); + perror("failed to fork"); } else if (pid == 0) { if (dup2(fd[0], STDIN_FILENO) < 0) { - fprintf(stderr, "failed redirect stdin, %m\n"); + perror("failed redirect stdin"); exit(-1); } if (close(fd[0]) < 0 || close(fd[1]) < 0) { - fprintf(stderr, "failed to close pipe, %m\n"); + perror("failed to close pipe"); exit(-1); } if (chroot(installer->root) < 0) { - fprintf(stderr, "failed to chroot to %s, %m\n", - installer->root); + fprintf(stderr, "failed to chroot to %s: %s\n", + installer->root, strerror(errno)); exit(-1); } printf("executing program %s in chroot %s\n", program, installer->root); if (execl(program, program, NULL)) { - fprintf(stderr, "failed to exec %s, %m\n", program); + fprintf(stderr, "failed to exec %s: %s\n", program, + strerror(errno)); exit(-1); } } else { if (script && razor_write(fd[1], script, strlen(script)) < 0) { - fprintf(stderr, "failed to pipe script, %m\n"); + perror("failed to pipe script"); return -1; } if (close(fd[0]) || close(fd[1])) { - fprintf(stderr, "failed to close pipe, %m\n"); + perror("failed to close pipe"); return -1; } if (wait(&status) < 0) { - fprintf(stderr, "wait for child failed, %m"); + perror("wait for child failed"); return -1; } if (status) @@ -646,7 +651,7 @@ run_script(struct installer *installer, #else fp = popen(program, "w"); if (fwrite(script, strlen(script), 1, fp) != 1) { - fprintf(stderr, "failed to pipe script, %m\n"); + perror("failed to pipe script"); return -1; } pclose(fp); diff --git a/librazor/util.c b/librazor/util.c index 1afb623..e2652a7 100644 --- a/librazor/util.c +++ b/librazor/util.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #if HAVE_SYS_MMAN_H @@ -73,8 +74,8 @@ razor_create_dir(const char *root, const char *path) return -1; } } else if (mkdir(buffer, 0777) < 0) { - fprintf(stderr, "failed to make directory %s: %m\n", - buffer); + fprintf(stderr, "failed to make directory %s: %s\n", + buffer, strerror(errno)); return -1; } @@ -97,7 +98,7 @@ razor_write(int fd, const void *data, size_t size) while (rest > 0) { written = write(fd, p, rest); if (written < 0) { - fprintf(stderr, "write error: %m\n"); + perror("write error"); return -1; } rest -= written; diff --git a/src/test-driver.c b/src/test-driver.c index 99b4d00..f55049d 100644 --- a/src/test-driver.c +++ b/src/test-driver.c @@ -45,7 +45,8 @@ parse_xml_file(const char *filename, fd = open(filename, O_RDONLY); if (fd < 0) { - fprintf(stderr, "failed to open %s: %m\n", filename); + fprintf(stderr, "failed to open %s: %s\n", filename, + strerror(errno)); exit(-1); } @@ -64,7 +65,7 @@ parse_xml_file(const char *filename, } if (fd < 0) { - fprintf(stderr, "read: %m\n"); + perror("read"); exit(-1); }