From 36c117dcea1521269aa0a587f7d883b19444da33 Mon Sep 17 00:00:00 2001 From: meep-eep Date: Wed, 9 Feb 2005 00:59:38 +0000 Subject: [PATCH] bug fix git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1525 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/uio/stdio/stdio.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sc2/src/sc2code/libs/uio/stdio/stdio.c b/sc2/src/sc2code/libs/uio/stdio/stdio.c index 504367e0b..3043a3786 100644 --- a/sc2/src/sc2code/libs/uio/stdio/stdio.c +++ b/sc2/src/sc2code/libs/uio/stdio/stdio.c @@ -615,6 +615,7 @@ stdio_EntriesIterator_new(long dirHandle) { stdio_EntriesIterator * stdio_EntriesIterator_new(DIR *dirHandle) { stdio_EntriesIterator *result; + size_t bufferSize; result = stdio_EntriesIterator_alloc(); result->dirHandle = dirHandle; @@ -623,18 +624,19 @@ stdio_EntriesIterator_new(DIR *dirHandle) { // maximum d_name field (NAME_MAX). // However, POSIX doesn't require this, and in fact // at least QNX defines struct dirent with an empty d_name field. + // Solaris defineds it with a d_name field of length 1. // This should take care of it: - result->direntBuffer = uio_malloc( - sizeof (struct dirent) - - ((sizeof (((struct dirent *) 0)->d_name) + 3) & 3) - + (((NAME_MAX + 1) + 3) & 3)); + bufferSize = sizeof (struct dirent) + - sizeof (((struct dirent *) 0)->d_name) + (NAME_MAX + 1); // Take the length of the dirent structure as it is defined, // subtract the length of the d_name field, and add the length // of the maximum length d_name field (NAME_MAX plus 1 for // the '\0'). - // The '(... +3) & 3' is to take into account that fields - // will be aligned on 4 bytes. - // (What about 64 bits machines?) + // XXX: Could this give problems with weird alignments? + // Note that the standard doesn't say d_name has to be + // the last field in the struct, though on all platforms + // I know of, it is. + result->direntBuffer = uio_malloc(bufferSize); return result; } #endif