Initial revision
authorroland <roland>
Sun, 15 Mar 1992 20:25:50 +0000 (20:25 +0000)
committerroland <roland>
Sun, 15 Mar 1992 20:25:50 +0000 (20:25 +0000)
time/emkdir.c [new file with mode: 0644]
time/ialloc.c [new file with mode: 0644]
time/scheck.c [new file with mode: 0644]

diff --git a/time/emkdir.c b/time/emkdir.c
new file mode 100644 (file)
index 0000000..dd88c7b
--- /dev/null
@@ -0,0 +1,83 @@
+#ifndef lint
+#ifndef NOID
+static char    elsieid[] = "@(#)emkdir.c       8.20";
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+#ifndef emkdir
+
+/*LINTLIBRARY*/
+
+#include "private.h"
+
+extern char *  imalloc P((int n));
+extern void    ifree P((char * p));
+
+static char *
+quoted(name)
+register const char *  name;
+{
+       register char * result;
+       register char * cp;
+       register int    c;
+
+       if (name == NULL)
+               name = "";
+       result = imalloc(4 * strlen(name) + 3);
+       if (result == NULL)
+               return NULL;
+       cp = result;
+#ifdef unix
+       *cp++ = '\'';
+       while ((c = *name++) != '\0')
+               if (c == '\'') {
+                       *cp++ = c;
+                       *cp++ = '\\';
+                       *cp++ = c;
+                       *cp++ = c;
+               } else  *cp++ = c;
+       *cp++ = '\'';
+#else /* !defined unix */
+       while ((c = *name++) != '\0')
+               if (c == '/')
+                       *cp++ = '\\';
+               else    *cp++ = c;
+#endif /* !defined unix */
+       *cp = '\0';
+       return result;
+}
+
+int
+emkdir(name, mode)
+const char *   name;
+const int      mode;
+{
+       register int            result;
+       register const char *   format;
+       register char *         command;
+       register char *         qname;
+
+       if ((qname = quoted(name)) == NULL)
+               return -1;
+#ifdef unix
+       format = "mkdir 2>&- %s && chmod 2>&- %o %s";
+#else /* !defined unix */
+       format = "mkdir %s";
+#endif /* !defined unix */
+       command = imalloc(strlen(format) + 2 * strlen(qname) + 20 + 1);
+       if (command == NULL) {
+               ifree(qname);
+               return -1;
+       }
+       (void) sprintf(command, format, qname, mode, qname);
+       ifree(qname);
+       result = system(command);
+       ifree(command);
+       return (result == 0) ? 0 : -1;
+}
+
+/*
+** UNIX is a registered trademark of AT&T.
+*/
+
+#endif /* !defined emkdir */
diff --git a/time/ialloc.c b/time/ialloc.c
new file mode 100644 (file)
index 0000000..f1c8d65
--- /dev/null
@@ -0,0 +1,101 @@
+#ifndef lint
+#ifndef NOID
+static char    elsieid[] = "@(#)ialloc.c       8.19";
+#endif /* !defined NOID */
+#endif /* !defined lint */
+
+/*LINTLIBRARY*/
+
+#include "private.h"
+
+#ifdef MAL
+#define NULLMAL(x)     ((x) == NULL || (x) == MAL)
+#else /* !defined MAL */
+#define NULLMAL(x)     ((x) == NULL)
+#endif /* !defined MAL */
+
+#define nonzero(n)     (((n) == 0) ? 1 : (n))
+
+char * icalloc P((int nelem, int elsize));
+char * icatalloc P((char * old, const char * new));
+char * icpyalloc P((const char * string));
+char * imalloc P((int n));
+char * irealloc P((char * pointer, int size));
+void   ifree P((char * pointer));
+
+char *
+imalloc(n)
+const int      n;
+{
+#ifdef MAL
+       register char * result;
+
+       result = malloc((alloc_size_t) nonzero(n));
+       return NULLMAL(result) ? NULL : result;
+#else /* !defined MAL */
+       return malloc((alloc_size_t) nonzero(n));
+#endif /* !defined MAL */
+}
+
+char *
+icalloc(nelem, elsize)
+int    nelem;
+int    elsize;
+{
+       if (nelem == 0 || elsize == 0)
+               nelem = elsize = 1;
+       return calloc((alloc_size_t) nelem, (alloc_size_t) elsize);
+}
+
+char *
+irealloc(pointer, size)
+char * const   pointer;
+const int      size;
+{
+       if (NULLMAL(pointer))
+               return imalloc(size);
+       return realloc((genericptr_t) pointer, (alloc_size_t) nonzero(size));
+}
+
+char *
+icatalloc(old, new)
+char * const           old;
+const char * const     new;
+{
+       register char * result;
+       register        oldsize, newsize;
+
+       newsize = NULLMAL(new) ? 0 : strlen(new);
+       if (NULLMAL(old))
+               oldsize = 0;
+       else if (newsize == 0)
+               return old;
+       else    oldsize = strlen(old);
+       if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
+               if (!NULLMAL(new))
+                       (void) strcpy(result + oldsize, new);
+       return result;
+}
+
+char *
+icpyalloc(string)
+const char * const     string;
+{
+       return icatalloc((char *) NULL, string);
+}
+
+void
+ifree(p)
+char * const   p;
+{
+       if (!NULLMAL(p))
+               (void) free(p);
+}
+
+void
+icfree(p)
+char * const   p;
+{
+       if (!NULLMAL(p))
+               (void) free(p);
+}
diff --git a/time/scheck.c b/time/scheck.c
new file mode 100644 (file)
index 0000000..c181cec
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef lint
+#ifndef NOID
+static char    elsieid[] = "@(#)scheck.c       8.10";
+#endif /* !defined lint */
+#endif /* !defined NOID */
+
+/*LINTLIBRARY*/
+
+#include "private.h"
+
+extern char *  imalloc P((int n));
+extern void    ifree P((char * p));
+
+char *
+scheck(string, format)
+const char * const     string;
+const char * const     format;
+{
+       register char *         fbuf;
+       register const char *   fp;
+       register char *         tp;
+       register int            c;
+       register char *         result;
+       char                    dummy;
+
+       result = "";
+       if (string == NULL || format == NULL)
+               return result;
+       fbuf = imalloc(2 * strlen(format) + 4);
+       if (fbuf == NULL)
+               return result;
+       fp = format;
+       tp = fbuf;
+       while ((*tp++ = c = *fp++) != '\0') {
+               if (c != '%')
+                       continue;
+               if (*fp == '%') {
+                       *tp++ = *fp++;
+                       continue;
+               }
+               *tp++ = '*';
+               if (*fp == '*')
+                       ++fp;
+               while (isascii(*fp) && isdigit(*fp))
+                       *tp++ = *fp++;
+               if (*fp == 'l' || *fp == 'h')
+                       *tp++ = *fp++;
+               else if (*fp == '[')
+                       do *tp++ = *fp++;
+                               while (*fp != '\0' && *fp != ']');
+               if ((*tp++ = *fp++) == '\0')
+                       break;
+       }
+       *(tp - 1) = '%';
+       *tp++ = 'c';
+       *tp = '\0';
+       if (sscanf(string, fbuf, &dummy) != 1)
+               result = (char *) format;
+       ifree(fbuf);
+       return result;
+}