Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site sdcrdcf.UUCP Path: utzoo!linus!philabs!seismo!hao!menlo70!sytek!hplabs!sdcrdcf!barryg From: barryg@sdcrdcf.UUCP Newsgroups: net.sources Subject: utime - command level equivalent of utime(2) for 4.1.2bsd Message-ID: <534@sdcrdcf.UUCP> Date: Tue, 20-Sep-83 14:10:46 EDT Article-I.D.: sdcrdcf.534 Posted: Tue Sep 20 14:10:46 1983 Date-Received: Fri, 23-Sep-83 06:02:16 EDT Reply-To: barryg@sdcrdcf.UUCP (Barry Gold) Organization: System Development Corporation, Santa Monica Lines: 121 #include "stdio.h" #include #include #define min(uix,uiy) (uix i) usage(); s = stat(fn1, &sbuf); if (s < 0) {printf("cannot stat: %s\n", fn1); exit(2);} timep[0] = sbuf.st_atime; origt = sbuf.st_mtime; if (fn2 != NULL) timep[1] = getmtime(fn2, -1); else timep[1] = getoldest(fn1); utime(fn1, timep); return 0; } getmtime(fn, prev) char *fn; int prev; {int s; struct stat sb; s = stat(fn, &sb); if (s == 0) return sb.st_mtime; else if (prev == -1) {printf("cannot stat: %s\n", fn); exit(3);} else return prev; } getoldest(fn) char *fn; {char buf[256]; int l; time_t t1, t2; t1 = origt; sprintf(buf, "%s.~", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, "%s.bak", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, "%s.BAK", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, ",%s", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); if (chdir(".deleted") < 0) return t1; t2 = getmtime(fn, t1); t1 = min(t1, t2); sprintf(buf, "%s.~", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, "%s.bak", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, "%s.BAK", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); sprintf(buf, ",%s", fn); t2 = getmtime(buf, t1); t1 = min(t1, t2); chdir(".."); return t1; }