-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneedsmade.c
More file actions
64 lines (50 loc) · 1.52 KB
/
needsmade.c
File metadata and controls
64 lines (50 loc) · 1.52 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "nrm.h"
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h> /* required for stat */
char *progname; /* program name for error message */
int aflag = 0;
int cflag = 0;
int fflag = 1;
int mflag = 0;
int iflag = 0; /* not used but needed to link with errout */
int needsmade(char *path1, char *path2);
int main(int argc, char **argv) /* test to see if first file is newer than second */
{
extern int optind; /* argv index of next option */
extern int opterr;
int c;
int errflag = 0;
int temp, returncode;
opterr = 0; /* disables getopt's error msg's */
progname = argv[0];
if (argc != 3)
errflag++; /* print usage if no com args */
if (errflag) {
fprintf(stderr, "usage: %s sourcefile targetfile\n", progname);
fprintf(stderr, " checks modification times of source, target.\n");
fprintf(stderr, " returns 0 if sourcefile is newer than target");
fprintf(stderr, " or if target does not exist.\n");
fprintf(stderr, " returns 1 if target is newer than source\n");
fprintf(stderr, " returns 2 if source does not exist\n");
exit(3);
}
return (needsmade(argv[1], argv[2]));
}
int needsmade(char *path1, char *path2)
{
double delta;
struct stat buf1;
struct stat buf2;
if (lstat(path1, &buf1) == -1) {
return(2);
}
if (lstat(path2, &buf2) == -1) {
return(0);
}
delta = difftime(buf1.st_mtime, buf2.st_mtime);
if (delta > 0.0)
return 0;
else
return 1;
}