Commit a942b15f authored by Nicholas De Nova's avatar Nicholas De Nova

Add errc(3) family.

parent 48902976
......@@ -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 \
......
/*
* 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);
}
/*
* 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);
}
/*
* 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);
}
/*
* 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment