beginning of local stub makefiles, to allow building from subdirectories ( I'm explic...
[reactos.git] / reactos / tools / rtouch.c
1 #include <sys/types.h>
2 #include <sys/stat.h>
3
4 #ifdef WIN32
5 #include <sys/utime.h>
6 #include <time.h>
7 #else
8 #include <sys/time.h>
9 #include <unistd.h>
10 #endif
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include <fcntl.h>
15 #include <stdio.h>
16
17 char* convert_path(char* origpath)
18 {
19 char* newpath;
20 int i;
21
22 //newpath = (char *)strdup(origpath);
23 newpath=malloc(strlen(origpath)+1);
24 strcpy(newpath,origpath);
25
26 i = 0;
27 while (newpath[i] != 0)
28 {
29 #ifdef UNIX_PATHS
30 if (newpath[i] == '\\')
31 {
32 newpath[i] = '/';
33 }
34 #else
35 #ifdef DOS_PATHS
36 if (newpath[i] == '/')
37 {
38 newpath[i] = '\\';
39 }
40 #endif
41 #endif
42 i++;
43 }
44 return(newpath);
45 }
46
47 int main(int argc, char* argv[])
48 {
49 char* path;
50 int id;
51 #ifdef WIN32
52 time_t now;
53 struct utimbuf fnow;
54 #endif
55
56 if (argc != 2)
57 {
58 fprintf(stderr, "Wrong number of arguments.\n");
59 exit(1);
60 }
61
62 path = convert_path(argv[1]);
63 id = open(path, S_IWRITE, S_IRUSR | S_IWUSR);
64 if (id < 0)
65 {
66 id = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
67 if (id < 0)
68 {
69 fprintf(stderr, "Cannot create file.\n");
70 exit(1);
71 }
72 }
73
74 close(id);
75
76 #ifdef WIN32
77 now = time(NULL);
78 fnow.actime = now;
79 fnow.modtime = now;
80 (int) utime(path, &fnow);
81 #else
82 (int) utimes(path, NULL);
83 #endif
84
85 exit(0);
86 }