Skip to content

Commit a6e0535

Browse files
committed
strtok_s is not defined in Cygwin. Use strok_r instead.
Also do some minor re-styling.
1 parent 24b1cd4 commit a6e0535

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

yara.c

+22-7
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ static void scan_dir(
395395
}
396396

397397

398+
#if defined(__CYGWIN__)
399+
#define strtok_s strtok_r
400+
#endif
401+
398402
static int populate_scan_list(
399403
const char* filename,
400404
int recursive,
@@ -403,29 +407,40 @@ static int populate_scan_list(
403407
char* context;
404408
DWORD nread;
405409

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+
408414
if (hFile == INVALID_HANDLE_VALUE)
409415
{
410416
fprintf(stderr, "error: could not open file \"%s\".\n", filename);
411417
return ERROR_COULD_NOT_OPEN_FILE;
412418
}
419+
413420
DWORD fileSize = GetFileSize(hFile, NULL);
421+
414422
if (fileSize == INVALID_FILE_SIZE)
415423
{
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);
417426
CloseHandle(hFile);
418427
return ERROR_COULD_NOT_READ_FILE;
419428
}
429+
420430
// 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+
422434
if (buf == NULL)
423435
{
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);
425438
CloseHandle(hFile);
426439
return ERROR_INSUFFICIENT_MEMORY;
427440
}
441+
428442
DWORD total = 0;
443+
429444
while (total < fileSize)
430445
{
431446
if (!ReadFile(hFile, buf + total, fileSize - total, &nread, NULL))
@@ -438,6 +453,7 @@ static int populate_scan_list(
438453
}
439454

440455
char* path = strtok_s(buf, "\n", &context);
456+
441457
while (path != NULL)
442458
{
443459
// remove trailing carriage return, if present
@@ -1413,10 +1429,9 @@ int main(
14131429
else
14141430
{
14151431
result = populate_scan_list(argv[argc - 1], recursive_search, start_time);
1432+
14161433
if (result != ERROR_SUCCESS)
1417-
{
14181434
exit_with_code(EXIT_FAILURE);
1419-
}
14201435
}
14211436

14221437
file_queue_finish();

0 commit comments

Comments
 (0)