]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/utils.c
Fix include paths for plugins to use the public API of pppd
[ppp.git] / pppd / utils.c
index 7228279ec000517a07bb15a6342141a77423203d..e75bb9c8eecd21279a999c18f8c0bc4f132ef1e3 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <ctype.h>
@@ -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
@@ -794,7 +819,7 @@ lock(char *dev)
 #else /* LOCKLIB */
 
     char lock_buffer[12];
-    int fd, pid, n;
+    int fd, pid, n, siz;
 
 #ifdef SVR4
     struct stat sbuf;
@@ -881,11 +906,16 @@ lock(char *dev)
 
     pid = getpid();
 #ifndef LOCK_BINARY
+    siz = 11;
     slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
-    write (fd, lock_buffer, 11);
+    n = write (fd, lock_buffer, siz);
 #else
-    write(fd, &pid, sizeof (pid));
+    siz = sizeof (pid);
+    n = write(fd, &pid, siz);
 #endif
+    if (n != siz) {
+       error("Could not write pid to lock file when locking");
+    }
     close(fd);
     return 0;
 
@@ -909,7 +939,7 @@ relock(int pid)
     return -1;
 #else /* LOCKLIB */
 
-    int fd;
+    int fd, n, siz;
     char lock_buffer[12];
 
     if (lock_file[0] == 0)
@@ -922,11 +952,16 @@ relock(int pid)
     }
 
 #ifndef LOCK_BINARY
+    siz = 11;
     slprintf(lock_buffer, sizeof(lock_buffer), "%10d\n", pid);
-    write (fd, lock_buffer, 11);
+    n = write (fd, lock_buffer, siz);
 #else
-    write(fd, &pid, sizeof(pid));
+    siz = sizeof(pid);
+    n = write(fd, &pid, siz);
 #endif /* LOCK_BINARY */
+    if (n != siz) {
+       error("Could not write pid to lock file when locking");
+    }
     close(fd);
     return 0;