Skip to content

Commit

Permalink
Add GNU libc extension function error()
Browse files Browse the repository at this point in the history
This patch adds GNU libc extension function error()
as specified at https://linux.die.net/man/3/error.
This function is used by core utils programs on Linux.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
wkozaczuk authored and nyh committed Apr 28, 2019
1 parent e37bbc9 commit 3b606e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ $(out)/musl/src/math/llroundl.o: conf-opt := $(conf-opt) -O0
musl += misc/a64l.o
libc += misc/basename.o
musl += misc/dirname.o
libc += misc/error.o
libc += misc/ffs.o
musl += misc/get_current_dir_name.o
libc += misc/gethostid.o
Expand Down
37 changes: 37 additions & 0 deletions libc/misc/error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2019 Waldemar Kozaczuk
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

extern char *program_invocation_name;

void
error (int status, int errnum, const char *message, ...)
{
fflush(stdout);

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

va_list args;
int ret;
va_start(args, message);
ret = vfprintf(stderr, message, args);
va_end(args);

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

fprintf(stderr, "\n" );

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

0 comments on commit 3b606e9

Please sign in to comment.