diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | compat-cygwin.c | 7 | ||||
| -rw-r--r-- | compat-linux.c | 1 | ||||
| -rw-r--r-- | compat-mingw.c | 26 | ||||
| -rw-r--r-- | compat-solaris.c | 2 | ||||
| -rw-r--r-- | compat.h | 3 | ||||
| -rw-r--r-- | compat/id-files-stat.c | 7 | ||||
| -rw-r--r-- | lib.c | 1 | ||||
| -rw-r--r-- | pre-process.c | 19 | ||||
| -rw-r--r-- | token.h | 2 | ||||
| -rw-r--r-- | tokenize.c | 16 |
11 files changed, 23 insertions, 65 deletions
@@ -99,9 +99,9 @@ obfuscate.o: $(LIB_H) example.o: $(LIB_H) storage.o: $(LIB_H) storage.h -compat-linux.o: compat/strtold.c compat/id-files-stat.c compat/mmap-blob.c \ +compat-linux.o: compat/strtold.c compat/mmap-blob.c \ $(LIB_H) -compat-solaris.o: compat/id-files-stat.c compat/mmap-blob.c $(LIB_H) +compat-solaris.o: compat/mmap-blob.c $(LIB_H) compat-mingw.o: $(LIB_H) compat-cygwin.o: $(LIB_H) diff --git a/compat-cygwin.c b/compat-cygwin.c index 7545703d..e65b538a 100644 --- a/compat-cygwin.c +++ b/compat-cygwin.c @@ -37,9 +37,4 @@ void blob_free(void *addr, unsigned long size) long double string_to_ld(const char *nptr, char **endptr) { return strtod(nptr, endptr); -} - -int identical_files(struct stream* s, struct stat *st, const char * name) -{ - return (s->dev == st->st_dev && s->ino == st->st_ino); -} +} diff --git a/compat-linux.c b/compat-linux.c index da24ab83..a7a61406 100644 --- a/compat-linux.c +++ b/compat-linux.c @@ -3,6 +3,5 @@ #include "lib.h" #include "allocate.h" -#include "compat/id-files-stat.c" #include "compat/mmap-blob.c" #include "compat/strtold.c" diff --git a/compat-mingw.c b/compat-mingw.c index 66456c72..21ca51a7 100644 --- a/compat-mingw.c +++ b/compat-mingw.c @@ -34,28 +34,4 @@ void blob_free(void *addr, unsigned long size) long double string_to_ld(const char *nptr, char **endptr) { return strtod(nptr, endptr); -} - -int identical_files(struct stream* s, struct stat *st, const char * name) -{ - HANDLE file1 =CreateFile(s->name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); - if(file1==INVALID_HANDLE_VALUE) - return 0; - HANDLE file2=CreateFile(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); - if(file2==INVALID_HANDLE_VALUE) { - CloseHandle(file1); - return 0; - } - BY_HANDLE_FILE_INFORMATION info1; - BY_HANDLE_FILE_INFORMATION info2; - int same=0; - if(GetFileInformationByHandle(file1,&info1) && GetFileInformationByHandle(file2,&info2)){ - if(info1.nFileIndexLow==info2.nFileIndexLow && - info1.nFileIndexHigh==info2.nFileIndexHigh && - info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber) - same=1; - } - CloseHandle(file1); - CloseHandle(file2); - return same; -} +} diff --git a/compat-solaris.c b/compat-solaris.c index 62a7714b..7253a892 100644 --- a/compat-solaris.c +++ b/compat-solaris.c @@ -1,10 +1,8 @@ #include "lib.h" #include "allocate.h" -#include "compat/id-files-stat.c" #include "compat/mmap-blob.c" - #include <floatingpoint.h> #include <limits.h> #include <errno.h> @@ -9,8 +9,6 @@ * Missing in mingw * - "string to long double" (C99 strtold()) * Missing in Solaris and mingw - * - checking for file identity (POSIX st_dev && st_ino comparison) - * mingw needs to check the name (st_dev/st_ino are zero) */ struct stream; struct stat; @@ -26,6 +24,5 @@ struct stat; void *blob_alloc(unsigned long size); void blob_free(void *addr, unsigned long size); long double string_to_ld(const char *nptr, char **endptr); -int identical_files(struct stream* s, struct stat *st, const char * name); #endif diff --git a/compat/id-files-stat.c b/compat/id-files-stat.c deleted file mode 100644 index 62f0f57e..00000000 --- a/compat/id-files-stat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "../token.h" -#include <sys/stat.h> - -int identical_files(struct stream* s, struct stat *st, const char * name) -{ - return s->dev == st->st_dev && s->ino == st->st_ino; -} @@ -17,7 +17,6 @@ #include <assert.h> #include <sys/types.h> -#include <sys/stat.h> #include "lib.h" #include "allocate.h" diff --git a/pre-process.c b/pre-process.c index 950aea37..0a24f56e 100644 --- a/pre-process.c +++ b/pre-process.c @@ -596,6 +596,23 @@ static const char *token_name_sequence(struct token *token, int endop, struct to return buffer; } +static int already_tokenized(const char *path) +{ + int i; + struct stream *s = input_streams; + + for (i = input_stream_nr-1; i >= 0; i--, s++) { + if (s->constant != CONSTANT_FILE_YES) + continue; + if (strcmp(path, s->name)) + continue; + if (!lookup_symbol(s->protect, NS_MACRO)) + continue; + return 1; + } + return 0; +} + static int try_include(const char *path, int plen, const char *filename, int flen, struct token **where, const char **next_path) { int fd; @@ -607,6 +624,8 @@ static int try_include(const char *path, int plen, const char *filename, int fle plen++; } memcpy(fullname+plen, filename, flen); + if (already_tokenized(fullname)) + return 1; fd = open(fullname, O_RDONLY); if (fd >= 0) { char * streamname = __alloc_bytes(plen + flen); @@ -41,8 +41,6 @@ struct stream { enum constantfile constant; int nesting; struct ident *protect; - dev_t dev; - ino_t ino; }; extern int input_stream_nr; @@ -14,7 +14,6 @@ #include <string.h> #include <ctype.h> #include <unistd.h> -#include <sys/stat.h> #include "lib.h" #include "allocate.h" @@ -166,7 +165,6 @@ int init_stream(const char *name, int fd, const char **next_path) { int stream = input_stream_nr; struct stream *current; - struct stat st; if (stream >= input_streams_allocated) { int newalloc = stream * 4 / 3 + 10; @@ -181,20 +179,6 @@ int init_stream(const char *name, int fd, const char **next_path) current->fd = fd; current->next_path = next_path; current->constant = CONSTANT_FILE_MAYBE; - if (fd >= 0 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { - int i; - - for (i = 0; i < stream; i++) { - struct stream *s = input_streams + i; - if (s->constant == CONSTANT_FILE_YES && - identical_files(s, &st, name) && - lookup_symbol(s->protect, NS_MACRO)) - return -1; - } - - current->dev = st.st_dev; - current->ino = st.st_ino; - } input_stream_nr = stream+1; return stream; } |
