forked from emacs-mirror/emacs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isemacsvalid.c
110 lines (94 loc) · 2.65 KB
/
isemacsvalid.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* isemacsvalid.c -*- C -*- */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "dumpemacs.h"
int is_emacs_valid(int debugflag)
{
struct stat sb;
int ret;
time_t lastMod;
ret = lstat(kEmacsArchPath, &sb);
if (ret == -1) {
if (errno == ENOENT) {
return 0; /* regenerate it */
} else {
return -1; /* error */
}
}
if (S_ISDIR(sb.st_mode)) {
errno = EISDIR;
return -1;
} else if (!S_ISREG(sb.st_mode)) {
/* if it is not a file, then nuke it: */
return 0;
}
/* It is a file. Check the times: */
lastMod = sb.st_mtime;
/* validate that the per-arch executable is
* newer than the wrapper or dumpemacs: */
ret = lstat(kEmacsWrapperPath, &sb);
if (ret == -1) {
return -1; /* error */
}
if (sb.st_mtime > lastMod) {
/* if the wrapper is more recent than the per-arch, then: */
return 0; /* (i.e. regenerate it) */
}
ret = lstat(kDumpEmacsPath, &sb);
if (ret == -1) {
return -1; /* error */
}
if (sb.st_mtime > lastMod) {
/* if the dumpemacs is more recent than the per-arch, then: */
return 0; /* (i.e. regenerate it) */
}
if (debugflag > 0) {
printf("debugflag is %d.\n", debugflag);
}
/* per-arch emacs is present and newer than the
* infrastructure tools, so let it be: */
return 1;
}
/* The Makefile will define this for us when building the executable: */
#ifdef STANDALONE_ISEMACSVALID
/* a header providing a library interface to the machochecker program,
* whose sources we stole from ld64: */
# include "machochecker.h"
int main(int argc, const char* argv[])
{
int ret = is_emacs_valid(0);
int printed = printf("Is emacs valid?\n");
switch (ret) {
case -1:
printed += fprintf(stderr, "Error");
if (errno != 0) {
printed += fprintf(stderr, ": %d (i.e. \"%s\")\n", errno,
strerror(errno));
} else {
printed += fprintf(stderr, ".\n");
}
break;
case 0:
printed += printf("Per-arch emacs is outdated; need to regenerate it.\n");
break;
case 1:
printed += printf("Per-arch emacs is present and new enough, so let it be.\n");
break;
default:
printed += fprintf(stderr, "Unhandled return value for is_emacs_valid()!\n");
break;
}
/* FIXME: munge argv to insert proper path to built emacs, if needed: */
ret = machocheck_main(argc, argv);
printed += printf("machocheck_main() returned %d: %s.\n", ret,
((ret == 0) ? "success, should be valid" : "failure, invalid"));
if (printed)
return ret;
else
exit(EXIT_FAILURE);
}
#endif /* STANDALONE_ISEMACSVALID */
/* EOF */