make it compile on linux too

svn path=/trunk/; revision=4025
This commit is contained in:
guido 2003-01-17 19:06:15 +00:00
parent e5057ddea7
commit d0d1b840ca

View file

@ -1,68 +1,81 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef WIN32
#include <sys/utime.h> #include <sys/utime.h>
#else
#include <sys/time.h>
#include <stdlib.h>
#endif
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
char* convert_path(char* origpath) char* convert_path(char* origpath)
{ {
char* newpath; char* newpath;
int i; int i;
newpath = (char *)strdup(origpath); newpath = (char *)strdup(origpath);
i = 0; i = 0;
while (newpath[i] != 0) while (newpath[i] != 0)
{ {
#ifdef UNIX_PATHS #ifdef UNIX_PATHS
if (newpath[i] == '\\') if (newpath[i] == '\\')
{ {
newpath[i] = '/'; newpath[i] = '/';
} }
#else #else
#ifdef DOS_PATHS #ifdef DOS_PATHS
if (newpath[i] == '/') if (newpath[i] == '/')
{ {
newpath[i] = '\\'; newpath[i] = '\\';
} }
#endif #endif
#endif #endif
i++; i++;
} }
return(newpath); return(newpath);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
char* path; char* path;
FILE* file; FILE* file;
time_t now; #ifdef WIN32
struct utimbuf fnow; time_t now;
struct utimbuf fnow;
#endif
if (argc != 2) if (argc != 2)
{ {
fprintf(stderr, "Wrong number of arguments.\n"); fprintf(stderr, "Wrong number of arguments.\n");
exit(1); exit(1);
} }
path = convert_path(argv[1]); path = convert_path(argv[1]);
file = (FILE *)open(path, S_IWRITE); file = (FILE *)open(path, S_IWRITE);
if (file == (void*)-1) if (file == (void*)-1)
{ {
file = (FILE *)open(path, S_IWRITE | O_CREAT); file = (FILE *)open(path, S_IWRITE | O_CREAT);
if (file == (void*)-1) if (file == (void*)-1)
{ {
fprintf(stderr, "Cannot create file.\n"); fprintf(stderr, "Cannot create file.\n");
exit(1); exit(1);
} }
} }
close(file); close(file);
now = time(); #ifdef WIN32
fnow.actime = now; now = time();
fnow.modtime = now; fnow.actime = now;
(int) utime(path, &fnow); fnow.modtime = now;
(int) utime(path, &fnow);
#else
(int) utimes(path, NULL);
#endif
exit(0); exit(0);
} }