123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "lt__private.h"
- #include <assert.h>
- #include "lt__dirent.h"
- #if defined __WINDOWS__
- void
- closedir (DIR *entry)
- {
- assert (entry != (DIR *) NULL);
- FindClose (entry->hSearch);
- free (entry);
- }
- DIR *
- opendir (const char *path)
- {
- char file_spec[LT_FILENAME_MAX];
- DIR *entry;
- assert (path != (char *) 0);
- if (lt_strlcpy (file_spec, path, sizeof file_spec) >= sizeof file_spec
- || lt_strlcat (file_spec, "\\", sizeof file_spec) >= sizeof file_spec)
- return (DIR *) 0;
- entry = (DIR *) malloc (sizeof(DIR));
- if (entry != (DIR *) 0)
- {
- entry->firsttime = TRUE;
- entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
- if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- if (lt_strlcat (file_spec, "\\*.*", sizeof file_spec) < sizeof file_spec)
- {
- entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
- }
- if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- entry = (free (entry), (DIR *) 0);
- }
- }
- }
- return entry;
- }
- struct dirent *
- readdir (DIR *entry)
- {
- int status;
- if (entry == (DIR *) 0)
- return (struct dirent *) 0;
- if (!entry->firsttime)
- {
- status = FindNextFile (entry->hSearch, &entry->Win32FindData);
- if (status == 0)
- return (struct dirent *) 0;
- }
- entry->firsttime = FALSE;
- if (lt_strlcpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
- sizeof entry->file_info.d_name) >= sizeof entry->file_info.d_name)
- return (struct dirent *) 0;
- entry->file_info.d_namlen = strlen (entry->file_info.d_name);
- return &entry->file_info;
- }
- #endif
|