aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrischka <grischka>2009-07-18 22:07:33 +0200
committergrischka <grischka>2009-07-18 22:07:33 +0200
commit94ae3984b0d4d3d78975d3bd48810cd5b6381618 (patch)
treef00293d6b3ed90f816e3c474ae2d08fa4bae1a7e
parent1df662c1b094d250db0501cf31db83dc5f9060e4 (diff)
downloadtinycc-94ae3984b0d4d3d78975d3bd48810cd5b6381618.tar.gz
tinycc-94ae3984b0d4d3d78975d3bd48810cd5b6381618.tar.bz2
tccpe: set tcc_lib_path from DLL
-rw-r--r--libtcc.c35
-rw-r--r--tcc.c4
-rw-r--r--tcc.h2
-rw-r--r--tccpe.c2
4 files changed, 10 insertions, 33 deletions
diff --git a/libtcc.c b/libtcc.c
index 3494ee2..c25fb2c 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -509,32 +509,6 @@ char *tcc_fileextension (const char *name)
return e ? e : strchr(b, 0);
}
-#ifdef _WIN32
-char *normalize_slashes(char *path)
-{
- char *p;
- for (p = path; *p; ++p)
- if (*p == '\\')
- *p = '/';
- return path;
-}
-
-void tcc_set_lib_path_w32(TCCState *s)
-{
- /* on win32, we suppose the lib and includes are at the location
- of 'tcc.exe' */
- char path[1024], *p;
- GetModuleFileNameA(NULL, path, sizeof path);
- p = tcc_basename(normalize_slashes(strlwr(path)));
- if (p - 5 > path && 0 == strncmp(p - 5, "/bin/", 5))
- p -= 5;
- else if (p > path)
- p--;
- *p = 0;
- tcc_set_lib_path(s, path);
-}
-#endif
-
void set_pages_executable(void *ptr, unsigned long length)
{
#ifdef _WIN32
@@ -1867,9 +1841,12 @@ TCCState *tcc_new(void)
if (!s)
return NULL;
tcc_state = s;
+#ifdef _WIN32
+ tcc_set_lib_path_w32(s);
+#else
+ tcc_set_lib_path(s, CONFIG_TCCDIR);
+#endif
s->output_type = TCC_OUTPUT_MEMORY;
- s->tcc_lib_path = CONFIG_TCCDIR;
-
preprocess_new();
/* we add dummy defines for some special macros to speed up tests
@@ -1993,6 +1970,7 @@ void tcc_delete(TCCState *s1)
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
+ tcc_free(s1->tcc_lib_path);
tcc_free(s1);
}
@@ -2348,6 +2326,7 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
/* set CONFIG_TCCDIR at runtime */
void tcc_set_lib_path(TCCState *s, const char *path)
{
+ tcc_free(s->tcc_lib_path);
s->tcc_lib_path = tcc_strdup(path);
}
diff --git a/tcc.c b/tcc.c
index daa1013..cadb5e9 100644
--- a/tcc.c
+++ b/tcc.c
@@ -427,9 +427,7 @@ int main(int argc, char **argv)
int64_t start_time = 0;
s = tcc_new();
-#ifdef _WIN32
- tcc_set_lib_path_w32(s);
-#endif
+
output_type = TCC_OUTPUT_EXE;
outfile = NULL;
multiple_files = 1;
diff --git a/tcc.h b/tcc.h
index 50bbd56..bf242e5 100644
--- a/tcc.h
+++ b/tcc.h
@@ -473,7 +473,7 @@ struct TCCState {
/* compile with built-in memory and bounds checker */
int do_bounds_check;
/* give the path of the tcc libraries */
- const char *tcc_lib_path;
+ char *tcc_lib_path;
/* error handling */
void *error_opaque;
diff --git a/tccpe.c b/tccpe.c
index fe87919..652ab06 100644
--- a/tccpe.c
+++ b/tccpe.c
@@ -1511,7 +1511,7 @@ PUB_FN int pe_load_file(struct TCCState *s1, const char *filename, int fd)
else if (pe_load_res(s1, fp) == 0)
ret = 0;
else if (read_mem(fp, 0, buf, sizeof buf) && 0 == strncmp(buf, "MZ", 2))
- ret = pe_load_dll(s1, filename, fp);
+ ret = pe_load_dll(s1, tcc_basename(filename), fp);
fclose(fp);
}
return ret;