bug fix
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1525 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -615,6 +615,7 @@ stdio_EntriesIterator_new(long dirHandle) {
|
|||||||
stdio_EntriesIterator *
|
stdio_EntriesIterator *
|
||||||
stdio_EntriesIterator_new(DIR *dirHandle) {
|
stdio_EntriesIterator_new(DIR *dirHandle) {
|
||||||
stdio_EntriesIterator *result;
|
stdio_EntriesIterator *result;
|
||||||
|
size_t bufferSize;
|
||||||
|
|
||||||
result = stdio_EntriesIterator_alloc();
|
result = stdio_EntriesIterator_alloc();
|
||||||
result->dirHandle = dirHandle;
|
result->dirHandle = dirHandle;
|
||||||
@@ -623,18 +624,19 @@ stdio_EntriesIterator_new(DIR *dirHandle) {
|
|||||||
// maximum d_name field (NAME_MAX).
|
// maximum d_name field (NAME_MAX).
|
||||||
// However, POSIX doesn't require this, and in fact
|
// However, POSIX doesn't require this, and in fact
|
||||||
// at least QNX defines struct dirent with an empty d_name field.
|
// 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:
|
// This should take care of it:
|
||||||
result->direntBuffer = uio_malloc(
|
bufferSize = sizeof (struct dirent)
|
||||||
sizeof (struct dirent)
|
- sizeof (((struct dirent *) 0)->d_name) + (NAME_MAX + 1);
|
||||||
- ((sizeof (((struct dirent *) 0)->d_name) + 3) & 3)
|
|
||||||
+ (((NAME_MAX + 1) + 3) & 3));
|
|
||||||
// Take the length of the dirent structure as it is defined,
|
// Take the length of the dirent structure as it is defined,
|
||||||
// subtract the length of the d_name field, and add the length
|
// subtract the length of the d_name field, and add the length
|
||||||
// of the maximum length d_name field (NAME_MAX plus 1 for
|
// of the maximum length d_name field (NAME_MAX plus 1 for
|
||||||
// the '\0').
|
// the '\0').
|
||||||
// The '(... +3) & 3' is to take into account that fields
|
// XXX: Could this give problems with weird alignments?
|
||||||
// will be aligned on 4 bytes.
|
// Note that the standard doesn't say d_name has to be
|
||||||
// (What about 64 bits machines?)
|
// the last field in the struct, though on all platforms
|
||||||
|
// I know of, it is.
|
||||||
|
result->direntBuffer = uio_malloc(bufferSize);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user