@@ -52,19 +52,17 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
52
52
53
53
DirSpec = (LPTSTR) malloc (BUFSIZE);
54
54
55
- if ( DirSpec == NULL )
56
- {
57
- errorstream<<" GetDirListing: Insufficient memory available" <<std::endl;
58
- retval = 1 ;
59
- goto Cleanup;
55
+ if (DirSpec == NULL ) {
56
+ errorstream<<" GetDirListing: Insufficient memory available" <<std::endl;
57
+ retval = 1 ;
58
+ goto Cleanup;
60
59
}
61
60
62
61
// Check that the input is not larger than allowed.
63
- if (pathstring.size () > (BUFSIZE - 2 ))
64
- {
65
- errorstream<<" GetDirListing: Input directory is too large." <<std::endl;
66
- retval = 3 ;
67
- goto Cleanup;
62
+ if (pathstring.size () > (BUFSIZE - 2 )) {
63
+ errorstream<<" GetDirListing: Input directory is too large." <<std::endl;
64
+ retval = 3 ;
65
+ goto Cleanup;
68
66
}
69
67
70
68
// _tprintf (TEXT("Target directory is %s.\n"), pathstring.c_str());
@@ -74,13 +72,10 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
74
72
// Find the first file in the directory.
75
73
hFind = FindFirstFile (DirSpec, &FindFileData);
76
74
77
- if (hFind == INVALID_HANDLE_VALUE)
78
- {
75
+ if (hFind == INVALID_HANDLE_VALUE) {
79
76
retval = (-1 );
80
77
goto Cleanup;
81
- }
82
- else
83
- {
78
+ } else {
84
79
// NOTE:
85
80
// Be very sure to not include '..' in the results, it will
86
81
// result in an epic failure when deleting stuff.
@@ -92,8 +87,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
92
87
listing.push_back (node);
93
88
94
89
// List all the other files in the directory.
95
- while (FindNextFile (hFind, &FindFileData) != 0 )
96
- {
90
+ while (FindNextFile (hFind, &FindFileData) != 0 ) {
97
91
DirListNode node;
98
92
node.name = FindFileData.cFileName ;
99
93
node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
@@ -103,15 +97,14 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
103
97
104
98
dwError = GetLastError ();
105
99
FindClose (hFind);
106
- if (dwError != ERROR_NO_MORE_FILES)
107
- {
100
+ if (dwError != ERROR_NO_MORE_FILES) {
108
101
errorstream<<" GetDirListing: FindNextFile error. Error is "
109
102
<<dwError<<std::endl;
110
103
retval = (-1 );
111
104
goto Cleanup;
112
105
}
113
106
}
114
- retval = 0 ;
107
+ retval = 0 ;
115
108
116
109
Cleanup:
117
110
free (DirSpec);
@@ -242,53 +235,51 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
242
235
{
243
236
std::vector<DirListNode> listing;
244
237
245
- DIR *dp;
246
- struct dirent *dirp;
247
- if ((dp = opendir (pathstring.c_str ())) == NULL ) {
238
+ DIR *dp;
239
+ struct dirent *dirp;
240
+ if ((dp = opendir (pathstring.c_str ())) == NULL ) {
248
241
// infostream<<"Error("<<errno<<") opening "<<pathstring<<std::endl;
249
- return listing;
250
- }
242
+ return listing;
243
+ }
251
244
252
- while ((dirp = readdir (dp)) != NULL ) {
245
+ while ((dirp = readdir (dp)) != NULL ) {
253
246
// NOTE:
254
247
// Be very sure to not include '..' in the results, it will
255
248
// result in an epic failure when deleting stuff.
256
- if (dirp->d_name [ 0 ]!= ' . ' ){
257
- DirListNode node ;
258
- node. name = dirp-> d_name ;
259
- if (node. name == " . " || node. name == " .. " )
260
- continue ;
249
+ if (dirp->d_name == " . " || dirp-> d_name == " .. " )
250
+ continue ;
251
+
252
+ DirListNode node;
253
+ node. name = dirp-> d_name ;
261
254
262
- int isdir = -1 ; // -1 means unknown
255
+ int isdir = -1 ; // -1 means unknown
263
256
264
- /*
265
- POSIX doesn't define d_type member of struct dirent and
266
- certain filesystems on glibc/Linux will only return
267
- DT_UNKNOWN for the d_type member.
257
+ /*
258
+ POSIX doesn't define d_type member of struct dirent and
259
+ certain filesystems on glibc/Linux will only return
260
+ DT_UNKNOWN for the d_type member.
268
261
269
- Also we don't know whether symlinks are directories or not.
270
- */
262
+ Also we don't know whether symlinks are directories or not.
263
+ */
271
264
#ifdef _DIRENT_HAVE_D_TYPE
272
- if (dirp->d_type != DT_UNKNOWN && dirp->d_type != DT_LNK)
273
- isdir = (dirp->d_type == DT_DIR);
265
+ if (dirp->d_type != DT_UNKNOWN && dirp->d_type != DT_LNK)
266
+ isdir = (dirp->d_type == DT_DIR);
274
267
#endif /* _DIRENT_HAVE_D_TYPE */
275
268
276
- /*
277
- Was d_type DT_UNKNOWN, DT_LNK or nonexistent?
278
- If so, try stat().
279
- */
280
- if (isdir == -1 )
281
- {
282
- struct stat statbuf;
283
- if (stat ((pathstring + " /" + node.name ).c_str (), &statbuf))
284
- continue ;
285
- isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
286
- }
287
- node.dir = isdir;
288
- listing.push_back (node);
269
+ /*
270
+ Was d_type DT_UNKNOWN, DT_LNK or nonexistent?
271
+ If so, try stat().
272
+ */
273
+ if (isdir == -1 ) {
274
+ struct stat statbuf;
275
+ if (stat ((pathstring + " /" + node.name ).c_str (), &statbuf))
276
+ continue ;
277
+ isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
289
278
}
290
- }
291
- closedir (dp);
279
+ node.dir = isdir;
280
+ listing.push_back (node);
281
+ }
282
+ closedir (dp);
292
283
293
284
return listing;
294
285
}
0 commit comments