---
Here is the second step: move the PATH-searching function to
lib/dpkg/path.c.  The only changes to the body of the function
consist of reformating to fit the style of the code around it ---
no functional change intended.

Like the first patch, this patch is not even tested.
Regardless, any comments would be welcome.

 lib/dpkg/path.c |   34 ++++++++++++++++++++++++++++++++++
 lib/dpkg/path.h |    3 +++
 src/help.c      |   24 +-----------------------
 3 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/lib/dpkg/path.c b/lib/dpkg/path.c
index 8ea891e..8c0c820 100644
--- a/lib/dpkg/path.c
+++ b/lib/dpkg/path.c
@@ -23,7 +23,11 @@
 #include <config.h>
 #include <compat.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <dpkg/path.h>
 
@@ -54,3 +58,33 @@ path_skip_slash_dotslash(const char *path)
        return path;
 }
 
+/*
+ * Verify that the named program can be found in the PATH.
+ * buf should have room for each path entry + '/' + name + '\0'
+ */
+bool
+path_findprog(const char *path, const char *name, char *buf, size_t bufsz)
+{
+       struct stat stab;
+       const char *s, *end;
+       size_t len;
+
+       s = path;
+       while (s) {
+               end = strchr(s, ':');
+               len = end ? end-s : strlen(s);
+               assert(bufsz >= len + 2 + strlen(name));
+
+               memcpy(buf, s, len);
+               if (len)
+                       buf[len++] = '/';
+               strcpy(buf + len, name);
+               if (stat(buf, &stab) == 0 && (stab.st_mode & 0111))
+                       break;
+
+               s = end;
+               if (s)
+                       s++;
+       }
+       return start;
+}
diff --git a/lib/dpkg/path.h b/lib/dpkg/path.h
index 701eb8e..03a9f40 100644
--- a/lib/dpkg/path.h
+++ b/lib/dpkg/path.h
@@ -27,11 +27,14 @@
 #ifdef HAVE_STDDEF_H
 #include <stddef.h>
 #endif
+#include <stdbool.h>
 
 DPKG_BEGIN_DECLS
 
 size_t path_rtrim_slash_slashdot(char *path);
 const char *path_skip_slash_dotslash(const char *path);
+bool path_findprog(const char *path, const char *name,
+                   char *buf, size_t bufsz);
 
 DPKG_END_DECLS
 
diff --git a/src/help.c b/src/help.c
index d898f33..aa179d4 100644
--- a/src/help.c
+++ b/src/help.c
@@ -29,7 +29,6 @@
 #include <dirent.h>
 #include <assert.h>
 #include <string.h>
-#include <stdbool.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -79,27 +78,6 @@ struct filenamenode *namenodetouse(struct filenamenode 
*namenode, struct pkginfo
   return r;
 }
 
-static bool checkpath_prog(const char *path, const char *name, char *buf, 
size_t bufsz) {
-/* Verify that the named program can be found in the PATH. */
-/* buf should have room for each path entry + '/' + name + '\0' */
-  struct stat stab;
-  const char *s, *p;
-  long l;
-
-  s= path;
-  while (s) {
-    p= strchr(s,':');
-    l= p ? p-s : (long)strlen(s);
-    assert(bufsz>=l+2+strlen(name));
-    memcpy(buf,s,l);
-    if (l) buf[l++]= '/';
-    strcpy(buf+l,name);
-    if (stat(buf,&stab) == 0 && (stab.st_mode & 0111)) break;
-    s= p; if (s) s++;
-  }
-  return s;
-}
-
 void checkpath(void) {
 /* Verify that some programs can be found in the PATH. */
   static const char *const checklist[]= { "ldconfig", 
@@ -123,7 +101,7 @@ void checkpath(void) {
   buf=(char*)m_malloc(bufsz);
   
   for (clp=checklist; *clp; clp++) {
-    if (!checkpath_prog(path,*clp,buf,bufsz)) {
+    if (!path_findprog(path,*clp,buf,bufsz)) {
       fprintf(stderr,_("dpkg: `%s' not found on PATH.\n"),*clp);
       warned++;
     }
-- 
1.6.4.244.ge5cd0





-- 
To UNSUBSCRIBE, email to debian-dpkg-bugs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to