X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Futils.c;h=e75bb9c8eecd21279a999c18f8c0bc4f132ef1e3;hp=c47192e67fef1a853830bb3d3ffd6885d756abbd;hb=HEAD;hpb=1480d439ca62d17d7a8a4704194860148dc27689 diff --git a/pppd/utils.c b/pppd/utils.c index c47192e..c995e3c 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -1,7 +1,7 @@ /* * utils.c - various utility functions used in pppd. * - * Copyright (c) 1999-2002 Paul Mackerras. All rights reserved. + * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,14 +10,10 @@ * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 2. The name(s) of the authors of this software must not be used to - * endorse or promote products derived from this software without - * prior written permission. - * - * 3. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by Paul Mackerras - * ". + * 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. * * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY @@ -68,7 +64,7 @@ extern char *strerror(); #endif -static void logit(int, char *, va_list); +static void logit(int, const char *, va_list); static void log_write(int, char *); static void vslp_printer(void *, char *, ...); static void format_packet(u_char *, int, printer_func, void *); @@ -120,7 +116,7 @@ strlcat(char *dest, const char *src, size_t len) * Returns the number of chars put into buf. */ int -slprintf(char *buf, int buflen, char *fmt, ...) +slprintf(char *buf, int buflen, const char *fmt, ...) { va_list args; int n; @@ -137,14 +133,15 @@ slprintf(char *buf, int buflen, char *fmt, ...) #define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0) int -vslprintf(char *buf, int buflen, char *fmt, va_list args) +vslprintf(char *buf, int buflen, const char *fmt, va_list args) { int c, i, n; int width, prec, fillch; int base, len, neg, quoted; - long lval = 0; - unsigned long val = 0; - char *str, *f, *buf0; + long long lval = 0; + unsigned long long val = 0; + char *str, *buf0; + const char *f; unsigned char *p; char num[32]; time_t t; @@ -207,6 +204,30 @@ vslprintf(char *buf, int buflen, char *fmt, va_list args) case 'l': c = *fmt++; switch (c) { + case 'l': + c = *fmt++; + switch (c) { + case 'd': + lval = va_arg(args, long long); + if (lval < 0) { + neg = 1; + val = -lval; + } else + val = lval; + base = 10; + break; + case 'u': + val = va_arg(args, unsigned long long); + base = 10; + break; + default: + OUTCHAR('%'); + OUTCHAR('l'); + OUTCHAR('l'); + --fmt; /* so %llz outputs %llz etc. */ + continue; + } + break; case 'd': lval = va_arg(args, long); if (lval < 0) { @@ -600,7 +621,7 @@ print_string(char *p, int len, printer_func printer, void *arg) * logit - does the hard work for fatal et al. */ static void -logit(int level, char *fmt, va_list args) +logit(int level, const char *fmt, va_list args) { char buf[1024]; @@ -635,7 +656,7 @@ log_write(int level, char *buf) * fatal - log an error message and die horribly. */ void -fatal(char *fmt, ...) +fatal(const char *fmt, ...) { va_list pvar; @@ -655,7 +676,7 @@ fatal(char *fmt, ...) * error - log an error message. */ void -error(char *fmt, ...) +error(const char *fmt, ...) { va_list pvar; @@ -670,7 +691,7 @@ error(char *fmt, ...) * warn - log a warning message. */ void -warn(char *fmt, ...) +warn(const char *fmt, ...) { va_list pvar; @@ -684,7 +705,7 @@ warn(char *fmt, ...) * notice - log a notice-level message. */ void -notice(char *fmt, ...) +notice(const char *fmt, ...) { va_list pvar; @@ -698,7 +719,7 @@ notice(char *fmt, ...) * info - log an informational message. */ void -info(char *fmt, ...) +info(const char *fmt, ...) { va_list pvar; @@ -712,7 +733,7 @@ info(char *fmt, ...) * dbglog - log a debug message. */ void -dbglog(char *fmt, ...) +dbglog(const char *fmt, ...) { va_list pvar;