summaryrefslogtreecommitdiff
path: root/sftp-glob.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-03-28 14:35:30 +1000
committerDamien Miller <djm@mindrot.org>2001-03-28 14:35:30 +1000
commit18bb473eb0509ef74cb7eb644925a9afaa8efaae (patch)
tree7f9ae81f1b275197e9f129910213fa2487d9593d /sftp-glob.c
parentc79bc0d75bca9367947020dd3ec806d33fa19b1b (diff)
- (djm) Work around Solaris' broken struct dirent. Diagnosis and suggested
fix from Philippe Levan <levan@epix.net>
Diffstat (limited to 'sftp-glob.c')
-rw-r--r--sftp-glob.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/sftp-glob.c b/sftp-glob.c
index 79dca00f1..f1252eecc 100644
--- a/sftp-glob.c
+++ b/sftp-glob.c
@@ -65,7 +65,9 @@ void *fudge_opendir(const char *path)
65 65
66struct dirent *fudge_readdir(struct SFTP_OPENDIR *od) 66struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
67{ 67{
68 static struct dirent ret; 68 /* Solaris needs sizeof(dirent) + path length (see below) */
69 static char buf[sizeof(struct dirent) + MAXPATHLEN];
70 struct dirent *ret = (struct dirent *)buf;
69#ifdef __GNU_LIBRARY__ 71#ifdef __GNU_LIBRARY__
70 static int inum = 1; 72 static int inum = 1;
71#endif /* __GNU_LIBRARY__ */ 73#endif /* __GNU_LIBRARY__ */
@@ -73,22 +75,30 @@ struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
73 if (od->dir[od->offset] == NULL) 75 if (od->dir[od->offset] == NULL)
74 return(NULL); 76 return(NULL);
75 77
76 memset(&ret, 0, sizeof(ret)); 78 memset(buf, 0, sizeof(buf));
77 strlcpy(ret.d_name, od->dir[od->offset++]->filename,
78 sizeof(ret.d_name));
79 79
80 /*
81 * Solaris defines dirent->d_name as a one byte array and expects
82 * you to hack around it.
83 */
84#ifdef BROKEN_ONE_BYTE_DIRENT_D_NAME
85 strlcpy(ret->d_name, od->dir[od->offset++]->filename, MAXPATHLEN);
86#else
87 strlcpy(ret->d_name, od->dir[od->offset++]->filename,
88 sizeof(ret->d_name));
89#endif
80#ifdef __GNU_LIBRARY__ 90#ifdef __GNU_LIBRARY__
81 /* 91 /*
82 * Idiot glibc uses extensions to struct dirent for readdir with 92 * Idiot glibc uses extensions to struct dirent for readdir with
83 * ALTDIRFUNCs. Not that this is documented anywhere but the 93 * ALTDIRFUNCs. Not that this is documented anywhere but the
84 * source... Fake an inode number to appease it. 94 * source... Fake an inode number to appease it.
85 */ 95 */
86 ret.d_ino = inum++; 96 ret->d_ino = inum++;
87 if (!inum) 97 if (!inum)
88 inum = 1; 98 inum = 1;
89#endif /* __GNU_LIBRARY__ */ 99#endif /* __GNU_LIBRARY__ */
90 100
91 return(&ret); 101 return(ret);
92} 102}
93 103
94void fudge_closedir(struct SFTP_OPENDIR *od) 104void fudge_closedir(struct SFTP_OPENDIR *od)