touch function that should also work on non unix os's, though I cant test here.

This commit is contained in:
Campbell Barton
2008-01-20 21:27:16 +00:00
parent c11fce1a9f
commit 88561ed669
2 changed files with 18 additions and 18 deletions

View File

@@ -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 */

View File

@@ -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);