Skip to content

Commit 3b606e9

Browse files
wkozaczuknyh
authored andcommitted
Add GNU libc extension function error()
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]>
1 parent e37bbc9 commit 3b606e9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ $(out)/musl/src/math/llroundl.o: conf-opt := $(conf-opt) -O0
13251325
musl += misc/a64l.o
13261326
libc += misc/basename.o
13271327
musl += misc/dirname.o
1328+
libc += misc/error.o
13281329
libc += misc/ffs.o
13291330
musl += misc/get_current_dir_name.o
13301331
libc += misc/gethostid.o

libc/misc/error.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2019 Waldemar Kozaczuk
3+
*
4+
* This work is open source software, licensed under the terms of the
5+
* BSD license as described in the LICENSE file in the top-level directory.
6+
*/
7+
8+
#include <stdlib.h>
9+
#include <stdio.h>
10+
#include <stdarg.h>
11+
#include <string.h>
12+
13+
extern char *program_invocation_name;
14+
15+
void
16+
error (int status, int errnum, const char *message, ...)
17+
{
18+
fflush(stdout);
19+
20+
fprintf(stderr, "%s: ", program_invocation_name);
21+
22+
va_list args;
23+
int ret;
24+
va_start(args, message);
25+
ret = vfprintf(stderr, message, args);
26+
va_end(args);
27+
28+
if (errnum) {
29+
fprintf(stderr, ": %s", strerror(errnum));
30+
}
31+
32+
fprintf(stderr, "\n" );
33+
34+
if (status) {
35+
exit(status);
36+
}
37+
}

0 commit comments

Comments
 (0)