diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/mknod.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/helpers/mknod.c b/helpers/mknod.c index e9e9737..10b0e1b 100644 --- a/helpers/mknod.c +++ b/helpers/mknod.c @@ -70,6 +70,18 @@ _err(const char *fmt, ...) fputc('\n', stderr); } +static void __attribute__((format(__printf__, 1, 2))) +_errno(const char *fmt, ...) +{ + va_list ap; + + fprintf(stderr, "%s: ", _program_name); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, ": %s\n", strerror(errno)); +} + static int _get_work_area(int argc, char *argv[], char **work_area) { @@ -199,7 +211,7 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } if (mkfifo(name, mode) != 0) { - _err(_("Failed to create link \"%s\""), name); + _errno(_("Failed to create link \"%s\""), name); return EXIT_FAILURE; } return EXIT_SUCCESS; @@ -232,7 +244,7 @@ main(int argc, char *argv[]) */ fd = open(name, O_CREAT | O_EXCL, mode); if (fd < 0 || close(fd) < 0) { - _err(_("Failed to create node")); + _errno(_("Failed to create node")); free(specials_file_name); return EXIT_FAILURE; } @@ -245,7 +257,7 @@ main(int argc, char *argv[]) goto opened; } } - _err(_("Failed to lock specials file")); + _errno(_("Failed to lock specials file")); free(specials_file_name); unlink(name); return EXIT_FAILURE; @@ -255,7 +267,7 @@ main(int argc, char *argv[]) specials_file = fopen(specials_file_name, "a"); if (specials_file == NULL) { - _err(_("Failed to open specials file stream")); + _errno(_("Failed to open specials file stream")); unlink(specials_lock_name); free(specials_file_name); unlink(name); @@ -264,7 +276,7 @@ main(int argc, char *argv[]) /* If "specials" is empty, write header. */ if (fstat(fileno(specials_file), &stat_buf) != 0) { - _err(_("Failed to stat specials file")); + _errno(_("Failed to stat specials file")); fclose(specials_file); unlink(specials_lock_name); free(specials_file_name); @@ -275,7 +287,7 @@ main(int argc, char *argv[]) if (fputs("version=1\n", specials_file) < 0 || fputs("type major minor name\n", specials_file) < 0) { - _err(_("Failed to write specials file")); + _errno(_("Failed to write specials file")); fclose(specials_file); unlink(specials_lock_name); free(specials_file_name); @@ -286,7 +298,7 @@ main(int argc, char *argv[]) if (fprintf(specials_file, "%c %8ld %8ld %s\n", type, major, minor, name) < 0) { - _err(_("Failed to write specials file")); + _errno(_("Failed to write specials file")); fclose(specials_file); unlink(specials_lock_name); free(specials_file_name); |