]> andersk Git - openssh.git/blobdiff - sftp-glob.c
- (stevesk) use X/Open socket interface for HP-UX 10.X also
[openssh.git] / sftp-glob.c
index 17f46a1513b1927c62f2f2b34cca5dccb14bb598..18b44f82e56bb56c00c2691dae35580739e68376 100644 (file)
@@ -23,9 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sftp-glob.c,v 1.1 2001/03/13 22:42:54 djm Exp $");
-
-#include <glob.h>
+RCSID("$OpenBSD: sftp-glob.c,v 1.6 2001/06/23 15:12:20 itojun Exp $");
 
 #include "ssh.h"
 #include "buffer.h"
@@ -51,7 +49,8 @@ static struct {
        int fd_out;
 } cur;
 
-void *fudge_opendir(const char *path)
+static void *
+fudge_opendir(const char *path)
 {
        struct SFTP_OPENDIR *r;
        
@@ -65,9 +64,12 @@ void *fudge_opendir(const char *path)
        return((void*)r);
 }
 
-struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
+static struct dirent *
+fudge_readdir(struct SFTP_OPENDIR *od)
 {
-       static struct dirent ret;
+       /* Solaris needs sizeof(dirent) + path length (see below) */
+       static char buf[sizeof(struct dirent) + MAXPATHLEN];
+       struct dirent *ret = (struct dirent *)buf;
 #ifdef __GNU_LIBRARY__
        static int inum = 1;
 #endif /* __GNU_LIBRARY__ */
@@ -75,31 +77,41 @@ struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
        if (od->dir[od->offset] == NULL)
                return(NULL);
 
-       memset(&ret, 0, sizeof(ret));
-       strlcpy(ret.d_name, od->dir[od->offset++]->filename, 
-           sizeof(ret.d_name));
+       memset(buf, 0, sizeof(buf));
 
+       /*
+        * Solaris defines dirent->d_name as a one byte array and expects
+        * you to hack around it.
+        */
+#ifdef BROKEN_ONE_BYTE_DIRENT_D_NAME
+       strlcpy(ret->d_name, od->dir[od->offset++]->filename, MAXPATHLEN);
+#else
+       strlcpy(ret->d_name, od->dir[od->offset++]->filename,
+           sizeof(ret->d_name));
+#endif
 #ifdef __GNU_LIBRARY__
        /*
         * Idiot glibc uses extensions to struct dirent for readdir with
         * ALTDIRFUNCs. Not that this is documented anywhere but the 
         * source... Fake an inode number to appease it.
         */
-       ret.d_ino = inum++;
+       ret->d_ino = inum++;
        if (!inum)
                inum = 1;
 #endif /* __GNU_LIBRARY__ */
 
-       return(&ret);
+       return(ret);
 }
 
-void fudge_closedir(struct SFTP_OPENDIR *od)
+static void
+fudge_closedir(struct SFTP_OPENDIR *od)
 {
        free_sftp_dirents(od->dir);
-       free(od);
+       xfree(od);
 }
 
-void attrib_to_stat(Attrib *a, struct stat *st)
+static void
+attrib_to_stat(Attrib *a, struct stat *st)
 {
        memset(st, 0, sizeof(*st));
        
@@ -117,11 +129,12 @@ void attrib_to_stat(Attrib *a, struct stat *st)
        }
 }
 
-int fudge_lstat(const char *path, struct stat *st)
+static int
+fudge_lstat(const char *path, struct stat *st)
 {
        Attrib *a;
        
-       if (!(a = do_lstat(cur.fd_in, cur.fd_out, (char*)path)))
+       if (!(a = do_lstat(cur.fd_in, cur.fd_out, (char*)path, 0)))
                return(-1);
        
        attrib_to_stat(a, st);
@@ -129,11 +142,12 @@ int fudge_lstat(const char *path, struct stat *st)
        return(0);
 }
 
-int fudge_stat(const char *path, struct stat *st)
+static int
+fudge_stat(const char *path, struct stat *st)
 {
        Attrib *a;
        
-       if (!(a = do_stat(cur.fd_in, cur.fd_out, (char*)path)))
+       if (!(a = do_stat(cur.fd_in, cur.fd_out, (char*)path, 0)))
                return(-1);
        
        attrib_to_stat(a, st);
@@ -142,8 +156,8 @@ int fudge_stat(const char *path, struct stat *st)
 }
 
 int
-remote_glob(int fd_in, int fd_out, const char *pattern, int flags, 
-    const int (*errfunc)(const char *, int), glob_t *pglob)
+remote_glob(int fd_in, int fd_out, const char *pattern, int flags,
+    int (*errfunc)(const char *, int), glob_t *pglob)
 {
        pglob->gl_opendir = (void*)fudge_opendir;
        pglob->gl_readdir = (void*)fudge_readdir;
@@ -155,6 +169,6 @@ remote_glob(int fd_in, int fd_out, const char *pattern, int flags,
        cur.fd_in = fd_in;
        cur.fd_out = fd_out;
 
-       return(glob(pattern, flags | GLOB_ALTDIRFUNC, (void*)errfunc, 
+       return(glob(pattern, flags | GLOB_ALTDIRFUNC, (void*)errfunc,
            pglob));
 }
This page took 0.07433 seconds and 4 git commands to generate.