From 88561ed669da880561ca323db52f9370287475c2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 20 Jan 2008 21:27:16 +0000 Subject: touch function that should also work on non unix os's, though I cant test here. --- source/blender/blenlib/BLI_blenlib.h | 2 +- source/blender/blenlib/intern/fileops.c | 34 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 42b3bf2ce14..e149c92c72b 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -296,7 +296,7 @@ int BLI_rename(char *from, char *to); int BLI_gzip(char *from, char *to); int BLI_delete(char *file, int dir, int recursive); int BLI_move(char *file, char *to); -int BLI_touch(char *file); +int BLI_touch(const char *file); char *BLI_last_slash(const char *string); /* BLI_rct.c */ diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index fe2d07238b6..2ee42d16176 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -140,6 +140,23 @@ int BLI_is_writable(char *filename) } } +int BLI_touch(const char *file) +{ + FILE *f = fopen(file,"r+b"); + if (f != NULL) { + char c = getc(f); + rewind(f); + putc(c,f); + } else { + f = fopen(file,"wb"); + } + if (f) { + fclose(f); + return 1; + } + return 0; +} + #ifdef WIN32 static char str[MAXPATHLEN+12]; @@ -161,12 +178,6 @@ int BLI_delete(char *file, int dir, int recursive) { return err; } -int BLI_touch(char *file) { - callLocalErrorCallBack("Touching files is unsupported on Windows"); - - return 1; -} - int BLI_move(char *file, char *to) { int err; @@ -296,17 +307,6 @@ int BLI_delete(char *file, int dir, int recursive) return -1; } -int BLI_touch(char *file) -{ - - if( BLI_exists("/bin/touch") ) - sprintf(str, "/bin/touch %s", file); - else - sprintf(str, "/usr/bin/touch %s", file); - - return system(str); -} - int BLI_move(char *file, char *to) { sprintf(str, "/bin/mv -f \"%s\" \"%s\"", file, to); -- cgit v1.2.3