diff options
author | dos-reis <gdr@axiomatics.org> | 2008-09-25 04:59:08 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2008-09-25 04:59:08 +0000 |
commit | e0c8f3d8155dabb7d7d54e426f56febfab77ee92 (patch) | |
tree | 4240cc0b9ec9eb01a4bf3e067a13cc74d6c7d403 /src/lib | |
parent | e2b728ff9a53eb2ff4518ad10beb649b5e636f74 (diff) | |
download | open-axiom-e0c8f3d8155dabb7d7d54e426f56febfab77ee92.tar.gz |
* include/cfuns.h (oa_copy_file): Declare.
* lib/cfuns-c.c (oa_chdir): Define.
(oa_dirname): Fix typo.
* hyper/htadd.c (copy_file): Remove.
(build_db_filename): Tidy.
(delete_file): Use oa_copy_file.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.in | 2 | ||||
-rw-r--r-- | src/lib/cfuns-c.c | 32 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 7ce00fad..fd84b82c 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -100,7 +100,7 @@ libspad.$(LIBEXT): $(libspad_objects) .PRECIOUS: %.$(OBJEXT) %.$(OBJEXT) %.lo: %.c $(axiom_c_macros_h) - $(COMPILE) $(oa_shrobj_flags) -no-suppress -o $@ $(CCF) \ + $(COMPILE) $(oa_shrobj_flags) -no-suppress -o $@ $(CCF) -g \ $(axiom_includes) $(AXIOM_X11_CFLAGS) $< # This is a support library, so it does not change often and diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c index 47a1f8c4..fc2a7e14 100644 --- a/src/lib/cfuns-c.c +++ b/src/lib/cfuns-c.c @@ -39,18 +39,19 @@ #include <errno.h> #include <sys/types.h> #include <sys/stat.h> -#include <unistd.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <assert.h> #include <math.h> +#include <unistd.h> #ifdef __WIN32__ # include <windows.h> #else # include <dirent.h> +# include <fcntl.h> #endif #include "cfuns.h" @@ -115,7 +116,7 @@ OPENAXIOM_EXPORT char* oa_dirname(const char* path) { const int n = strlen(path); - char* mark = mark + n; + char* mark = path + n; if (n == 0) return strdup("."); @@ -608,6 +609,33 @@ oa_get_tmpdir(void) } +OPENAXIOM_EXPORT int +oa_copy_file(const char* src, const char* dst) +{ +#ifdef __WIN32__ + return CopyFile(src,dst, /* bFailIfExists = */ 0) ? 0 : -1; +#else +#define OA_BUFSZ 512 + char buf[OA_BUFSZ]; + int src_fd; + int dst_fd; + int count; + if((src_fd = open(src, O_RDONLY)) < 0) + return -1; + if ((dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC)) < 0) { + close(src_fd); + return -1; + } + + while ((count = read(src_fd, buf, OA_BUFSZ)) > 0) + if (write(dst_fd, buf, count) != count) + break; + +#undef OA_BUFSZ + return (close(dst_fd) < 0 || close(src_fd) < 0 || count < 0) ? -1 : 0; +#endif +} + OPENAXIOM_EXPORT double plus_infinity(void ) |