diff options
| author | mingodad <mingodad@gmail.com> | 2013-01-11 00:04:38 +0000 |
|---|---|---|
| committer | mingodad <mingodad@gmail.com> | 2013-01-11 00:04:38 +0000 |
| commit | 59e18aee0e509a3ca75dbe6f909e18c1d17893d1 (patch) | |
| tree | 1ee20b231505273a1b1ba678b67c6c9e5812a414 /tccpp.c | |
| parent | 0a8c7d143eb0dcae15db9b61feb7b93228645d5f (diff) | |
| download | tinycc-59e18aee0e509a3ca75dbe6f909e18c1d17893d1.tar.gz tinycc-59e18aee0e509a3ca75dbe6f909e18c1d17893d1.tar.bz2 | |
Added what I call virtual io to tinycc this way we can make a monolitic executable or library that contains all needed to compile programs, truly tinycc portable.
Tested under linux exec the "mk-it" shell script and you'll end up with a portable tinycc executable that doesn't depend on anything else.
Diffstat (limited to 'tccpp.c')
| -rw-r--r-- | tccpp.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -360,13 +360,13 @@ static int tcc_peekc_slow(BufferedFile *bf) int len; /* only tries to read if really end of buffer */ if (bf->buf_ptr >= bf->buf_end) { - if (bf->fd != -1) { + if (bf->fd.fd != -1) { #if defined(PARSE_DEBUG) len = 8; #else len = IO_BUF_SIZE; #endif - len = read(bf->fd, bf->buffer, len); + len = vio_read(bf->fd, bf->buffer, len); if (len < 0) len = 0; } else { @@ -1438,6 +1438,8 @@ ST_FUNC void preprocess(int is_bof) CachedInclude *e; BufferedFile **f; const char *path; + int size; + vio_fd fd; if (i == -2) { /* check absolute include path */ @@ -1450,8 +1452,9 @@ ST_FUNC void preprocess(int is_bof) /* search in current dir if "header.h" */ if (c != '\"') continue; - path = file->filename; - pstrncpy(buf1, path, tcc_basename(path) - path); + size = tcc_basename(file->filename) - file->filename; + memcpy(buf1, file->filename, size); + buf1[size] = '\0'; } else { /* search in all the include paths */ @@ -1481,10 +1484,13 @@ ST_FUNC void preprocess(int is_bof) #ifdef INC_DEBUG printf("%s: skipping cached %s\n", file->filename, buf1); #endif + vio_initialize(&fd); + fd.fd = 0; goto include_done; } - if (tcc_open(s1, buf1) < 0) + fd = tcc_open(s1, buf1); + if (fd.fd < 0) include_trynext: continue; |
