]> code.citadel.org Git - citadel.git/blobdiff - webcit/snprintf.c
* wildmat.c, braindamage.c: added
[citadel.git] / webcit / snprintf.c
index 89d650d7d8331f1f9a9a62b519c43f532d2e5fc3..5cf567fd65b99be635573219278561c59378c3ca 100644 (file)
 #include <stdarg.h>
 #include <string.h>
 
-static int
-needed (const char *fmt, va_list argp)
+static int needed(const char *fmt, va_list argp)
 {
-  static FILE *sink = NULL;
+       static FILE *sink = NULL;
 
-  /* ok, there's a small race here that could result in the sink being
-   * opened more than once if we're threaded, but I'd rather ignore it than
-   * spend cycles synchronizing :-) */
+       /* ok, there's a small race here that could result in the sink being
+        * opened more than once if we're threaded, but I'd rather ignore it than
+        * spend cycles synchronizing :-) */
 
-  if (sink == NULL)
-    {
-      if ((sink = fopen("/dev/null", "w")) == NULL)
-       {
-         perror("/dev/null");
-         exit(1);
+       if (sink == NULL) {
+               if ((sink = fopen("/dev/null", "w")) == NULL) {
+                       perror("/dev/null");
+                       exit(1);
+               }
        }
-    }
-
-  return vfprintf(sink, fmt, argp);
+       return vfprintf(sink, fmt, argp);
 }
 
-int
-vsnprintf (char *buf, size_t max, const char *fmt, va_list argp)
+int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp)
 {
-  char *p;
-  int size;
-
-  if ((p = malloc(needed(fmt, argp) + 1)) == NULL)
-    {
-      fprintf(stderr, "vsnprintf: malloc failed, aborting\n");
-      abort();
-    }
+       char *p;
+       int size;
 
-  if ((size = vsprintf(p, fmt, argp)) >= max)
-    size = -1;
+       if ((p = malloc(needed(fmt, argp) + 1)) == NULL) {
+               fprintf(stderr, "vsnprintf: malloc failed, aborting\n");
+               abort();
+       }
+       if ((size = vsprintf(p, fmt, argp)) >= max)
+               size = -1;
 
-  strncpy(buf, p, max);
-  buf[max - 1] = 0;
-  free(p);
-  return size;
+       strncpy(buf, p, max);
+       buf[max - 1] = 0;
+       free(p);
+       return size;
 }
 
-int
-snprintf (char *buf, size_t max, const char *fmt, ...)
+int snprintf(char *buf, size_t max, const char *fmt,...)
 {
-  va_list argp;
-  int bytes;
+       va_list argp;
+       int bytes;
 
-  va_start(argp, fmt);
-  bytes = vsnprintf(buf, max, fmt, argp);
-  va_end(argp);
+       va_start(argp, fmt);
+       bytes = vsnprintf(buf, max, fmt, argp);
+       va_end(argp);
 
-  return bytes;
+       return bytes;
 }