#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/utime.h>
#include <io.h>
#include <fcntl.h>
#include <getopt.h>
#include <various.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Go to the source code of this file.
|
int rw | __P ((char *, struct stat *, int)) |
|
void stime_arg1 | __P ((char *, time_t *)) |
|
void stime_arg2 | __P ((char *, int, time_t *)) |
|
void usage | __P ((void)) |
|
int | main (int argc, char *argv[]) |
|
void | stime_arg1 (char *arg, time_t *tvp) |
|
void | stime_arg2 (char *arg, int year, time_t *tvp) |
|
void | stime_file (char *fname, time_t *tvp) |
|
int | rw (char *fname, struct stat *sbp, int force) |
|
void | usage () |
|
◆ ATOI2
#define ATOI2 |
( |
|
ar | ) |
((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; |
◆ DEFFILEMODE
◆ __P() [1/4]
◆ __P() [2/4]
◆ __P() [3/4]
◆ __P() [4/4]
◆ main()
Definition at line 78 of file touch.c.
79{
85
87
88 aflag = cflag = fflag =
mflag = timeset = 0;
90
92 switch(ch) {
93 case 'a':
94 aflag = 1;
95 break;
96 case 'c':
97 cflag = 1;
98 break;
99 case 'f':
100 fflag = 1;
101 break;
102 case 'm':
104 break;
105 case 'r':
106 timeset = 1;
108 break;
109 case 't':
110 timeset = 1;
112 break;
113 case '?':
114 default:
116 }
119
120
121 if (aflag == 0 &&
mflag == 0)
123
124
125
126
127
128 if (!timeset &&
argc > 1) {
131 if (*
p ==
'\0' && (
len == 8 ||
len == 10)) {
132 timeset = 1;
134 }
135 }
136
137
138 if (!timeset)
139 tv[1] = tv[0];
140
143
145
147 if (!cflag) {
148
154 continue;
155 }
156
157
158 if (!timeset)
159 continue;
160 } else
161 continue;
162 }
163
164 if (!aflag)
168
169
170 utb.actime = tv[0];
171 utb.modtime = tv[1];
173 continue;
174
175
176 if (timeset) {
179 }
180
181
182
183
184
185
186
188 continue;
189
190
193 }
195}
int getopt(int nargc, char *const *nargv, const char *ostr)
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
_CRTIMP int __cdecl _open(const char *_Filename, int _OpenFlag,...)
void stime_arg1(char *arg, time_t *tvp)
void stime_file(char *fname, time_t *tvp)
void stime_arg2(char *arg, int year, time_t *tvp)
◆ rw()
Definition at line 291 of file touch.c.
292{
293 int fd, needed_chmod,
rval;
295
296
299 return (1);
300 }
301
302 needed_chmod =
rval = 0;
308 needed_chmod = 1;
309 }
310
312 if (
_read(
fd, &
byte,
sizeof(
byte)) !=
sizeof(
byte))
316 if (
_write(
fd, &
byte,
sizeof(
byte)) !=
sizeof(
byte))
318 } else {
319 if (
_write(
fd, &
byte,
sizeof(
byte)) !=
sizeof(
byte)) {
322
325 warn(
"%s: file modified", fname);
326 }
327 }
328
332 }
335 warn(
"%s: permissions modified", fname);
336 }
338}
const char * strerror(int err)
_Check_return_opt_ _CRTIMP long __cdecl _lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin)
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)
_CRTIMP int __cdecl _write(_In_ int _FileHandle, _In_reads_bytes_(_MaxCharCount) const void *_Buf, _In_ unsigned int _MaxCharCount)
_Check_return_ _CRTIMP int __cdecl _read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
_Check_return_ _CRTIMP int __cdecl _chsize(_In_ int _FileHandle, _In_ long _Size)
◆ stime_arg1()
Definition at line 200 of file touch.c.
201{
203 int yearset;
205
208
211 else {
213 goto terr;
216 }
217
218 yearset = 0;
220 case 12:
223 yearset = 1;
224
225 case 10:
226 if (yearset) {
228 t->tm_year += yearset;
229 } else {
231 if (yearset < 69)
232 t->tm_year = yearset + 2000;
233 else
234 t->tm_year = yearset + 1900;
235 }
237
238 case 8:
244 break;
245 default:
246 goto terr;
247 }
248
251 if (tvp[0] == -1)
253 "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]");
254}
ACPI_SIZE strlen(const char *String)
char * strchr(const char *String, int ch)
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Referenced by main().
◆ stime_arg2()
Definition at line 257 of file touch.c.
258{
260
263
269 if (year)
271
274 if (tvp[0] == -1)
276 "out of range or illegal time specification: MMDDhhmm[yy]");
277}
Referenced by main().
◆ stime_file()
Definition at line 280 of file touch.c.
281{
283
286 tvp[0] =
sb.st_atime;
287 tvp[1] =
sb.st_mtime;
288}
Referenced by main().
◆ usage()
Definition at line 342 of file touch.c.
343{
345 "usage: touch [-acfm] [-r file] [-t time] file ...\n");
347}
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
Referenced by main().
◆ __progname
◆ copyright
Initial value:=
"@(#) Copyright (c) 1993 Regents of the University of California.\n\
All rights reserved.\n"
Definition at line 40 of file touch.c.