*/
#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"
int fd_out;
} cur;
-void *fudge_opendir(const char *path)
+static void *
+fudge_opendir(const char *path)
{
struct SFTP_OPENDIR *r;
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__ */
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));
}
}
-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);
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);
}
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;
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));
}