# ifndef lint static char Sccs_id[] = "%W% (NTUA hackers) (%G%)"; # endif #include #include #include #include #include char *ctime (); long gettimeofday (); struct timeval *tp; struct timezone *tzp; long x; int month[2][12] = { {2678400, 2419200, 2678400, 2592000, 2678400, 2592000, 2678400, 2678400, 2592000, 2678400, 2592000, 2678400}, {2678400, 2505600, 2678400, 2592000, 2678400, 2592000, 2678400, 2678400, 2592000, 2678400, 2592000, 2678400} }; int date, hour, date1, date2, date3, hour1, hour2; /* * chtim: change the modification date of a file */ main (argc, argv) register int argc; register char **argv; { register int i, j, total; char *path = "/etc/passwd"; char *prog = *argv; struct stat *stb; struct timeval *tvp[2]; long txp[4]; tp = (struct timeval *) malloc (sizeof (struct timeval)); tzp = (struct timezone *) malloc (sizeof (struct timezone)); stb = (struct stat *) malloc (sizeof (struct stat)); if (argc != 4) { fprintf (stderr, "%s: Usage: %s ddmmyy hhmm filename\n", prog, prog); exit (1); } else { date = atoi (argv[1]); hour = atoi (argv[2]); date1 = date / 10000; date2 = (date - 10000 * date1) / 100; date3 = date % 100; hour1 = hour / 100; hour2 = hour % 100; if (argc == 4) path = argv[3]; total = 0; for (i = 70; i < date3; i++) if (((i % 4) == 0)) total += 31622400; else total += 31536000; for (i = 0; i < (date2 - 1); i++) if ((date3 % 4) == 0) total += month[1][i]; else total += month[0][i]; total += (date1 - 1) * 24 * 3600 + hour1 * 3600 + hour2 * 60; gettimeofday (tp, tzp); total += tzp -> tz_minuteswest * 60; /* txp[0]=tp->tv_sec; txp[1]=tp->tv_usec; txp[2]=tp->tv_sec; txp[3]=tp->tv_usec; */ txp[0] = total; txp[1] = 0; txp[2] = total; txp[3] = 0; if (utimes (path, txp) == -1) { fprintf(stderr, "%s: utimes failed\n", prog); exit(2); } } exit(0); }