From bf234723494dfd847bf7b030f2227c7bbd99b36b Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Thu, 18 Oct 2018 16:02:47 +0100 Subject: [PATCH] Don't #undef stat and #define stat(). stat is one of those unfortunate identifiers for which there is both a struct and a function. MinGW uses a #define for setting struct stat to be the right struct, so doing #undef stat to clear the way for a #define for stat() the function inadvertantly clobbers the selected stat struct. To avoid this, we define la_stat() to _la_stat on Windows and stat() elsewhere, and then use la_stat() instead of stat(). --- libarchive/archive_match.c | 2 +- libarchive/archive_platform.h | 2 ++ libarchive/archive_read_disk_entry_from_file.c | 2 +- libarchive/archive_read_disk_posix.c | 2 +- libarchive/archive_util.c | 2 +- libarchive/archive_windows.h | 5 +---- libarchive/archive_write_disk_posix.c | 10 +++++----- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/libarchive/archive_match.c b/libarchive/archive_match.c index f150e8224..027d9715d 100644 --- a/libarchive/archive_match.c +++ b/libarchive/archive_match.c @@ -1232,7 +1232,7 @@ set_timefilter_pathname_mbs(struct archive_match *a, int timetype, archive_set_error(&(a->archive), EINVAL, "pathname is empty"); return (ARCHIVE_FAILED); } - if (stat(path, &st) != 0) { + if (la_stat(path, &st) != 0) { archive_set_error(&(a->archive), errno, "Failed to stat()"); return (ARCHIVE_FAILED); } diff --git a/libarchive/archive_platform.h b/libarchive/archive_platform.h index 32b884c96..b8bcb52bc 100644 --- a/libarchive/archive_platform.h +++ b/libarchive/archive_platform.h @@ -69,6 +69,8 @@ * either Windows or Posix APIs. */ #if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) #include "archive_windows.h" +#else +#define la_stat(path,stref) stat(path,stref) #endif /* diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c index 1786cff38..90d10bee9 100644 --- a/libarchive/archive_read_disk_entry_from_file.c +++ b/libarchive/archive_read_disk_entry_from_file.c @@ -188,7 +188,7 @@ archive_read_disk_entry_from_file(struct archive *_a, } } else #endif - if (stat(path, &s) != 0) { + if (la_stat(path, &s) != 0) { archive_set_error(&a->archive, errno, "Can't stat %s", path); return (ARCHIVE_FAILED); diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index cdf754123..75aa54c71 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -2450,7 +2450,7 @@ tree_current_stat(struct tree *t) #else if (tree_enter_working_dir(t) != 0) return NULL; - if (stat(tree_current_access_path(t), &t->st) != 0) + if (la_stat(tree_current_access_path(t), &t->st) != 0) #endif return NULL; t->flags |= hasStat; diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index 96d61456d..3399c0b5f 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -449,7 +449,7 @@ __archive_mktemp(const char *tmpdir) temp_name.s[temp_name.length-1] = '\0'; temp_name.length --; } - if (stat(temp_name.s, &st) < 0) + if (la_stat(temp_name.s, &st) < 0) goto exit_tmpfile; if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; diff --git a/libarchive/archive_windows.h b/libarchive/archive_windows.h index e77cd08fc..87d8c891b 100644 --- a/libarchive/archive_windows.h +++ b/libarchive/archive_windows.h @@ -112,10 +112,7 @@ #if !defined(__BORLANDC__) && !defined(__WATCOMC__) #define setmode _setmode #endif -#ifdef stat -#undef stat -#endif -#define stat(path,stref) __la_stat(path,stref) +#define la_stat(path,stref) __la_stat(path,stref) #if !defined(__WATCOMC__) #if !defined(__BORLANDC__) #define strdup _strdup diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c index 3fd5f5798..7ae4becdd 100644 --- a/libarchive/archive_write_disk_posix.c +++ b/libarchive/archive_write_disk_posix.c @@ -2018,7 +2018,7 @@ restore_entry(struct archive_write_disk *a) * follow the symlink if we're creating a dir. */ if (S_ISDIR(a->mode)) - r = stat(a->name, &a->st); + r = la_stat(a->name, &a->st); /* * If it's not a dir (or it's a broken symlink), * then don't follow it. @@ -2184,7 +2184,7 @@ create_filesystem_object(struct archive_write_disk *a) #ifdef HAVE_LSTAT r = lstat(a->name, &st); #else - r = stat(a->name, &st); + r = la_stat(a->name, &st); #endif if (r != 0) r = errno; @@ -2687,7 +2687,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, * This is needed to extract hardlinks over * symlinks. */ - r = stat(head, &st); + r = la_stat(head, &st); if (r != 0) { tail[0] = c; if (errno == ENOENT) { @@ -3027,7 +3027,7 @@ create_dir(struct archive_write_disk *a, char *path) * here loses the ability to extract through symlinks. Also note * that this should not use the a->st cache. */ - if (stat(path, &st) == 0) { + if (la_stat(path, &st) == 0) { if (S_ISDIR(st.st_mode)) return (ARCHIVE_OK); if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { @@ -3085,7 +3085,7 @@ create_dir(struct archive_write_disk *a, char *path) * don't add it to the fixup list here, as it's already been * added. */ - if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) + if (la_stat(path, &st) == 0 && S_ISDIR(st.st_mode)) return (ARCHIVE_OK); archive_set_error(&a->archive, errno, "Failed to create dir '%s'", -- 2.47.2