@@ -395,6 +395,10 @@ static void scan_dir(
395
395
}
396
396
397
397
398
+ #if defined(__CYGWIN__ )
399
+ #define strtok_s strtok_r
400
+ #endif
401
+
398
402
static int populate_scan_list (
399
403
const char * filename ,
400
404
int recursive ,
@@ -403,29 +407,40 @@ static int populate_scan_list(
403
407
char * context ;
404
408
DWORD nread ;
405
409
406
- HANDLE hFile = CreateFile (filename , GENERIC_READ , FILE_SHARE_READ , NULL ,
407
- OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
410
+ HANDLE hFile = CreateFile (
411
+ filename , GENERIC_READ , FILE_SHARE_READ , NULL ,
412
+ OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
413
+
408
414
if (hFile == INVALID_HANDLE_VALUE )
409
415
{
410
416
fprintf (stderr , "error: could not open file \"%s\".\n" , filename );
411
417
return ERROR_COULD_NOT_OPEN_FILE ;
412
418
}
419
+
413
420
DWORD fileSize = GetFileSize (hFile , NULL );
421
+
414
422
if (fileSize == INVALID_FILE_SIZE )
415
423
{
416
- fprintf (stderr , "error: could not determine size of file \"%s\".\n" , filename );
424
+ fprintf (stderr ,
425
+ "error: could not determine size of file \"%s\".\n" , filename );
417
426
CloseHandle (hFile );
418
427
return ERROR_COULD_NOT_READ_FILE ;
419
428
}
429
+
420
430
// INVALID_FILE_SIZE is 0xFFFFFFFF, so (+1) will not overflow
421
- char * buf = (char * ) VirtualAlloc (NULL , fileSize + 1 , MEM_COMMIT , PAGE_READWRITE );
431
+ char * buf = (char * ) VirtualAlloc (
432
+ NULL , fileSize + 1 , MEM_COMMIT , PAGE_READWRITE );
433
+
422
434
if (buf == NULL )
423
435
{
424
- fprintf (stderr , "error: could not allocate memory for file \"%s\".\n" , filename );
436
+ fprintf (stderr ,
437
+ "error: could not allocate memory for file \"%s\".\n" , filename );
425
438
CloseHandle (hFile );
426
439
return ERROR_INSUFFICIENT_MEMORY ;
427
440
}
441
+
428
442
DWORD total = 0 ;
443
+
429
444
while (total < fileSize )
430
445
{
431
446
if (!ReadFile (hFile , buf + total , fileSize - total , & nread , NULL ))
@@ -438,6 +453,7 @@ static int populate_scan_list(
438
453
}
439
454
440
455
char * path = strtok_s (buf , "\n" , & context );
456
+
441
457
while (path != NULL )
442
458
{
443
459
// remove trailing carriage return, if present
@@ -1413,10 +1429,9 @@ int main(
1413
1429
else
1414
1430
{
1415
1431
result = populate_scan_list (argv [argc - 1 ], recursive_search , start_time );
1432
+
1416
1433
if (result != ERROR_SUCCESS )
1417
- {
1418
1434
exit_with_code (EXIT_FAILURE );
1419
- }
1420
1435
}
1421
1436
1422
1437
file_queue_finish ();
0 commit comments