chiark / gitweb /
checkpath.c: Move the symlink-target buffer into the state structure.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 17 Jul 2024 12:13:13 +0000 (13:13 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 17 Jul 2024 12:23:10 +0000 (13:23 +0100)
checkpath.c

index 76f80fac97f3888b52dbb4e22e71f19c720986e7..8a19ae5cdd84df10f32c85c4c91bcf08c0735708 100644 (file)
@@ -68,6 +68,7 @@ struct state {
   pool *p;                             /* Allocation pool */
   struct elt *sp;                      /* Stack pointer for list */
   dstr path;                           /* Current path string */
+  dstr link;                           /* Symbolic link target string */
 };
 
 /*----- Static variables --------------------------------------------------*/
@@ -363,7 +364,6 @@ unsigned checkpath(const char *p, const struct checkpath *cp)
   pool *pp;
   struct stat st;
   unsigned bad = 0;
-  dstr buf = DSTR_INIT;
   int i;
 
   /* --- Initialize the state --- */
@@ -373,6 +373,7 @@ unsigned checkpath(const char *p, const struct checkpath *cp)
   state->p = pp;
   state->sp = (/*unconst*/ struct elt *)&rootnode;
   dstr_create(&state->path);
+  dstr_create(&state->link);
 
   /* --- Try to find the current directory --- */
 
@@ -436,15 +437,17 @@ unsigned checkpath(const char *p, const struct checkpath *cp)
 
       /* --- Resolve the link --- */
 
-      dstr_reset(&buf);
-      dstr_ensure(&buf, st.st_size + 1);
-      if ((i = readlink(state->path.buf, buf.buf, buf.sz)) < 0) {
+      dstr_reset(&state->link);
+      dstr_ensure(&state->link, st.st_size + 1);
+      if ((i = readlink(state->path.buf,
+                       state->link.buf, state->link.sz)) < 0) {
        report(cp, CP_ERROR, 0, state->path.buf, "can't readlink: %e");
        bad |= CP_ERROR;
        break;
       }
-      buf.buf[i] = 0;
-      report(cp, CP_SYMLINK, 2, state->path.buf, "symlink -> `%s'", buf.buf);
+      state->link.buf[i] = 0;
+      report(cp, CP_SYMLINK, 2, state->path.buf,
+            "symlink -> `%s'", state->link.buf);
 
       /* --- Handle sticky parents --- *
        *
@@ -463,11 +466,11 @@ unsigned checkpath(const char *p, const struct checkpath *cp)
 
       /* --- Sort out what to do from here --- */
 
-      if (buf.buf[0] == '/')
+      if (state->link.buf[0] == '/')
        popall(state);
       else
        pop(state);
-      ee = splitpath(state, buf.buf, ee);
+      ee = splitpath(state, state->link.buf, ee);
       continue;
     }
 
@@ -499,7 +502,7 @@ unsigned checkpath(const char *p, const struct checkpath *cp)
   }
 
   dstr_destroy(&state->path);
-  dstr_destroy(&buf);
+  dstr_destroy(&state->link);
   pool_destroy(state->p);
   return (bad);
 }