This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / ext / File / Glob / bsd_glob.c
index d0d4a91..0635901 100644 (file)
@@ -200,10 +200,31 @@ static Direntry_t *       my_readdir(DIR*);
 static Direntry_t *
 my_readdir(DIR *d)
 {
+#ifndef NETWARE
     return PerlDir_read(d);
+#else
+    return (DIR *)PerlDir_read(d);
+#endif
 }
 #else
-#define        my_readdir      readdir
+
+/* ReliantUNIX (OS formerly known as SINIX) defines readdir
+ * in LFS-mode to be a 64-bit version of readdir.  */
+
+#   ifdef sinix
+static Direntry_t *    my_readdir(DIR*);
+
+static Direntry_t *
+my_readdir(DIR *d)
+{
+    return readdir(d);
+}
+#   else
+
+#       define my_readdir      readdir
+
+#   endif
+
 #endif
 
 #ifdef MACOS_TRADITIONAL
@@ -240,12 +261,19 @@ bsd_glob(const char *pattern, int flags,
 #ifndef MACOS_TRADITIONAL
        patnext = (U8 *) pattern;
 #endif
+       /* TODO: GLOB_APPEND / GLOB_DOOFFS aren't supported yet */
+#if 0
        if (!(flags & GLOB_APPEND)) {
                pglob->gl_pathc = 0;
                pglob->gl_pathv = NULL;
                if (!(flags & GLOB_DOOFFS))
                        pglob->gl_offs = 0;
        }
+#else
+       pglob->gl_pathc = 0;
+       pglob->gl_pathv = NULL;
+       pglob->gl_offs = 0;
+#endif
        pglob->gl_flags = flags & ~GLOB_MAGCHAR;
        pglob->gl_errfunc = errfunc;
        pglob->gl_matchc = 0;
@@ -304,7 +332,7 @@ bsd_glob(const char *pattern, int flags,
 
        /* We operate on a copy of the pattern */
        len = strlen(pattern);
-       New(0, new_pat, len + 1, char);
+       Newx(new_pat, len + 1, char);
        if (new_pat == NULL)
            return (GLOB_NOSPACE);
 
@@ -506,7 +534,6 @@ globexp2(const Char *ptr, const Char *pattern,
 static const Char *
 globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
 {
-       struct passwd *pwd;
        char *h;
        const Char *p;
        Char *b, *eb;
@@ -517,7 +544,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
        /* Copy up to the end of the string or / */
        eb = &patbuf[patbuf_len - 1];
        for (p = pattern + 1, h = (char *) patbuf;
-            h < (char*)eb && *p && *p != BG_SLASH; *h++ = *p++)
+            h < (char*)eb && *p && *p != BG_SLASH; *h++ = (char)*p++)
                ;
 
        *h = BG_EOS;
@@ -534,6 +561,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
                 */
                if ((h = getenv("HOME")) == NULL) {
 #ifdef HAS_PASSWD
+                       struct passwd *pwd;
                        if ((pwd = getpwuid(getuid())) == NULL)
                                return pattern;
                        else
@@ -547,6 +575,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
                 * Expand a ~user
                 */
 #ifdef HAS_PASSWD
+               struct passwd *pwd;
                if ((pwd = getpwnam((char*) patbuf)) == NULL)
                        return pattern;
                else
@@ -980,7 +1009,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp)
        if (pglob->gl_pathv)
                pathv = Renew(pglob->gl_pathv,newsize,char*);
        else
-               New(0,pathv,newsize,char*);
+               Newx(pathv,newsize,char*);
        if (pathv == NULL) {
                if (pglob->gl_pathv) {
                        Safefree(pglob->gl_pathv);
@@ -1001,7 +1030,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limitp)
                ;
        len = (STRLEN)(p - path);
        *limitp += len;
-       New(0, copy, p-path, char);
+       Newx(copy, p-path, char);
        if (copy != NULL) {
                if (g_Ctoc(path, copy, len)) {
                        Safefree(copy);
@@ -1159,7 +1188,7 @@ static int
 g_Ctoc(register const Char *str, char *buf, STRLEN len)
 {
        while (len--) {
-               if ((*buf++ = *str++) == BG_EOS)
+               if ((*buf++ = (char)*str++) == BG_EOS)
                        return (0);
        }
        return (1);
@@ -1187,7 +1216,7 @@ qprintf(const char *str, register Char *s)
 
 #ifdef MACOS_TRADITIONAL
 
-/* Replace the last occurence of the pattern ":[^:]+::", e.g. ":lib::",
+/* Replace the last occurrence of the pattern ":[^:]+::", e.g. ":lib::",
    with a single ':', if possible. It is not an error, if the pattern
    doesn't match (we return -1), but if there are two consecutive colons
    '::', there must be a preceding ':[^:]+'. Hence,  a volume path like