81
81
82
82
#define TO_SOCKET (x ) _get_osfhandle(x)
83
83
84
- bool NtSyncProcess = TRUE;
85
-
86
84
static struct ChildRecord * CreateChild (const char * , const char * , SECURITY_ATTRIBUTES * , HANDLE , HANDLE , HANDLE );
87
85
static bool has_redirection (const char * );
88
86
static void StartSockets ();
@@ -502,26 +500,6 @@ FindFreeChildSlot(void)
502
500
}
503
501
504
502
505
- int
506
- SafeFree (char * * vec , int vecc )
507
- {
508
- // vec
509
- // |
510
- // V ^---------------------V
511
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
512
- // | | | .... | NULL | | ..... |\0 | | ..... |\0 |...
513
- // +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
514
- // |- elements+1 -| ^ 1st element ^ 2nd element
515
-
516
- char * p ;
517
-
518
- p = (char * )vec ;
519
- free (p );
520
-
521
- return 0 ;
522
- }
523
-
524
-
525
503
/*
526
504
ruby -lne 'BEGIN{$cmds = Hash.new(0); $mask = 1}'
527
505
-e '$cmds[$_.downcase] |= $mask' -e '$mask <<= 1 if ARGF.eof'
@@ -1423,8 +1401,12 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
1423
1401
// return the pointer to the current file name.
1424
1402
//
1425
1403
1426
- #define GetBit (bits , i ) ((bits)[(i) / 8] & (1 << (i) % 8))
1427
- #define SetBit (bits , i ) ((bits)[(i) / 8] |= (1 << (i) % 8))
1404
+ #define GetBit (bits , i ) ((bits)[(i) / CHAR_BIT] & (1 << (i) % CHAR_BIT))
1405
+ #define SetBit (bits , i ) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT))
1406
+
1407
+ #define BitOfIsDir (n ) ((n) * 2)
1408
+ #define BitOfIsRep (n ) ((n) * 2 + 1)
1409
+ #define DIRENT_PER_CHAR (CHAR_BIT / 2)
1428
1410
1429
1411
DIR *
1430
1412
rb_w32_opendir (const char * filename )
@@ -1497,9 +1479,9 @@ rb_w32_opendir(const char *filename)
1497
1479
strcpy (p -> start , fd .cFileName );
1498
1480
p -> bits [0 ] = 0 ;
1499
1481
if (fd .dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
1500
- SetBit (p -> bits , 0 );
1482
+ SetBit (p -> bits , BitOfIsDir ( 0 ) );
1501
1483
if (fd .dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT )
1502
- SetBit (p -> bits , 1 );
1484
+ SetBit (p -> bits , BitOfIsRep ( 0 ) );
1503
1485
p -> nfiles ++ ;
1504
1486
1505
1487
//
@@ -1511,21 +1493,34 @@ rb_w32_opendir(const char *filename)
1511
1493
while (FindNextFile (fh , & fd )) {
1512
1494
char * newpath ;
1513
1495
1514
- len = strlen (fd .cFileName );
1496
+ len = strlen (fd .cFileName ) + 1 ;
1515
1497
1516
1498
//
1517
1499
// bump the string table size by enough for the
1518
1500
// new name and it's null terminator
1519
1501
//
1520
1502
1521
- newpath = (char * )realloc (p -> start , idx + len + 1 );
1503
+ newpath = (char * )realloc (p -> start , idx + len );
1522
1504
if (newpath == NULL ) {
1523
1505
goto error ;
1524
1506
}
1525
1507
p -> start = newpath ;
1526
1508
strcpy (& p -> start [idx ], fd .cFileName );
1509
+
1510
+ if (p -> nfiles % DIRENT_PER_CHAR == 0 ) {
1511
+ char * tmp = realloc (p -> bits , p -> nfiles / DIRENT_PER_CHAR + 1 );
1512
+ if (!tmp )
1513
+ goto error ;
1514
+ p -> bits = tmp ;
1515
+ p -> bits [p -> nfiles / DIRENT_PER_CHAR ] = 0 ;
1516
+ }
1517
+ if (fd .dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
1518
+ SetBit (p -> bits , BitOfIsDir (p -> nfiles ));
1519
+ if (fd .dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT )
1520
+ SetBit (p -> bits , BitOfIsRep (p -> nfiles ));
1521
+
1527
1522
p -> nfiles ++ ;
1528
- idx += len + 1 ;
1523
+ idx += len ;
1529
1524
}
1530
1525
FindClose (fh );
1531
1526
p -> size = idx ;
@@ -1576,8 +1571,8 @@ rb_w32_readdir(DIR *dirp)
1576
1571
//
1577
1572
// Attributes
1578
1573
//
1579
- dirp -> dirstr .d_isdir = GetBit (dirp -> bits , dirp -> loc * 2 );
1580
- dirp -> dirstr .d_isrep = GetBit (dirp -> bits , dirp -> loc * 2 + 1 );
1574
+ dirp -> dirstr .d_isdir = GetBit (dirp -> bits , BitOfIsDir ( dirp -> loc ) );
1575
+ dirp -> dirstr .d_isrep = GetBit (dirp -> bits , BitOfIsRep ( dirp -> loc ) );
1581
1576
1582
1577
//
1583
1578
// Now set up for the next call to readdir
@@ -2698,7 +2693,7 @@ poll_child_status(struct ChildRecord *child, int *stat_loc)
2698
2693
}
2699
2694
2700
2695
rb_pid_t
2701
- waitpid (rb_pid_t pid , int * stat_loc , int options )
2696
+ waitpid (rb_pid_t pid , int * stat_loc , int options )
2702
2697
{
2703
2698
DWORD timeout ;
2704
2699
0 commit comments