touch 修订:可以修改链接文件的时间

发表于:2007-06-09来源:作者:点击数: 标签:
在/usr/src目录下:patch touch.diff --- usr.bin/touch/touch.c.origSun Jul 28 14:52:15 2002 +++ usr.bin/touch/touch.cTue Mar 15 13:34:14 2005 @@ -133,22 +133,23 @@ for (rval = 0; *argv; ++argv) { /* See if the file exists. */ -if (stat(*argv,
在/usr/src目录下:patch < touch.diff


--- usr.bin/touch/touch.c.orig	Sun Jul 28 14:52:15 2002
+++ usr.bin/touch/touch.c Tue Mar 15 13:34:14 2005
@@ -133,22 +133,23 @@

for (rval = 0; *argv; ++argv) {
/* See if the file exists. */
- if (stat(*argv, &sb)) {
- if (!cflag) {
- /* Create the file. */
- fd = open(*argv,
- O_WRONLY | O_CREAT, DEFFILEMODE);
- if (fd == -1 || fstat(fd, &sb) || close(fd)) {
- rval = 1;
- warn("%s", *argv);
- continue;
- }
+ if (lstat(*argv, &sb))
+ if (stat(*argv, &sb)) {
+ if (!cflag) {
+ /* Create the file. */
+ fd = open(*argv,
+ O_WRONLY | O_CREAT, DEFFILEMODE);
+ if (fd == -1 || fstat(fd, &sb) || close(fd)) {
+ rval = 1;
+ warn("%s", *argv);
+ continue;
+ }

- /* If using the current time, we're done. */
- if (!timeset)
+ /* If using the current time, we're done. */
+ if (!timeset)
+ continue;
+ } else
continue;
- } else
- continue;
}

if (!aflag)
@@ -157,15 +158,20 @@
TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);

/* Try utimes(2). */
+ if (S_ISLNK(sb.st_mode))
+ {
+ if (!lutimes(*argv, tv))
+ continue;
+ }
+
if (!utimes(*argv, tv))
- continue;
-
+ continue;
+
/* If the user specified a time, nothing else we can do. */
if (timeset) {
rval = 1;
warn("%s", *argv);
}
-
/*
* System V and POSIX 1003.1 require that a NULL argument
* set the aclearcase/" target="_blank" >ccess/modification times to the current time.




原文转自:http://www.ltesting.net