Skip to content

Commit

Permalink
tools: Don't user error.h for better portability
Browse files Browse the repository at this point in the history
This is a glibc specific extension. We were already using the BSD
alternative err()/errx() in some places, and that seems more widely
suported, so lets just use that everywhere.

Most of the conversions are trivial:

 * error(EXIT_FAILURE, errno, => err(EXIT_FAILURE,
 * error(EXIT_FAILURE, 0, => errx(EXIT_FAILURE,
 * error(0, 0, => fprintf(stderr,
 * error(0, errno, => perror(

Although in some places we had to set errno to be able to use err().

Signed-off-by: Alexander Larsson <[email protected]>
  • Loading branch information
alexlarsson committed Sep 25, 2023
1 parent 1bfacc0 commit a38da45
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 68 deletions.
5 changes: 2 additions & 3 deletions tools/composefs-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <error.h>
#include <errno.h>
#include <fcntl.h>

Expand Down Expand Up @@ -80,13 +79,13 @@ int main(int argc, char **argv)

FILE *out_file = fopen(dst_path, "we");
if (out_file == NULL)
error(EXIT_FAILURE, errno, "failed to open '%s'", dst_path);
err(EXIT_FAILURE, "failed to open '%s'", dst_path);

options.file = out_file;
options.file_write_cb = write_cb;

if (lcfs_write_to(root, &options) < 0)
error(EXIT_FAILURE, errno, "cannot write file");
err(EXIT_FAILURE, "cannot write file");

lcfs_node_unref(root);

Expand Down
Loading

0 comments on commit a38da45

Please sign in to comment.