Subject: standards/33123: standards compliance & glob.h
To: None <standards-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <murray@river-styx.org>
List: netbsd-bugs
Date: 03/22/2006 04:35:00
>Number:         33123
>Category:       standards
>Synopsis:       standards compliance & glob.h
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    standards-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 22 04:35:00 +0000 2006
>Originator:     Murray Armfield
>Release:        NetBSD-current
>Organization:
>Environment:
N/A
>Description:
The glob_t structure as found in <glob.h> is slightly different to the POSIX standard. int's used instead of size_t's. Patches follow correcting glob.h header and miscellaneous usage throughout tree.
>How-To-Repeat:
Inspect POSIX standard and our <glob.h>
>Fix:
Patches for glob.h and programs using it follow...

--- include/glob.h.orig 2005-09-13 11:44:32.000000000 +1000
+++ include/glob.h
@@ -47,9 +47,9 @@
 #endif

 typedef struct {
-       int gl_pathc;           /* Count of total paths so far. */
+       size_t gl_pathc;                /* Count of total paths so far. */
        int gl_matchc;          /* Count of paths matching pattern. */
-       int gl_offs;            /* Reserved at beginning of gl_pathv. */
+       size_t gl_offs;         /* Reserved at beginning of gl_pathv. */
        int gl_flags;           /* Copy of flags parameter to glob. */
        char **gl_pathv;        /* List of paths matching pattern. */
                                /* Copy of errfunc parameter to glob. */

--- lib/libc/gen/glob.c.orig    2006-01-25 04:24:09.000000000 +1100
+++ lib/libc/gen/glob.c
@@ -460,7 +460,8 @@ glob0(pattern, pglob)
        glob_t *pglob;
 {
        const Char *qpatnext;
-       int c, error, oldpathc;
+       int c, error;
+       size_t oldpathc;
        Char *bufnext, patbuf[MAXPATHLEN+1];
        size_t limit = 0;

@@ -545,7 +546,7 @@ glob0(pattern, pglob)
                }
        } else if (!(pglob->gl_flags & GLOB_NOSORT)) {
                qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
-                   (size_t)pglob->gl_pathc - oldpathc, sizeof(char *),
+                   pglob->gl_pathc - oldpathc, sizeof(char *),
                    compare);
        }

@@ -791,8 +792,7 @@ globextend(path, pglob, limit)
        size_t *limit;
 {
        char **pathv;
-       int i;
-       size_t newsize, len;
+       size_t i, newsize, len;
        char *copy;
        const Char *p;

@@ -895,7 +895,7 @@ void
 globfree(pglob)
        glob_t *pglob;
 {
-       int i;
+       size_t i;
        char **pp;

        _DIAGASSERT(pglob != NULL);

--- usr.bin/less/less/lglob.h.orig      2003-04-14 12:10:00.000000000 +1000
+++ usr.bin/less/less/lglob.h
@@ -34,7 +34,7 @@
 #else
 #if MSDOS_COMPILER==DJGPPC

-#define        DECL_GLOB_LIST(list)            glob_t list;  int i;
+#define        DECL_GLOB_LIST(list)            glob_t list;  size_t i;
 #define        GLOB_LIST(filename,list)        glob(filename,GLOB_NOCHECK,0,&list)
 #define        GLOB_LIST_FAILED(list)          0
 #define        SCAN_GLOB_LIST(list,p)          i = 0;  i < list.gl_pathc;  i++

--- usr.bin/man/man.c.orig      2004-01-06 10:23:36.000000000 +1100
+++ usr.bin/man/man.c
@@ -381,7 +381,8 @@ manual(page, tag, pg, pathsearch)
 {
        ENTRY *ep, *e_sufp, *e_tag;
        TAG *missp, *sufp;
-       int anyfound, cnt, error, found;
+       int anyfound, error, found;
+       size_t cnt;
        char *p, buf[MAXPATHLEN], *escpage, *eptr;
        static const char escglob[] = "\\~?*{}[]";

--- usr.sbin/catman/catman.c.orig       2004-10-30 06:35:16.000000000 +1000
+++ usr.sbin/catman/catman.c
@@ -264,7 +264,8 @@ uniquepath(void)
        struct stat st1;
        struct stat st2;
        struct stat st3;
-       int i, j, len, lnk, gflags;
+       int len, lnk, gflags;
+       size_t i, j;
        char path[PATH_MAX], *p;

        gflags = 0;

--- usr.sbin/pkg_install/lib/file.c.orig        2005-12-06 12:07:30.000000000 +1100
+++ usr.sbin/pkg_install/lib/file.c
@@ -553,7 +553,7 @@ move_files(const char *dir, const char *
 {
        char    fpath[MaxPathSize];
        glob_t  globbed;
-       int     i;
+       size_t  i;

        (void) snprintf(fpath, sizeof(fpath), "%s/%s", dir, pattern);
        if ((i=glob(fpath, GLOB_NOSORT, NULL, &globbed)) != 0) {
@@ -589,7 +589,7 @@ remove_files(const char *path, const cha
 {
        char    fpath[MaxPathSize];
        glob_t  globbed;
-       int     i;
+       size_t  i;

        (void) snprintf(fpath, sizeof(fpath), "%s/%s", path, pattern);
        if ((i=glob(fpath, GLOB_NOSORT, NULL, &globbed)) != 0) {