#ifdef HAVE_PROCESS_H
# include <process.h> /* getpid() */
#endif
-#ifdef HAVE_UTIME_H
-# include <utime.h>
-#endif
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <stdarg.h>
#include <locale.h>
-#include <sys/time.h>
+#if HAVE_UTIME
+# include <sys/types.h>
+# ifdef HAVE_UTIME_H
+# include <utime.h>
+# endif
+
+# ifdef HAVE_SYS_UTIME_H
+# include <sys/utime.h>
+# endif
+#endif
+#include <sys/stat.h>
/* For TIOCGWINSZ and friends: */
#ifdef HAVE_SYS_IOCTL_H
void
touch (const char *file, time_t tm)
{
- struct timeval timevals[2];
+#if HAVE_UTIME
+# ifdef HAVE_STRUCT_UTIMBUF
+ struct utimbuf times;
+# else
+ struct {
+ time_t actime;
+ time_t modtime;
+ } times;
+# endif
+ times.modtime = tm;
+ times.actime = time (NULL);
+ if (utime (file, ×) == -1)
+ logprintf (LOG_NOTQUIET, "utime(%s): %s\n", file, strerror (errno));
+#else
+ struct timespec timespecs[2];
+ int fd;
- timevals[0].tv_sec = time (NULL);
- timevals[0].tv_usec = 0L;
- timevals[1].tv_sec = tm;
- timevals[1].tv_usec = 0L;
+ fd = open (file, O_WRONLY);
+ if (fd < 0)
+ {
+ logprintf (LOG_NOTQUIET, "open(%s): %s\n", file, strerror (errno));
+ return;
+ }
+
+ timespecs[0].tv_sec = time (NULL);
+ timespecs[0].tv_nsec = 0L;
+ timespecs[1].tv_sec = tm;
+ timespecs[1].tv_nsec = 0L;
- if (utimes (file, timevals) == -1)
- logprintf (LOG_NOTQUIET, "utimes(%s): %s\n", file, strerror (errno));
+ if (futimens (fd, timespecs) == -1)
+ logprintf (LOG_NOTQUIET, "futimens(%s): %s\n", file, strerror (errno));
+
+ close (fd);
+#endif
}
/* Checks if FILE is a symbolic link, and removes it if it is. Does
{
int l = strlen (s);
+ if (opt.output_document && strcmp (s, opt.output_document) == 0)
+ return true;
+
while (l && s[l] != '/')
--l;
if (s[l] == '/')
/* We don't have siglongjmp to preserve the set of blocked signals;
if we longjumped out of the handler at this point, SIGALRM would
remain blocked. We must unblock it manually. */
- int mask = siggetmask ();
- mask &= ~sigmask (SIGALRM);
- sigsetmask (mask);
+ sigset_t set;
+ sigemptyset (&set);
+ sigaddset (&set, SIGALRM);
+ sigprocmask (SIG_BLOCK, &set, NULL);
/* Now it's safe to longjump. */
longjmp (run_with_timeout_env, -1);