X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Futils.c;h=fd213c2044725993565f8352d9e6e05959d70292;hb=812e8e5c87da4fd84ae7bc5b6a18c85106188eb3;hp=7228279ec000517a07bb15a6342141a77423203d;hpb=6531eb055818ea1b4df386b3e7132392771cd0e5;p=ppp.git diff --git a/pppd/utils.c b/pppd/utils.c index 7228279..fd213c2 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -28,6 +28,10 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -137,6 +141,7 @@ vslprintf(char *buf, int buflen, 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; unsigned char *p; @@ -202,11 +207,12 @@ vslprintf(char *buf, int buflen, char *fmt, va_list args) c = *fmt++; switch (c) { case 'd': - val = va_arg(args, long); - if (val < 0) { + lval = va_arg(args, long); + if (lval < 0) { neg = 1; - val = -val; - } + val = -lval; + } else + val = lval; base = 10; break; case 'u': @@ -323,6 +329,7 @@ vslprintf(char *buf, int buflen, char *fmt, va_list args) OUTCHAR(c); } continue; +#ifndef UNIT_TEST case 'P': /* print PPP packet */ bufinfo.ptr = buf; bufinfo.len = buflen + 1; @@ -332,6 +339,7 @@ vslprintf(char *buf, int buflen, char *fmt, va_list args) buf = bufinfo.ptr; buflen = bufinfo.len - 1; continue; +#endif case 'B': p = va_arg(args, unsigned char *); for (n = prec; n > 0; --n) { @@ -426,6 +434,7 @@ log_packet(u_char *p, int len, char *prefix, int level) } #endif /* unused */ +#ifndef UNIT_TEST /* * format_packet - make a readable representation of a packet, * calling `printer(arg, format, ...)' to output it. @@ -471,6 +480,7 @@ format_packet(u_char *p, int len, printer_func printer, void *arg) else printer(arg, "%.*B", len, p); } +#endif /* UNIT_TEST */ /* * init_pr_log, end_pr_log - initialize and finish use of pr_log. @@ -597,6 +607,7 @@ logit(int level, char *fmt, va_list args) log_write(level, buf); } +#ifndef UNIT_TEST static void log_write(int level, char *buf) { @@ -611,6 +622,13 @@ log_write(int level, char *buf) log_to_fd = -1; } } +#else +static void +log_write(int level, char *buf) +{ + printf("<%d>: %s\n", level, buf); +} +#endif /* * fatal - log an error message and die horribly. @@ -625,7 +643,11 @@ fatal(char *fmt, ...) logit(LOG_ERR, fmt, pvar); va_end(pvar); +#ifndef UNIT_TEST die(1); /* as promised */ +#else + exit(-1); +#endif } /* @@ -729,6 +751,8 @@ dump_packet(const char *tag, unsigned char *p, int len) dbglog("%s %P", tag, p, len); } + +#ifndef UNIT_TEST /* * complete_read - read a full `count' bytes from fd, * unless end-of-file or an error other than EINTR is encountered. @@ -754,6 +778,7 @@ complete_read(int fd, void *buf, size_t count) } return done; } +#endif /* Procedures for locking the serial device using a lock file. */ #ifndef LOCK_DIR