History

win: fix dir comparison during include dirs processing

Use native Windows API via wrapper with stat-like API.

Avi Halachmi (:avih) committed 11 years ago

Commit acbab221 parent 9d333881 file · +60 −16Browse files

Unified · Split

libtcc.c+60−16
@@ -1510,6 +1510,50 @@ LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val) · 1509 unmodified lines
15101510 }
15111511
15121512
1513+#ifndef _WIN32
1514+typedef struct stat file_info_t;
1515+#else
1516+typedef BY_HANDLE_FILE_INFORMATION file_info_t;
1517+#endif
1518+
1519+int get_file_info(const char *fname, file_info_t *out_info)
1520+{
1521+#ifndef _WIN32
1522+ return stat(fname, out_info);
1523+#else
1524+ int rv = 1;
1525+ HANDLE h = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1526+ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, NULL);
1527+ if (h == INVALID_HANDLE_VALUE)
1528+ return rv;
1529+
1530+ rv = !GetFileInformationByHandle(h, out_info);
1531+ CloseHandle(h);
1532+ return rv;
1533+#endif
1534+}
1535+
1536+int is_dir(file_info_t *info)
1537+{
1538+#ifndef _WIN32
1539+ return S_ISDIR(info->st_mode);
1540+#else
1541+ return info->dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
1542+#endif
1543+}
1544+
1545+int is_same_file(const file_info_t *fi1, const file_info_t *fi2)
1546+{
1547+#ifndef _WIN32
1548+ return fi1->st_dev == fi2->st_dev &&
1549+ fi1->st_ino == fi2->st_ino;
1550+#else
1551+ return fi1->dwVolumeSerialNumber == fi2->dwVolumeSerialNumber &&
1552+ fi1->nFileIndexHigh == fi2->nFileIndexHigh &&
1553+ fi1->nFileIndexLow == fi2->nFileIndexLow;
1554+#endif
1555+}
1556+
15131557 ST_FUNC void tcc_mormalize_inc_dirs(TCCState *s)
15141558 {
15151559 /* check a preprocessor include dirs and remove not
@@ -1517,8 +1561,8 @@ ST_FUNC void tcc_mormalize_inc_dirs(TCCState *s) · 1 unmodified line
15171561 - for each duplicate path keep just the first one
15181562 - remove each include_path that exists in sysinclude_paths
15191563 */
1520− struct stat sysinc_stats[50]; // we don't use VLA in tcc code
1521− struct stat inc_stats[50];
1564+ file_info_t sysinc_stats[50]; // we don't use VLA in tcc code
1565+ file_info_t inc_stats[50];
15221566 int num_sysinc = s->nb_sysinclude_paths;
15231567 int num_inc = s->nb_include_paths;
15241568 char** pp;
@@ -1532,28 +1576,28 @@ ST_FUNC void tcc_mormalize_inc_dirs(TCCState *s) · 7 unmodified lines
15321576
15331577 pp = s->sysinclude_paths;
15341578 for (i=0; i < num_sysinc; i++) {
1535− struct stat *st = &sysinc_stats [i];
1536− r = stat( pp [i], st);
1537− if (r || !S_ISDIR(st->st_mode)) {
1579+ file_info_t *st = &sysinc_stats [i];
1580+ r = get_file_info( pp [i], st);
1581+ if (r || !is_dir(st)) {
15381582 tcc_free( pp[i] );
15391583 pp[i] = 0;
15401584 }
15411585 }
15421586 pp = s->include_paths;
15431587 for (i=0; i < num_inc; i++) {
1544− struct stat *st = &inc_stats [i];
1545− r = stat( pp [i], st);
1546− if (r || !S_ISDIR(st->st_mode)) {
1588+ file_info_t *st = &inc_stats [i];
1589+ r = get_file_info( pp [i], st);
1590+ if (r || !is_dir(st)) {
15471591 tcc_free( pp[i] );
15481592 pp[i] = 0;
15491593 }
15501594 }
15511595
15521596 for (i=0; i < num_inc; i++) {
1553− struct stat *st1 = &inc_stats [i];
1597+ file_info_t *st1 = &inc_stats [i];
15541598 for (j=i+1; j < num_inc; j++) {
1555− struct stat *st2 = &inc_stats [j];
1556− if ((st1->st_dev == st2->st_dev) && (st1->st_ino == st2->st_ino)) {
1599+ file_info_t *st2 = &inc_stats [j];
1600+ if (is_same_file(st1, st2)) {
15571601 pp = &s->include_paths[j];
15581602 if (*pp) {
15591603 tcc_free( *pp );
@@ -1562,8 +1606,8 @@ ST_FUNC void tcc_mormalize_inc_dirs(TCCState *s) · 2 unmodified lines
15621606 }
15631607 }
15641608 for (j=0; i < num_sysinc; i++) {
1565− struct stat *st2 = &sysinc_stats [j];
1566− if ((st1->st_dev == st2->st_dev) && (st1->st_ino == st2->st_ino)) {
1609+ file_info_t *st2 = &sysinc_stats [j];
1610+ if (is_same_file(st1, st2)) {
15671611 pp = &s->include_paths[i];
15681612 if (*pp) {
15691613 tcc_free( *pp );
@@ -1573,10 +1617,10 @@ ST_FUNC void tcc_mormalize_inc_dirs(TCCState *s) · 3 unmodified lines
15731617 }
15741618 }
15751619 for (i=0; i < num_sysinc; i++) {
1576− struct stat *st1 = &sysinc_stats [i];
1620+ file_info_t *st1 = &sysinc_stats [i];
15771621 for (j=i+1; j < num_sysinc; j++) {
1578− struct stat *st2 = &sysinc_stats [j];
1579− if ((st1->st_dev == st2->st_dev) && (st1->st_ino == st2->st_ino)) {
1622+ file_info_t *st2 = &sysinc_stats [j];
1623+ if (is_same_file(st1, st2)) {
15801624 pp = &s->sysinclude_paths[j];
15811625 if (*pp) {
15821626 tcc_free( *pp );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t