Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/usr.sbin/pkg_install/lib Pull up revisions 1.31-1.32:



details:   https://anonhg.NetBSD.org/src/rev/4cbe8beaba29
branches:  netbsd-1-4
changeset: 469389:4cbe8beaba29
user:      he <he%NetBSD.org@localhost>
date:      Mon Sep 13 22:24:11 1999 +0000

description:
Pull up revisions 1.31-1.32:
  Hide test for URLlength()>0 behind a macro (IS_URL()).
  Bring closer to /usr/share/misc/style with the aid of indent(1).
(hubertf)

diffstat:

 usr.sbin/pkg_install/lib/file.c |  671 ++++++++++++++++++++-------------------
 1 files changed, 345 insertions(+), 326 deletions(-)

diffs (truncated from 902 to 300 lines):

diff -r c0ec673e4f2e -r 4cbe8beaba29 usr.sbin/pkg_install/lib/file.c
--- a/usr.sbin/pkg_install/lib/file.c   Mon Sep 13 22:17:54 1999 +0000
+++ b/usr.sbin/pkg_install/lib/file.c   Mon Sep 13 22:24:11 1999 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: file.c,v 1.25.2.3 1999/08/22 18:12:49 he Exp $ */
+/*     $NetBSD: file.c,v 1.25.2.4 1999/09/13 22:24:11 he Exp $ */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
 #else
-__RCSID("$NetBSD: file.c,v 1.25.2.3 1999/08/22 18:12:49 he Exp $");
+__RCSID("$NetBSD: file.c,v 1.25.2.4 1999/09/13 22:24:11 he Exp $");
 #endif
 #endif
 
@@ -40,18 +40,19 @@
 #include <time.h>
 #include <fcntl.h>
 
-/* This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
+/*
+ * This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
  * NetBSD's ftp command to do all FTP, which will DTRT for proxies,
  * etc.
  */
 static FILE *
 ftpGetURL(char *url, int *retcode)
 {
-       FILE *ftp;
-       pid_t pid_ftp;
-       int p[2];
+       FILE   *ftp;
+       pid_t   pid_ftp;
+       int     p[2];
 
-       *retcode=0;
+       *retcode = 0;
 
        if (pipe(p) < 0) {
                *retcode = 1;
@@ -65,15 +66,15 @@
        }
        if (pid_ftp == 0) {
                /* child */
-               dup2(p[1],1);
+               dup2(p[1], 1);
                close(p[1]);
 
-               fprintf(stderr, ">>> ftp -o - %s\n",url); 
-               execl("/usr/bin/ftp","ftp","-V","-o","-",url,NULL);
+               fprintf(stderr, ">>> ftp -o - %s\n", url);
+               execl("/usr/bin/ftp", "ftp", "-V", "-o", "-", url, NULL);
                exit(1);
        } else {
                /* parent */
-               ftp = fdopen(p[0],"r");
+               ftp = fdopen(p[0], "r");
 
                close(p[1]);
 
@@ -85,113 +86,128 @@
        return ftp;
 }
 
-/* Quick check to see if a file exists */
+/*
+ * Quick check to see if a file exists
+ */
 Boolean
 fexists(char *fname)
 {
-    struct stat dummy;
-    if (!lstat(fname, &dummy))
-       return TRUE;
-    return FALSE;
+       struct stat dummy;
+       if (!lstat(fname, &dummy))
+               return TRUE;
+       return FALSE;
 }
 
-/* Quick check to see if something is a directory */
+/*
+ * Quick check to see if something is a directory
+ */
 Boolean
 isdir(char *fname)
 {
-    struct stat sb;
+       struct stat sb;
 
-    if (lstat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
-       return TRUE;
-    else
-       return FALSE;
+       if (lstat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
+               return TRUE;
+       else
+               return FALSE;
 }
 
-/* Check if something is a link to a directory */
+/*
+ * Check if something is a link to a directory
+ */
 Boolean
 islinktodir(char *fname)
 {
-    struct stat sb;
+       struct stat sb;
 
-    if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) {
-        if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
-           return TRUE; /* link to dir! */
-        else
-           return FALSE; /* link to non-dir */
-    } else
-        return FALSE;  /* non-link */
+       if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) {
+               if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
+                       return TRUE;    /* link to dir! */
+               else
+                       return FALSE;   /* link to non-dir */
+       } else
+               return FALSE;   /* non-link */
 }
 
-/* Check to see if file is a dir, and is empty */
+/*
+ * Check to see if file is a dir, and is empty
+ */
 Boolean
 isemptydir(char *fname)
 {
-    if (isdir(fname) || islinktodir(fname)) {
-       DIR *dirp;
-       struct dirent *dp;
+       if (isdir(fname) || islinktodir(fname)) {
+               DIR    *dirp;
+               struct dirent *dp;
 
-       dirp = opendir(fname);
-       if (!dirp)
-           return FALSE;       /* no perms, leave it alone */
-       for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
-           if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
-               closedir(dirp);
-               return FALSE;
-           }
+               dirp = opendir(fname);
+               if (!dirp)
+                       return FALSE;   /* no perms, leave it alone */
+               for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
+                       if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
+                               closedir(dirp);
+                               return FALSE;
+                       }
+               }
+               (void) closedir(dirp);
+               return TRUE;
        }
-       (void)closedir(dirp);
-       return TRUE;
-    }
-    return FALSE;
+       return FALSE;
 }
 
+/*
+ * Check if something is a regular file
+ */
 Boolean
 isfile(char *fname)
 {
-    struct stat sb;
-    if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
-       return TRUE;
-    return FALSE;
+       struct stat sb;
+       if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
+               return TRUE;
+       return FALSE;
 }
 
-/* Check to see if file is a file and is empty. If nonexistent or not
-   a file, say "it's empty", otherwise return TRUE if zero sized. */
+/*
+ * Check to see if file is a file and is empty. If nonexistent or not
+ * a file, say "it's empty", otherwise return TRUE if zero sized.
+ */
 Boolean
 isemptyfile(char *fname)
 {
-    struct stat sb;
-    if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
-       if (sb.st_size != 0)
-           return FALSE;
-    }
-    return TRUE;
+       struct stat sb;
+       if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
+               if (sb.st_size != 0)
+                       return FALSE;
+       }
+       return TRUE;
 }
 
-/* this struct defines the leading part of a valid URL name */
+/* This struct defines the leading part of a valid URL name */
 typedef struct url_t {
-       char    *u_s;           /* the leading part of the URL */
-       int     u_len;          /* its length */
-} url_t;
+       char   *u_s;            /* the leading part of the URL */
+       int     u_len;          /* its length */
+}       url_t;
 
-/* a table of valid leading strings for URLs */
-static url_t   urls[] = {
-       {       "ftp://";,       6       },
-       {       "http://";,      7       },
-       {       NULL    }
+/* A table of valid leading strings for URLs */
+static url_t urls[] = {
+       {"ftp://";, 6},
+       {"http://";, 7},
+       {NULL}
 };
 
-/* Returns length of leading part of any URL from urls table, or -1 */
+/*
+ * Returns length of leading part of any URL from urls table, or -1
+ */
 int
 URLlength(char *fname)
 {
-       url_t   *up;
-       int      i;
+       url_t  *up;
+       int     i;
 
        if (fname != (char *) NULL) {
-               for (i = 0 ; isspace((unsigned char)*fname) ; i++) {
+               for (i = 0; isspace((unsigned char) *fname); i++) {
                        fname++;
                }
-               for (up = urls ; up->u_s ; up++) {
+               for (up = urls; up->u_s; up++) {
                        if (strncmp(fname, up->u_s, up->u_len) == 0) {
                                return i + up->u_len;
                        }
@@ -200,14 +216,16 @@
        return -1;
 }
 
-/* Returns the host part of a URL */
-char *
+/*
+ * Returns the host part of a URL
+ */
+char   *
 fileURLHost(char *fname, char *where, int max)
 {
-       char    *ret;
-       int      i;
+       char   *ret;
+       int     i;
 
-       if ((i = URLlength(fname)) < 0) {
+       if ((i = URLlength(fname)) < 0) {       /* invalid URL? */
                errx(1, "fileURLhost called with a bad URL: `%s'", fname);
        }
        fname += i;
@@ -226,14 +244,16 @@
        return ret;
 }
 
-/* Returns the filename part of a URL */
-char *
+/*
+ * Returns the filename part of a URL
+ */
+char   *
 fileURLFilename(char *fname, char *where, int max)
 {
-       char    *ret;
-       int      i;
+       char   *ret;
+       int     i;
 
-       if ((i = URLlength(fname)) < 0) {
+       if ((i = URLlength(fname)) < 0) {       /* invalid URL? */
                errx(1, "fileURLhost called with a bad URL: `%s'", fname);
        }
        fname += i;
@@ -258,97 +278,92 @@
  * Try and fetch a file by URL, returning the directory name for where
  * it's unpacked, if successful.



Home | Main Index | Thread Index | Old Index