diff options
author | dos-reis <gdr@axiomatics.org> | 2008-05-21 16:10:51 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2008-05-21 16:10:51 +0000 |
commit | ab4a8ba818d6fa8d237a55639c7361b376162f81 (patch) | |
tree | 168c9ad6a661034c16221bd7fcbc4ee9941c2489 /src/lib | |
parent | c145229d7f609447ec9342f60643c62e35bd553f (diff) | |
download | open-axiom-ab4a8ba818d6fa8d237a55639c7361b376162f81.tar.gz |
* include/cfuns.h (oa_get_tmpdir): Declare.
(oa_access_file_for_read): Likewise.
* lib/cfuns-c.c (oa_getcwd): Define.
(oa_access_file_for_read): Likewise.
(oa_get_tmpdir): Likewise.
* hyper/addfile.c: Don't include hyper.h
(build_ht_filename): Use oa_getcwd, oa_access_file_for_read.
(temp_file_open): Use oa_get_tmpdir.
* hyper/htadd.c (build_db_filename): Don't fall back to bogus
filename.
* hyper/hyper.h (temp_dir): Remove.
(def_spad): Likewise.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/cfuns-c.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c index 4a1e596f..bc6e10bd 100644 --- a/src/lib/cfuns-c.c +++ b/src/lib/cfuns-c.c @@ -466,3 +466,77 @@ oa_getenv(const char* var) return getenv(var); #endif } + + +OPENAXIOM_EXPORT char* +oa_getcwd(void) +{ + int bufsz = 256; + char* buf = (char*) malloc(bufsz); +#ifdef __MINGW32__ + int n = GetCurrentDirectory(bufsz, bufsz); + if (n == 0) { + perror("oa_getcwd"); + exit(-1); + } + else if (n > bufsz) { + buf = realloc(buf,n); + if (GetCurrentDirectory(n, buf) != n) { + perror("oa_getcwd"); + exit(-1); + } + } + return buf; +#else /* __MINGW32__ */ + errno = 0; + while (getcwd(buf,bufsz) == 0) { + if (errno == ERANGE) { + errno = 0; + bufsz *= 2; + buf = realloc(buf, bufsz); + } + else { + perror("oa_getcwd"); + exit(-1); + } + } + return buf; +#endif +} + +OPENAXIOM_EXPORT int +oa_access_file_for_read(const char* path) +{ +#ifdef __MINGW32__ + GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES ? -1 : 1; +#else + return access(path, R_OK); +#endif +} + + +OPENAXIOM_EXPORT const char* +oa_get_tmpdir(void) +{ +#ifdef __MINGW32__ + char* buf; + /* First, probe. */ + int bufsz = GetTempPath(0, NULL); + if (bufsz == 0) { + perror("oa_get_tmpdir"); + exit(-1); + } + else { + buf = (char*) malloc(bufsz + 1); + if(GetTempPath(bufsz, buf) != bufsz) { + perror("oa_get_tmpdir"); + free(buf); + exit(-1); + } + buf[bufsz] = '\0'; + } + return buf; +#else + return "/tmp"; +#endif +} |