From 18bb473eb0509ef74cb7eb644925a9afaa8efaae Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 28 Mar 2001 14:35:30 +1000 Subject: - (djm) Work around Solaris' broken struct dirent. Diagnosis and suggested fix from Philippe Levan --- sftp-glob.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'sftp-glob.c') 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) 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__ */ @@ -73,22 +75,30 @@ 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) -- cgit v1.2.3