Skip to content

Commit

Permalink
Remove dependency on glibc-specific error.h
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpolverari committed Oct 10, 2024
1 parent 2e2a8bd commit f8bf0e9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ dcfldd_SOURCES = dcfldd.c \
full-write.h \
output.c output.h \
split.c split.h \
hashformat.c hashformat.h
hashformat.c hashformat.h \
error.c error.h
4 changes: 4 additions & 0 deletions src/dcfldd.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
#include "util.h"
#include "log.h"

extern char *program_invocation_name;

/* The name this program was run with. */
char *program_name;

Expand Down Expand Up @@ -719,6 +721,8 @@ int main(int argc, char **argv)
for (i = 0; i < 256; i++)
trans_table[i] = i;

program_invocation_name = basename(argv[0]);

/* Decode arguments. */
scanargs(argc, argv);

Expand Down
30 changes: 30 additions & 0 deletions src/error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

extern char *program_invocation_name;

/* mimics GNU libc error() behavior */
void error(int status, int errnum, const char *format, ...) {
va_list args;
va_start(args, format);

fflush (stdout);
fprintf(stderr, "%s: ", program_invocation_name);

vfprintf(stderr, format, args);
va_end(args);

if (errnum) {
fprintf(stderr, ": %s", strerror(errnum));
}

fprintf(stderr, "\n");

if (status) {
exit(status);
}
}

6 changes: 6 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef DCFLDD_ERROR_H
#define DCFLDD_ERROR_H

void error(int status, int errnum, const char *format, ...);

#endif /* DCFLDD_ERROR_H */
Binary file added src/error.o
Binary file not shown.
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void skip2(int fdesc, char *file, uintmax_t records, size_t blocksize,

#ifdef __linux__

# include <error.h>
# include "error.h"
# include <sys/mtio.h>

# define MT_SAME_POSITION(P, Q) \
Expand Down

0 comments on commit f8bf0e9

Please sign in to comment.