From bcd106b6b33596cd177837c56b8784e38618ee0d Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 14 Feb 2009 14:48:33 -0500 Subject: [PATCH] Fix a few namespace issues in err.c. While I'm here, use sysexits in examples in the manual page. Obtained-from: FreeBSD --- lib/libc/gen/err.3 | 26 ++++++++++++++------------ lib/libc/gen/err.c | 30 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3 index 11749bb638..463cf85293 100644 --- a/lib/libc/gen/err.3 +++ b/lib/libc/gen/err.3 @@ -9,10 +9,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)err.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD: src/lib/libc/gen/err.3,v 1.11.2.6 2001/12/14 18:33:51 ru Exp $ +.\" $FreeBSD: src/lib/libc/gen/err.3,v 1.24 2008/10/31 15:14:40 rwatson Exp $ .\" $DragonFly: src/lib/libc/gen/err.3,v 1.4 2008/10/06 21:21:30 swildner Exp $ .\" .Dd March 6, 1999 @@ -99,7 +95,7 @@ and a space are output. If the .Fa fmt argument is not NULL, the -.Xr printf 3 +.Xr printf 3 Ns -like formatted error message is output. The output is terminated by a newline character. .Pp @@ -115,7 +111,7 @@ and .Fn vwarnc functions append an error message obtained from .Xr strerror 3 -based on a code or the global variable +based on a supplied error code value or the global variable .Va errno , preceded by another colon and space unless the .Fa fmt @@ -159,6 +155,10 @@ and .Fn verrx functions do not return, but exit with the value of the argument .Fa eval . +It is recommended that the standard values defined in +.Xr sysexits 3 +be used for the value of +.Fa eval . The .Fn err_set_exit function can be used to specify a function which is called before @@ -181,15 +181,16 @@ Display the current information string and exit: .Bd -literal -offset indent if ((p = malloc(size)) == NULL) - err(1, NULL); + err(EX_OSERR, NULL); if ((fd = open(file_name, O_RDONLY, 0)) == -1) - err(1, "%s", file_name); + err(EX_NOINPUT, "%s", file_name); .Ed .Pp Display an error message and exit: .Bd -literal -offset indent if (tm.tm_hour < START_TIME) - errx(1, "too early, wait until %s", start_time_string); + errx(EX_DATAERR, "too early, wait until %s", + start_time_string); .Ed .Pp Warn of an error: @@ -198,7 +199,7 @@ if ((fd = open(raw_device, O_RDONLY, 0)) == -1) warnx("%s: %s: trying the block device", raw_device, strerror(errno)); if ((fd = open(block_device, O_RDONLY, 0)) == -1) - err(1, "%s", block_device); + err(EX_OSFILE, "%s", block_device); .Ed .Pp Warn of an error without using the global variable @@ -212,7 +213,8 @@ if (error != 0) .Xr exit 3 , .Xr fmtmsg 3 , .Xr printf 3 , -.Xr strerror 3 +.Xr strerror 3 , +.Xr sysexits 3 .Sh HISTORY The .Fn err diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c index 0adf101df4..b155574cf6 100644 --- a/lib/libc/gen/err.c +++ b/lib/libc/gen/err.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -29,21 +25,22 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * From: @(#)err.c 8.1 (Berkeley) 6/4/93 * - * $FreeBSD: src/lib/libc/gen/err.c,v 1.6 1999/08/27 23:58:33 peter Exp $ + * @(#)err.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/gen/err.c,v 1.15 2008/04/03 20:36:44 imp Exp $ * $DragonFly: src/lib/libc/gen/err.c,v 1.5 2006/02/12 21:14:11 dillon Exp $ */ -#include +#include "namespace.h" #include #include +#include #include #include #include +#include "un-namespace.h" -#include - +#include "libc_private.h" static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); @@ -68,8 +65,10 @@ err_set_exit(void (*ef)(int)) err_exit = ef; } +__weak_reference(_err, err); + void -err(int eval, const char *fmt, ...) +_err(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -97,7 +96,7 @@ verrc(int eval, int code, const char *fmt, va_list ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", getprogname()); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -122,7 +121,7 @@ verrx(int eval, const char *fmt, va_list ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", getprogname()); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); @@ -131,6 +130,8 @@ verrx(int eval, const char *fmt, va_list ap) exit(eval); } +__weak_reference(_warn, warn); + void _warn(const char *fmt, ...) { @@ -139,7 +140,6 @@ _warn(const char *fmt, ...) vwarnc(errno, fmt, ap); va_end(ap); } -__weak_reference(_warn,warn); void vwarn(const char *fmt, va_list ap) @@ -161,7 +161,7 @@ vwarnc(int code, const char *fmt, va_list ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", getprogname()); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) { vfprintf(err_file, fmt, ap); fprintf(err_file, ": "); @@ -183,7 +183,7 @@ vwarnx(const char *fmt, va_list ap) { if (err_file == 0) err_set_file((FILE *)0); - fprintf(err_file, "%s: ", getprogname()); + fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); -- 2.41.0