~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to win32/win32.c

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-06-06 11:58:24 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070606115824-qzldkdwq3dvfpf84
Tags: 1.9.0+20070606-1
* new upstream snapshot. (2006-06-06)
* updated debian/generated-incs/* files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1383
1383
// return the pointer to the current file name. 
1384
1384
//
1385
1385
 
1386
 
#define GetBit(bits, i) ((bits)[(i) / 8] &  (1 << (i) % 8))
1387
 
#define SetBit(bits, i) ((bits)[(i) / 8] |= (1 << (i) % 8))
 
1386
#define GetBit(bits, i) ((bits)[(i) / CHAR_BIT] &  (1 << (i) % CHAR_BIT))
 
1387
#define SetBit(bits, i) ((bits)[(i) / CHAR_BIT] |= (1 << (i) % CHAR_BIT))
 
1388
 
 
1389
#define BitOfIsDir(n) ((n) * 2)
 
1390
#define BitOfIsRep(n) ((n) * 2 + 1)
 
1391
#define DIRENT_PER_CHAR (CHAR_BIT / 2)
1388
1392
 
1389
1393
DIR *
1390
1394
rb_w32_opendir(const char *filename)
1443
1447
        return NULL;
1444
1448
    }
1445
1449
 
1446
 
    //
1447
 
    // now allocate the first part of the string table for the
1448
 
    // filenames that we find.
1449
 
    //
1450
 
    idx = strlen(fd.cFileName)+1;
1451
 
    if (!(p->start = (char *)malloc(idx)) || !(p->bits = (char *)malloc(1))) {
1452
 
      error:
1453
 
        rb_w32_closedir(p);
1454
 
        FindClose(fh);
1455
 
        errno = ENOMEM;
1456
 
        return NULL;
1457
 
    }
1458
 
    strlcpy(p->start, fd.cFileName, idx);
1459
 
    p->bits[0] = 0;
1460
 
    if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1461
 
        SetBit(p->bits, 0);
1462
 
    if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1463
 
        SetBit(p->bits, 1);
1464
 
    p->nfiles++;
 
1450
    idx = 0;
1465
1451
 
1466
1452
    //
1467
1453
    // loop finding all the files that match the wildcard
1469
1455
    // the variable idx should point one past the null terminator
1470
1456
    // of the previous string found.
1471
1457
    //
1472
 
    while (FindNextFile(fh, &fd)) {
 
1458
    do {
1473
1459
        len = strlen(fd.cFileName) + 1;
1474
1460
 
1475
1461
        //
1477
1463
        // new name and it's null terminator 
1478
1464
        //
1479
1465
        tmp = realloc(p->start, idx + len);
1480
 
        if (!tmp)
1481
 
            goto error;
 
1466
        if (!tmp) {
 
1467
          error:
 
1468
            rb_w32_closedir(p);
 
1469
            FindClose(fh);
 
1470
            errno = ENOMEM;
 
1471
            return NULL;
 
1472
        }
 
1473
 
1482
1474
        p->start = tmp;
1483
1475
        strlcpy(&p->start[idx], fd.cFileName, len);
1484
1476
 
1485
 
        if (p->nfiles % 4 == 0) {
1486
 
            tmp = realloc(p->bits, p->nfiles / 4 + 1);
 
1477
        if (p->nfiles % DIRENT_PER_CHAR == 0) {
 
1478
            tmp = realloc(p->bits, p->nfiles / DIRENT_PER_CHAR + 1);
1487
1479
            if (!tmp)
1488
1480
                goto error;
1489
1481
            p->bits = tmp;
1490
 
            p->bits[p->nfiles / 4] = 0;
 
1482
            p->bits[p->nfiles / DIRENT_PER_CHAR] = 0;
1491
1483
        }
1492
1484
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1493
 
            SetBit(p->bits, p->nfiles * 2);
 
1485
            SetBit(p->bits, BitOfIsDir(p->nfiles));
1494
1486
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1495
 
            SetBit(p->bits, p->nfiles * 2 + 1);
 
1487
            SetBit(p->bits, BitOfIsRep(p->nfiles));
1496
1488
 
1497
1489
        p->nfiles++;
1498
1490
        idx += len;
1499
 
    }
 
1491
    } while (FindNextFile(fh, &fd));
1500
1492
    FindClose(fh);
1501
1493
    p->size = idx;
1502
1494
    p->curr = p->start;
1547
1539
        //
1548
1540
        // Attributes
1549
1541
        //
1550
 
        dirp->dirstr.d_isdir = GetBit(dirp->bits, dirp->loc * 2);
1551
 
        dirp->dirstr.d_isrep = GetBit(dirp->bits, dirp->loc * 2 + 1);
 
1542
        dirp->dirstr.d_isdir = GetBit(dirp->bits, BitOfIsDir(dirp->loc));
 
1543
        dirp->dirstr.d_isrep = GetBit(dirp->bits, BitOfIsRep(dirp->loc));
1552
1544
 
1553
1545
        //
1554
1546
        // Now set up for the next call to readdir