mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add errc(3) family.
This commit is contained in:
parent
4890297611
commit
a942b15f91
7 changed files with 136 additions and 10 deletions
|
@ -331,13 +331,17 @@ dirent/rewinddir.o \
|
|||
dirent/scandir.o \
|
||||
dlfcn/dlfcn.o \
|
||||
err/err.o \
|
||||
err/errc.o \
|
||||
err/errx.o \
|
||||
error/gnu_error.o \
|
||||
err/verr.o \
|
||||
err/verrc.o \
|
||||
err/verrx.o \
|
||||
err/vwarn.o \
|
||||
err/vwarnc.o \
|
||||
err/vwarnx.o \
|
||||
err/warn.o \
|
||||
err/warnc.o \
|
||||
err/warnx.o \
|
||||
fcntl/creat.o \
|
||||
fcntl/fcntl.o \
|
||||
|
|
29
libc/err/errc.c
Normal file
29
libc/err/errc.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Nicholas De Nova.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* err/errc.c
|
||||
* Print an error message to stderr.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void errc(int exitcode, int errnum, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
verrc(exitcode, errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
28
libc/err/verrc.c
Normal file
28
libc/err/verrc.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Nicholas De Nova.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* err/verrc.c
|
||||
* Print an error message to stderr.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void verrc(int exitcode, int errnum, const char* fmt, va_list ap)
|
||||
{
|
||||
vwarnc(errnum, fmt, ap);
|
||||
exit(exitcode);
|
||||
}
|
|
@ -25,14 +25,5 @@
|
|||
|
||||
void vwarn(const char* fmt, va_list ap)
|
||||
{
|
||||
int errnum = errno;
|
||||
flockfile(stderr);
|
||||
fprintf_unlocked(stderr, "%s: ", program_invocation_name);
|
||||
if ( fmt )
|
||||
{
|
||||
vfprintf_unlocked(stderr, fmt, ap);
|
||||
fputs_unlocked(": ", stderr);
|
||||
}
|
||||
fprintf_unlocked(stderr, "%s\n", strerror(errnum));
|
||||
funlockfile(stderr);
|
||||
vwarnc(errno, fmt, ap);
|
||||
}
|
||||
|
|
37
libc/err/vwarnc.c
Normal file
37
libc/err/vwarnc.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Jonas 'Sortie' Termansen.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* err/vwarnc.c
|
||||
* Print an error message to stderr.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void vwarnc(int errnum, const char* fmt, va_list ap)
|
||||
{
|
||||
flockfile(stderr);
|
||||
fprintf_unlocked(stderr, "%s: ", program_invocation_name);
|
||||
if ( fmt )
|
||||
{
|
||||
vfprintf_unlocked(stderr, fmt, ap);
|
||||
fputs_unlocked(": ", stderr);
|
||||
}
|
||||
fprintf_unlocked(stderr, "%s\n", strerror(errnum));
|
||||
funlockfile(stderr);
|
||||
}
|
29
libc/err/warnc.c
Normal file
29
libc/err/warnc.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Nicholas De Nova.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* err/warnc.c
|
||||
* Print an error message to stderr.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void warnc(int errnum, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vwarnc(errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
|
@ -30,18 +30,26 @@ extern "C" {
|
|||
|
||||
__attribute__((__noreturn__, __format__(__printf__, 2, 3)))
|
||||
void err(int, const char*, ...);
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 4)))
|
||||
void errc(int, int, const char*, ...);
|
||||
__attribute__((__noreturn__, __format__(__printf__, 2, 3)))
|
||||
void errx(int, const char*, ...);
|
||||
__attribute__((__noreturn__, __format__(__printf__, 2, 0)))
|
||||
void verr(int, const char*, va_list);
|
||||
__attribute__((__noreturn__, __format__(__printf__, 3, 0)))
|
||||
void verrc(int, int, const char*, va_list);
|
||||
__attribute__((__noreturn__, __format__(__printf__, 2, 0)))
|
||||
void verrx(int, const char*, va_list);
|
||||
__attribute__((__format__(__printf__, 1, 2)))
|
||||
void warn(const char*, ...);
|
||||
__attribute__((__format__(__printf__, 2, 3)))
|
||||
void warnc(int, const char*, ...);
|
||||
__attribute__((__format__(__printf__, 1, 2)))
|
||||
void warnx(const char*, ...);
|
||||
__attribute__((__format__(__printf__, 1, 0)))
|
||||
void vwarn(const char*, va_list);
|
||||
__attribute__((__format__(__printf__, 2, 0)))
|
||||
void vwarnc(int, const char*, va_list);
|
||||
__attribute__((__format__(__printf__, 1, 0)))
|
||||
void vwarnx(const char*, va_list);
|
||||
|
||||
|
|
Loading…
Reference in a new issue