Make flags be unsigned.
[checkpath] / path.c
diff --git a/path.c b/path.c
index fd6271b..f731e52 100644 (file)
--- a/path.c
+++ b/path.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: path.c,v 1.1 1999/04/06 20:12:07 mdw Exp $
+ * $Id: path.c,v 1.4 2001/01/25 22:16:02 mdw Exp $
  *
  * Check a path for safety
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: path.c,v $
- * Revision 1.1  1999/04/06 20:12:07  mdw
- * Initial revision
+ * Revision 1.4  2001/01/25 22:16:02  mdw
+ * Make flags be unsigned.
+ *
+ * Revision 1.3  1999/05/21 22:07:20  mdw
+ * Take advantage of new dynamic string macros.
+ *
+ * Revision 1.2  1999/05/18 20:49:12  mdw
+ * Use a dynamic string for reading symlinks.
+ *
+ * Revision 1.1.1.1  1999/04/06 20:12:07  mdw
+ * Import new project.
  *
  */
 
@@ -69,19 +78,15 @@ struct elt {
   char e_name[1];                      /* Name of the directory */
 };
 
-enum {
-  f_sticky = 1                         /* Directory has sticky bit set */
-};
+#define f_sticky 1u                    /* Directory has sticky bit set */
 
-enum {
-  f_last = 1                           /* This is the final item to check */
-};
+#define f_last 1u                      /* This is the final item to check */
 
 /*----- Static variables --------------------------------------------------*/
 
 static struct elt rootnode = { 0, 0, 0 }; /* Root of the list */
 static struct elt *sp;                 /* Stack pointer for list */
-static dstr d;                         /* Current path string */
+static dstr d = DSTR_INIT;             /* Current path string */
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -211,13 +216,12 @@ static void report(struct chkpath *cp, int what, int verbose,
   /* --- Format the message nicely --- */
 
   if (cp->cp_what & CP_REPORT) {
-    dstr d;
+    dstr d = DSTR_INIT;
     va_list ap;
     const char *q = msg;
     size_t n;
     int e = errno;
 
-    dstr_create(&d);
     va_start(ap, msg);
     if (verbose > 1)
       dstr_puts(&d, "[ ");
@@ -352,7 +356,7 @@ int path_check(const char *p, struct chkpath *cp)
   struct stat st;
   int bad = 0;
 
-  /* --- Initialise stack pointer and path string --- */
+  /* --- Initialize stack pointer and path string --- */
 
   sp = &rootnode;
   dstr_destroy(&d);
@@ -418,18 +422,19 @@ int path_check(const char *p, struct chkpath *cp)
     /* --- Handle symbolic links specially --- */
 
     if (S_ISLNK(st.st_mode)) {
-      char buf[PATH_MAX];
+      dstr buf = DSTR_INIT;
       int i;
 
       /* --- Resolve the link --- */
 
-      if ((i = readlink(d.buf, buf, sizeof(buf))) < 0) {
+      dstr_ensure(&buf, st.st_size + 1);
+      if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) {
        report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e");
        bad |= CP_ERROR;
        break;
       }
-      buf[i] = 0;
-      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf);
+      buf.buf[i] = 0;
+      report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf.buf);
 
       /* --- Handle sticky parents --- *
        *
@@ -448,11 +453,12 @@ int path_check(const char *p, struct chkpath *cp)
 
       /* --- Sort out what to do from here --- */
 
-      if (buf[0] == '/')
+      if (buf.buf[0] == '/')
        popall();
       else
        pop();
-      ee = splitpath(buf, ee);
+      ee = splitpath(buf.buf, ee);
+      dstr_destroy(&buf);
       continue;
     }