touch: posix open
This commit is contained in:
parent
8ec404cdec
commit
444de72fd3
3
kill.1
3
kill.1
@ -25,4 +25,5 @@ lists available signals. If a
|
|||||||
.I signum
|
.I signum
|
||||||
is given, only the corresponding signal name will be printed.
|
is given, only the corresponding signal name will be printed.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.IR kill (2)
|
.IR kill (2),
|
||||||
|
.IR signal (7)
|
||||||
|
27
touch.c
27
touch.c
@ -43,17 +43,20 @@ touch(const char *str)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
struct utimbuf ut;
|
struct utimbuf ut;
|
||||||
|
|
||||||
if(stat(str, &st) == -1) {
|
if(stat(str, &st) == 0) {
|
||||||
if(errno != ENOENT)
|
ut.actime = st.st_atime;
|
||||||
eprintf("stat %s:", str);
|
ut.modtime = t;
|
||||||
if(cflag)
|
if(utime(str, &ut) == -1)
|
||||||
return;
|
eprintf("utime %s:", str);
|
||||||
if((fd = creat(str, O_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
|
return;
|
||||||
eprintf("creat %s:", str);
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
ut.actime = st.st_atime;
|
else if(errno != ENOENT)
|
||||||
ut.modtime = t;
|
eprintf("stat %s:", str);
|
||||||
if(utime(str, &ut) == -1)
|
else if(cflag)
|
||||||
eprintf("utime %s:", str);
|
return;
|
||||||
|
if((fd = open(str, O_CREAT|O_EXCL,
|
||||||
|
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == -1)
|
||||||
|
eprintf("open %s:", str);
|
||||||
|
close(fd);
|
||||||
|
touch(str);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user