[3.0] Bump libgdata to 0.6.4
[jhbuild/xnox.git] / install-check.c
blob725b024bf8baa119207a8ef2eba39ce30e605092
1 /* install-check
2 * Copyright (C) 2002 Manish Singh
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/wait.h>
28 static void
29 compare (const char *f1,
30 const char *f2)
32 struct stat b1, b2;
33 int status;
34 pid_t pid, rpid;
36 if (stat (f2, &b2) || stat (f1, &b1))
37 return;
39 if (b1.st_size != b2.st_size)
40 return;
42 pid = fork ();
44 if (pid == 0)
45 execlp ("cmp", "cmp", "-s", f1, f2, NULL);
46 else if (pid < 0)
47 return;
50 rpid = waitpid (pid, &status, 0);
51 while (rpid == -1 && errno == EINTR);
53 if (rpid != pid)
54 status = -1;
56 if (status != -1 && WIFEXITED (status) && WEXITSTATUS (status) == 0)
57 exit (0);
60 int
61 main (int argc,
62 char **argv)
64 struct stat buf;
65 char **args;
66 int i, len;
67 char *dot, *lastarg, *start;
69 lastarg = argv[argc - 1];
71 dot = strrchr (lastarg, '.');
72 if (dot == NULL)
74 len = strlen (lastarg);
75 if (len < strlen ("orbit-idl-2"))
76 goto install;
78 start = lastarg + len - strlen ("orbit-idl-2");
79 if (strcmp (start, "orbit-idl-2") != 0)
80 goto install;
82 else if (dot[1] != 'h' && dot[1] != 'c' && strcmp (dot + 1, "idl") != 0)
83 goto install;
85 if ((argc == 4) &&
86 (strcmp (argv[1], "-c") == 0) &&
87 (strcmp (argv[2], "-d") != 0) &&
88 !stat (argv[3], &buf) &&
89 !S_ISDIR (buf.st_mode))
90 compare (argv[2], argv[3]);
91 else if ((argc == 3) &&
92 (strcmp (argv[1], "-d") != 0) &&
93 !stat (argv[2], &buf) &&
94 !S_ISDIR (buf.st_mode))
95 compare (argv[1], argv[2]);
96 else if ((argc == 6) &&
97 (strcmp (argv[1], "-c") == 0) &&
98 (strcmp (argv[2], "-m") == 0) &&
99 !stat (argv[5], &buf) &&
100 !S_ISDIR (buf.st_mode))
101 compare (argv[4], argv[5]);
102 else if ((argc == 5) &&
103 (strcmp (argv[1], "-m") == 0) &&
104 !stat (argv[4], &buf) &&
105 !S_ISDIR (buf.st_mode))
106 compare (argv[3], argv[4]);
108 install:
109 args = malloc (sizeof (char *) * (argc + 1));
111 #ifndef WITH_INSTALL
112 args[0] = "install";
113 #else
114 args[0] = WITH_INSTALL;
115 #endif
117 for (i = 1; i < argc; i++)
118 args[i] = argv[i];
120 args[argc] = NULL;
122 execvp (args[0], args);
123 perror("executing 'install' failed");
125 return 1;