File: touchr.c

package info (click to toggle)
clisp 1999-07-22-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 36,876 kB
  • ctags: 19,900
  • sloc: ansic: 76,750; lisp: 65,522; asm: 16,504; sh: 8,971; fortran: 8,277; makefile: 3,251; objc: 2,481; perl: 1,744; java: 553; sed: 96
file content (25 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* Copies the date from one file to another file. */
/* "touchr file1 file2" is equivalent to
   "touch -r file1 file2", assuming GNU touch. */
/* Bruno Haible 8.7.1994 */

#include <sys/types.h>
#include <sys/stat.h> /* stat */
#include <sys/time.h> /* struct timeval, utimes */
#include <errno.h> /* EINTR, perror */

int main (argc,argv)
  int argc;
  char* argv[];
{ if (argc != 1+2) { exit(1); }
 {char* filename1 = argv[1];
  char* filename2 = argv[2];
  struct stat statbuf;
  struct timeval tv[2];
  if (stat(filename1,&statbuf) < 0) { perror(filename1); exit(1); }
  tv[0].tv_sec = statbuf.st_atime; tv[0].tv_usec = 0;
  tv[1].tv_sec = statbuf.st_mtime; tv[1].tv_usec = 0;
  if (utimes(filename2,tv) < 0) { perror(filename2); exit(1); }
  exit(0);
}}