1
#ifndef WIN32_LEAN_AND_MEAN
2
#define WIN32_LEAN_AND_MEAN
16
#define SUFFIX _T("*")
17
#define SLASH _T("\\")
19
/* Helper for opendir(). */
20
static inline unsigned _tGetFileAttributes (const _TCHAR * tPath)
23
/* GetFileAttributesW does not work on W9x, so convert to ANSI */
26
char aPath [MAX_PATH];
27
WideCharToMultiByte (CP_ACP, 0, tPath, -1, aPath, MAX_PATH, NULL,
29
return GetFileAttributesA (aPath);
31
return GetFileAttributesW (tPath);
33
return GetFileAttributesA (tPath);
38
_topendir (const _TCHAR *szPath)
42
_TCHAR szFullPath[MAX_PATH];
52
if (szPath[0] == _T('\0'))
58
rc = _tGetFileAttributes (szPath);
59
if (rc == (unsigned int)-1)
65
if (!(rc & FILE_ATTRIBUTE_DIRECTORY))
72
_tfullpath (szFullPath,szPath,MAX_PATH);
74
nd = (_TDIR *) malloc (sizeof (_TDIR) + (_tcslen (szFullPath)
76
+ _tcslen (SUFFIX) + 1)
86
_tcscpy (nd->dd_name,szFullPath);
88
if (nd->dd_name[0] != _T('\0')
89
&& _tcsrchr (nd->dd_name,_T('/')) != nd->dd_name
90
+ _tcslen (nd->dd_name) - 1
91
&& _tcsrchr (nd->dd_name,_T('\\')) != nd->dd_name
92
+ _tcslen (nd->dd_name) - 1)
94
_tcscat (nd->dd_name,SLASH);
97
_tcscat (nd->dd_name,SUFFIX);
103
nd->dd_dir.d_ino = 0;
104
nd->dd_dir.d_reclen = 0;
105
nd->dd_dir.d_namlen = 0;
106
memset (nd->dd_dir.d_name,0,FILENAME_MAX);
112
_treaddir (_TDIR * dirp)
119
return (struct _tdirent *) 0;
122
if (dirp->dd_stat < 0)
125
return (struct _tdirent *) 0;
127
else if (dirp->dd_stat == 0)
130
dirp->dd_handle = _tfindfirst (dirp->dd_name,&(dirp->dd_dta));
132
if (dirp->dd_handle == -1)
145
if (_tfindnext (dirp->dd_handle,&(dirp->dd_dta)))
148
DWORD winerr = GetLastError ();
149
if (winerr == ERROR_NO_MORE_FILES)
151
_findclose (dirp->dd_handle);
152
dirp->dd_handle = -1;
162
if (dirp->dd_stat > 0)
165
dirp->dd_dir.d_namlen = _tcslen (dirp->dd_dta.name);
166
_tcscpy (dirp->dd_dir.d_name,dirp->dd_dta.name);
167
return &dirp->dd_dir;
170
return (struct _tdirent *) 0;
174
_tclosedir (_TDIR * dirp)
187
if (dirp->dd_handle != -1)
189
rc = _findclose (dirp->dd_handle);
198
_trewinddir (_TDIR * dirp)
208
if (dirp->dd_handle != -1)
210
_findclose (dirp->dd_handle);
213
dirp->dd_handle = -1;
218
_ttelldir (_TDIR * dirp)
227
return dirp->dd_stat;
231
_tseekdir (_TDIR * dirp,long lPos)
250
if (dirp->dd_handle != -1)
252
_findclose (dirp->dd_handle);
254
dirp->dd_handle = -1;
262
while ((dirp->dd_stat < lPos) && _treaddir (dirp));