Author: cwittich
Date: Thu Mar 6 17:36:43 2008
New Revision: 32587
URL:
http://svn.reactos.org/svn/reactos?rev=3D32587&view=3Drev
Log:
apply patch from Christophe Gisquet <christophe dot gisquet at free.fr> wit=
h some modifications
-don't use access with X_OK, it won't work on Vista
http://lists.samba.org/archive/ccache/2006q3/000242.html
Modified:
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/args.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.h
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/cleanup.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/execute.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/hash.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/stats.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/unify.c
trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/util.c
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/args.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/args.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/args.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/args.c Thu Mar 6 17:3=
6:43 2008
@@ -38,7 +38,7 @@
void args_add(ARGS *args, const char *s)
{
args->argv =3D (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(ch=
ar *));
- args->argv[args->argc] =3D x_strdup(s);
+ args->argv[args->argc] =3D x_quote_strdup(s);
args->argc++;
args->argv[args->argc] =3D NULL;
}
@@ -69,7 +69,7 @@
args->argv =3D (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(ch=
ar *));
memmove(&args->argv[1], &args->argv[0], =
(args->argc+1) * sizeof(args->argv[0]));
- args->argv[0] =3D x_strdup(s);
+ args->argv[0] =3D x_quote_strdup(s);
args->argc++;
}
=
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/ccache.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.c Thu Mar 6 17=
:36:43 2008
@@ -87,6 +87,38 @@
{"ii", "ii"},
{NULL, NULL}};
=
+static int first_is_meh(const char* first)
+{
+ const char* exe =3D strrchr(first, PATH_SEP_CHAR);
+ const size_t len =3D strlen(MYNAME);
+
+ if (exe) exe++;
+ else exe=3Dfirst;
+ return (strlen(exe) >=3D len && strncmp(exe, MYNAME, len) =3D=3D 0
&&
+ (exe[len]=3D=3D0 || strcmp(exe+len, ".exe")=3D=3D0) );
+}
+
+char *build_command(char **argv)
+{
+ char *cmd;
+ int i, length =3D 0;
+
+ for(i =3D 0; argv[i]; i++) {
+ length++;
+ length +=3D (int)strlen(argv[i]);
+ }
+
+ cmd =3D (char *)malloc(length);
+ strcpy(cmd, argv[0]);
+
+ for(i =3D 1; argv[i]; i++) {
+ strcat(cmd, " ");
+ strcat(cmd, argv[i]);
+ }
+
+ return cmd;
+}
+
/*
something went badly wrong - just execute the real compiler
*/
@@ -155,12 +187,15 @@
{
char *path_stderr;
char *tmp_stdout, *tmp_stderr, *tmp_hashname;
- struct stat st1, st2;
+ struct stat st;
int status;
-
- x_asprintf(&tmp_stdout, "%s/tmp.stdout.%s", temp_dir, tmp_string());
- x_asprintf(&tmp_stderr, "%s/tmp.stderr.%s", temp_dir, tmp_string());
- x_asprintf(&tmp_hashname, "%s/tmp.hash.%s.o", temp_dir, tmp_string());
+ off_t size =3D 0;
+
+ /* No quoting, unique arguments */
+ x_asprintf(&tmp_stdout, "%s"PATH_SEP"tmp.stdout.%s", temp_dir,
tmp_string=
());
+ x_asprintf(&tmp_stderr, "%s"PATH_SEP"tmp.stderr.%s", temp_dir,
tmp_string=
());
+ /* Must be quoted as it will belong to a command-line */
+ x_asprintf(&tmp_hashname, "%s"PATH_SEP"tmp.hash.%s.o", temp_dir,
tmp_stri=
ng());
=
args_add(args, "-o");
args_add(args, tmp_hashname);
@@ -181,7 +216,7 @@
status =3D execute(args->argv, tmp_stdout, tmp_stderr);
args_pop(args, 3);
=
- if (stat(tmp_stdout, &st1) !=3D 0 || st1.st_size !=3D 0) {
+ if (stat(tmp_stdout, &st) !=3D 0 || st.st_size !=3D 0) {
cc_log("compiler produced stdout for %s\n", output_file);
stats_update(STATS_STDOUT);
unlink(tmp_stdout);
@@ -198,7 +233,7 @@
=
fd =3D open(tmp_stderr, O_RDONLY | O_BINARY);
if (fd !=3D -1) {
- if (strcmp(output_file, "/dev/null") =3D=3D 0 ||
+ if (strcmp(output_file, DEV_NULL) =3D=3D 0 ||
rename(tmp_hashname, output_file) =3D=3D 0 || errno =3D=3D ENOENT) {
if (cpp_stderr) {
/* we might have some stderr from cpp */
@@ -211,8 +246,7 @@
}
}
=
- /* we can use a quick method of
- getting the failed output */
+ /* we can use a quick method of getting the failed output */
copy_fd(fd, 2);
close(fd);
unlink(tmp_stderr);
@@ -228,19 +262,32 @@
failed();
}
=
+ if (stat(tmp_hashname, &st) !=3D 0 || rename(tmp_hashname, hashname) !=
=3D 0) {
+ cc_log("failed to rename output: %s\n"
+ " '%s'\n"
+ " -> '%s': \n",
+ strerror(errno), tmp_hashname, hashname);
+ stats_update(STATS_ERROR);
+ failed();
+ }
+ cc_log("Moved '%s' to '%s'\n", tmp_hashname, hashname);
+ size +=3D file_size(&st);
+
x_asprintf(&path_stderr, "%s.stderr", hashname);
-
- if (stat(tmp_stderr, &st1) !=3D 0 ||
- stat(tmp_hashname, &st2) !=3D 0 ||
- rename(tmp_hashname, hashname) !=3D 0 ||
- rename(tmp_stderr, path_stderr) !=3D 0) {
- cc_log("failed to rename tmp files - %s\n", strerror(errno));
+ if (stat(tmp_stderr, &st) !=3D 0 || rename(tmp_stderr, path_stderr) !=3D =
0) {
+ cc_log("failed to rename stderr: %s\n"
+ " '%s'\n"
+ " -> '%s': \n",
+ strerror(errno), tmp_stderr, path_stderr);
stats_update(STATS_ERROR);
failed();
}
=
+ cc_log("Moved '%s' to '%s'\n", tmp_stderr, path_stderr);
+ size +=3D file_size(&st);
+
cc_log("Placed %s into cache\n", output_file);
- stats_tocache(file_size(&st1) + file_size(&st2));
+ stats_tocache(size);
=
free(tmp_hashname);
free(tmp_stderr);
@@ -331,8 +378,8 @@
hash_string(str_basename(args->argv[0]));
}
=
- hash_int(st.st_size);
- hash_int(st.st_mtime);
+ hash_int((int)st.st_size);
+ hash_int((int)st.st_mtime);
=
/* possibly hash the current working directory */
if (getenv("CCACHE_HASHDIR")) {
@@ -356,11 +403,11 @@
input_base[10] =3D 0;
}
=
- /* now the run */
- x_asprintf(&path_stdout, "%s/%s.tmp.%s.%s", temp_dir,
- input_base, tmp_string(), =
- i_extension);
- x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string());
+ /* now the run - path_std* are unique args =3D> no quoting */
+ x_asprintf(&path_stdout, "%s"PATH_SEP"%s.tmp.%s.%s", temp_dir,
+ input_base, tmp_string(), =
+ i_extension);
+ x_asprintf(&path_stderr, "%s"PATH_SEP"tmp.cpp_stderr.%s",
temp_dir, tmp_s=
tring());
=
if (!direct_i_file) {
/* run cpp on the input file to obtain the .i */
@@ -423,17 +470,18 @@
=
/* we use a N level subdir for the cache path to reduce the impact
on filesystems which are slow for large directories
+ Quoting not necessary because unique argument, or not used yet.
*/
s =3D hash_result();
- x_asprintf(&hash_dir, "%s/%c", cache_dir, s[0]);
- x_asprintf(&stats_file, "%s/stats", hash_dir);
+ x_asprintf(&hash_dir, "%s"PATH_SEP"%c", cache_dir, s[0]);
+ x_asprintf(&stats_file, "%s"PATH_SEP"stats", hash_dir);
for (i=3D1; i<nlevels; i++) {
char *p;
if (create_dir(hash_dir) !=3D 0) {
cc_log("failed to create %s\n", hash_dir);
failed();
}
- x_asprintf(&p, "%s/%c", hash_dir, s[i]);
+ x_asprintf(&p, "%s"PATH_SEP"%c", hash_dir, s[i]);
free(hash_dir);
hash_dir =3D p;
}
@@ -441,7 +489,7 @@
cc_log("failed to create %s\n", hash_dir);
failed();
}
- x_asprintf(&hashname, "%s/%s", hash_dir, s+nlevels);
+ x_asprintf(&hashname, "%s"PATH_SEP"%s", hash_dir, s+nlevels);
free(hash_dir);
}
=
@@ -483,7 +531,7 @@
=
utime(stderr_file, NULL);
=
- if (strcmp(output_file, "/dev/null") =3D=3D 0) {
+ if (strcmp(output_file, DEV_NULL) =3D=3D 0) {
ret =3D 0;
} else {
unlink(output_file);
@@ -562,10 +610,10 @@
base =3D str_basename(argv[0]);
=
/* we might be being invoked like "ccache gcc -c foo.c" */
- if (strcmp(base, MYNAME) =3D=3D 0) {
+ if (first_is_meh(argv[0])) {
args_remove_first(orig_args);
free(base);
- if (strchr(argv[1],'/')) {
+ if (strchr(argv[1],PATH_SEP_CHAR)) {
/* a full path was given */
return;
}
@@ -801,7 +849,7 @@
if (!output_file) {
char *p;
output_file =3D x_strdup(input_file);
- if ((p =3D strrchr(output_file, '/'))) {
+ if ((p =3D strrchr(output_file, PATH_SEP_CHAR))) {
output_file =3D p+1;
}
p =3D strrchr(output_file, '.');
@@ -815,7 +863,7 @@
}
=
/* cope with -o /dev/null */
- if (strcmp(output_file,"/dev/null") !=3D 0 && stat(output_file,
&st) =3D=
=3D 0 && !S_ISREG(st.st_mode)) {
+ if (strcmp(output_file, DEV_NULL) !=3D 0 && stat(output_file, &st) =3D=3D=
0 && !S_ISREG(st.st_mode)) {
cc_log("Not a regular file %s\n", output_file);
stats_update(STATS_DEVICE);
failed();
@@ -934,14 +982,15 @@
=
case 'F':
v =3D atoi(optarg);
- stats_set_limits(v, -1);
+ stats_set_limits((long)v, -1);
printf("Set cache file limit to %u\n", (unsigned)v);
break;
=
case 'M':
v =3D value_units(optarg);
- stats_set_limits(-1, v);
+ stats_set_limits(-1, (long) v);
printf("Set cache size limit to %uk\n", (unsigned)v);
+ printf("not implemented");
break;
=
default:
@@ -983,7 +1032,7 @@
=
cache_dir =3D getenv("CCACHE_DIR");
if (!cache_dir) {
- x_asprintf(&cache_dir, "%s/.ccache", get_home_directory());
+ x_asprintf(&cache_dir, "%s"PATH_SEP".ccache",
get_home_directory());
}
=
temp_dir =3D getenv("CCACHE_TEMPDIR");
@@ -1009,8 +1058,8 @@
=
=
/* check if we are being invoked as "ccache" */
- if (strlen(argv[0]) >=3D strlen(MYNAME) &&
- strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) =3D=3D 0) {
+ if (first_is_meh(argv[0]))
+ {
if (argc < 2) {
usage();
exit(1);
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.h
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/ccache.h?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.h (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/ccache.h Thu Mar 6 17=
:36:43 2008
@@ -1,23 +1,38 @@
#define CCACHE_VERSION "2.4"
=
#include "config.h"
+#define USUAL_PATH_SEP_CHAR '/'
+#define USUAL_PATH_SEP "/"
+#define WIN32_PATH_SEP_CHAR '\\'
+#define WIN32_PATH_SEP "\\"
=
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/mman.h>
-#include <sys/file.h>
+#ifdef _WIN32
+ #include <windows.h>
+ #include <sys/locking.h>
+ #define PATH_SEP WIN32_PATH_SEP
+ #define PATH_SEP_CHAR WIN32_PATH_SEP_CHAR
+ #define DEV_NULL "NUL"
+#else
+ #include <unistd.h>
+ #include <sys/wait.h>
+ #include <sys/mman.h>
+ #include <sys/file.h>
+ #include <utime.h>
+ #include <dirent.h>
+ #define PATH_SEP USUAL_PATH_SEP
+ #define PATH_SEP_CHAR USUAL_PATH_SEP_CHAR
+ #define DEV_NULL "/dev/null"
+#endif
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
-#include <utime.h>
#include <stdarg.h>
-#include <dirent.h>
#include <limits.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
@@ -83,6 +98,7 @@
int create_dir(const char *dir);
void x_asprintf(char **ptr, const char *format, ...);
char *x_strdup(const char *s);
+char *x_quote_strdup(const char* s);
void *x_realloc(void *ptr, size_t size);
void *x_malloc(size_t size);
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/cleanup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/cleanup.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/cleanup.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/cleanup.c Thu Mar 6 1=
7:36:43 2008
@@ -50,7 +50,9 @@
{
char *p;
=
+#ifndef WIN32
if (!S_ISREG(st->st_mode)) return;
+#endif
=
p =3D str_basename(fname);
if (strcmp(p, "stats") =3D=3D 0) {
@@ -107,8 +109,8 @@
{
unsigned i;
=
- size_threshold =3D maxsize * LIMIT_MULTIPLE;
- files_threshold =3D maxfiles * LIMIT_MULTIPLE;
+ size_threshold =3D maxsize * (size_t) LIMIT_MULTIPLE;
+ files_threshold =3D maxfiles * (size_t) LIMIT_MULTIPLE;
=
num_files =3D 0;
total_size =3D 0;
@@ -143,8 +145,9 @@
int i;
=
for (i=3D0;i<=3D0xF;i++) {
- x_asprintf(&dname, "%s/%1x", dir, i);
- x_asprintf(&sfile, "%s/%1x/stats", dir, i);
+ /* No need to quote, unique argument */
+ x_asprintf(&dname, "%s"PATH_SEP"%1x", dir, i);
+ x_asprintf(&sfile, "%s"PATH_SEP"%1x"PATH_SEP"stats",
dir, i);
=
memset(counters, 0, sizeof(counters));
stats_read(sfile, counters);
@@ -183,7 +186,7 @@
int i;
=
for (i=3D0;i<=3D0xF;i++) {
- x_asprintf(&dname, "%s/%1x", dir, i);
+ x_asprintf(&dname, "%s"PATH_SEP"%1x", dir, i);
traverse(dir, wipe_fn);
free(dname);
}
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/execute.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/execute.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/execute.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/execute.c Thu Mar 6 1=
7:36:43 2008
@@ -27,6 +27,7 @@
const char *path_stdout,
const char *path_stderr)
{
+#ifndef _WIN32
pid_t pid;
int status;
=
@@ -64,8 +65,87 @@
}
=
return WEXITSTATUS(status);
+#else /* Should be portable */
+ int status =3D -2;
+ int fd, std_od =3D -1, std_ed =3D -1;
+
+ unlink(path_stdout);
+ std_od =3D _dup(1);
+ fd =3D _open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 06=
66);
+ if (fd =3D=3D -1) {
+ status =3D STATUS_NOCACHE;
+ cc_log("stdout error: failed to open %s\n", path_stdout);
+ goto out;
+ }
+ /*std_od =3D */ _dup2(fd, 1);
+ _close(fd);
+
+ unlink(path_stderr);
+ fd =3D _open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 06=
66);
+ std_ed =3D _dup(2); =
+ if (fd =3D=3D -1) {
+ status =3D STATUS_NOCACHE;
+ cc_log("stderr error: failed to open %s\n", path_stderr);
+ goto out;
+ }
+ /*std_ed =3D*/ _dup2(fd, 2);
+ _close(fd);
+
+ /* Spawn process (_exec* familly doesn't return) */
+ status =3D _spawnv(_P_WAIT, argv[0], argv);
+
+ out:
+ cc_log("%s:\n stdout -> %s\n stderr -> %s\n process
status=3D%i\n",
+ argv[0], path_stdout, path_stderr, status);
+ if (status =3D=3D -1) cc_log("Error %i: %s\n", errno, strerror(errno));
+
+ /* Restore descriptors */
+ if (std_od !=3D -1) _dup2(std_od, 1);
+ if (std_ed !=3D -1) _dup2(std_ed, 2); =
+ _flushall();
+
+ return (status>0);
+#endif
}
=
+
+
+/*
+ Check that the executable exists
+*/
+char is_exec_file(const char *fname, const char *exclude_name)
+{
+ struct stat st1, st2;
+
+ if (access(fname, 0) =3D=3D 0 &&
+#ifndef _WIN32 /* Symlinks not used under windows */
+ lstat(fname, &st1) =3D=3D 0 &&
+#endif
+ stat(fname, &st2) =3D=3D 0 &&
+ S_ISREG(st2.st_mode)) {
+#ifndef _WIN32 /* Symlinks not used under windows */
+ /* if its a symlink then ensure it doesn't
+ point at something called exclude_name */
+ if (S_ISLNK(st1.st_mode)) {
+ char *buf =3D x_realpath(fname);
+ if (buf) {
+ char *p =3D str_basename(buf);
+ if (strcmp(p, exclude_name) =3D=3D 0) {
+ /* its a link to "ccache" ! */
+ free(p);
+ free(buf);
+ return -1;
+ }
+ free(buf);
+ free(p);
+ }
+ }
+#endif =
+ /* found it! */
+ return 1;
+ }
+ return -1;
+}
=
/*
find an executable by name in $PATH. Exclude any that are links to exclu=
de_name =
@@ -74,9 +154,9 @@
{
char *path;
char *tok;
- struct stat st1, st2;
-
- if (*name =3D=3D '/') {
+ const char *sep =3D ":";
+
+ if (*name =3D=3D PATH_SEP_CHAR) {
return x_strdup(name);
}
=
@@ -91,39 +171,37 @@
=
path =3D x_strdup(path);
=
+ /* Determine path separator */
+ if (strchr(path, ';')) sep =3D ";";
+
/* search the path looking for the first compiler of the right name
that isn't us */
- for (tok=3Dstrtok(path,":"); tok; tok =3D strtok(NULL, ":")) {
+ for (tok=3Dstrtok(path, sep); tok; tok =3D strtok(NULL, sep)) {
char *fname;
- x_asprintf(&fname, "%s/%s", tok, name);
+ x_asprintf(&fname, "%s"PATH_SEP"%s", tok, name);
/* look for a normal executable file */
- if (access(fname, X_OK) =3D=3D 0 &&
- lstat(fname, &st1) =3D=3D 0 &&
- stat(fname, &st2) =3D=3D 0 &&
- S_ISREG(st2.st_mode)) {
- /* if its a symlink then ensure it doesn't
- point at something called exclude_name */
- if (S_ISLNK(st1.st_mode)) {
- char *buf =3D x_realpath(fname);
- if (buf) {
- char *p =3D str_basename(buf);
- if (strcmp(p, exclude_name) =3D=3D 0) {
- /* its a link to "ccache" ! */
- free(p);
- free(buf);
- continue;
- }
- free(buf);
- free(p);
- }
- }
-
- /* found it! */
+ =
+
+ if (is_exec_file(fname, exclude_name) > 0)
+ {
free(path);
return fname;
}
free(fname);
- }
-
+
+ /* found it! */
+#ifdef _WIN32 /* Add .exe under win32 */
+ x_asprintf(&fname, "%s"PATH_SEP"%s.exe", tok, name);
+
+ /* look for a normal executable file */
+ if (is_exec_file(fname, exclude_name) > 0)
+ {
+ free(path);
+ return fname;
+ }
+ free(fname);
+#endif
+ }
+free(path);
return NULL;
}
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/hash.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/hash.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/hash.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/hash.c Thu Mar 6 17:3=
6:43 2008
@@ -35,7 +35,7 @@
=
void hash_string(const char *s)
{
- hash_buffer(s, strlen(s));
+ hash_buffer(s, (int)strlen(s));
}
=
void hash_int(int x)
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/stats.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/stats.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/stats.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/stats.c Thu Mar 6 17:=
36:43 2008
@@ -126,7 +126,7 @@
=
if (!stats_file) {
if (!cache_dir) return;
- x_asprintf(&stats_file, "%s/stats", cache_dir);
+ x_asprintf(&stats_file, "%s"PATH_SEP"stats", cache_dir);
}
=
/* open safely to try to prevent symlink races */
@@ -215,9 +215,9 @@
char *fname;
=
if (dir =3D=3D -1) {
- x_asprintf(&fname, "%s/stats", cache_dir);
+ x_asprintf(&fname, "%s"PATH_SEP"stats", cache_dir);
} else {
- x_asprintf(&fname, "%s/%1x/stats", cache_dir, dir);
+ x_asprintf(&fname, "%s"PATH_SEP"%1x"PATH_SEP"stats",
cache_dir, dir);
}
=
stats_read(fname, counters);
@@ -259,12 +259,12 @@
char *fname;
unsigned counters[STATS_END];
=
- x_asprintf(&fname, "%s/stats", cache_dir);
+ x_asprintf(&fname, "%s"PATH_SEP"stats", cache_dir);
unlink(fname);
free(fname);
=
for (dir=3D0;dir<=3D0xF;dir++) {
- x_asprintf(&fname, "%s/%1x/stats", cache_dir, dir);
+ x_asprintf(&fname, "%s"PATH_SEP"%1x"PATH_SEP"stats",
cache_dir, dir);
fd =3D safe_open(fname);
if (fd =3D=3D -1) {
free(fname);
@@ -305,9 +305,9 @@
char *fname, *cdir;
int fd;
=
- x_asprintf(&cdir, "%s/%1x", cache_dir, dir);
+ x_asprintf(&cdir, "%s"PATH_SEP"%1x", cache_dir, dir);
create_dir(cdir);
- x_asprintf(&fname, "%s/stats", cdir);
+ x_asprintf(&fname, "%s"PATH_SEP"stats", cdir);
free(cdir);
=
memset(counters, 0, sizeof(counters));
@@ -336,7 +336,7 @@
char *stats_file;
=
create_dir(dir);
- x_asprintf(&stats_file, "%s/stats", dir);
+ x_asprintf(&stats_file, "%s"PATH_SEP"stats", dir);
=
memset(counters, 0, sizeof(counters));
=
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/unify.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/unify.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/unify.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/unify.c Thu Mar 6 17:=
36:43 2008
@@ -209,7 +209,7 @@
q =3D p[ofs];
for (i=3D0;i<tokens[q].num_toks;i++) {
unsigned char *s =3D (unsigned char *)tokens[q].toks[i];
- int len =3D strlen((char *)s);
+ int len =3D (int) strlen((char *)s);
if (size >=3D ofs+len && memcmp(&p[ofs], s, len) =3D=3D 0) {
int j;
for (j=3D0;s[j];j++) {
@@ -241,6 +241,7 @@
int fd;
struct stat st; =
char *map;
+ HANDLE view;
=
fd =3D open(fname, O_RDONLY|O_BINARY);
if (fd =3D=3D -1 || fstat(fd, &st) !=3D 0) {
@@ -249,6 +250,33 @@
return -1;
}
=
+#ifdef _WIN32
+ /* win32 equivalent of mmap is ViewMapOfFile, but malloc+read
+ may be better */
+ view =3D CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
+ PAGE_READONLY|SEC_COMMIT, 0,0 , NULL);
+ if (NULL =3D=3D view) {
+ cc_log("Failed to create file mapping %s: %s\n",
+ fname, strerror(errno));
+ stats_update(STATS_PREPROCESSOR);
+ return -1;
+ }
+
+ map =3D MapViewOfFile(view, FILE_MAP_READ, 0, 0, st.st_size);
+ if (NULL =3D=3D map) {
+ cc_log("Failed to map view of file %s: %s\n",
+ fname, strerror(errno));
+ stats_update(STATS_PREPROCESSOR);
+ return -1;
+ }
+
+ /* pass it through the unifier */
+ unify((unsigned char *)map, st.st_size);
+
+ UnmapViewOfFile(map);
+ CloseHandle(view);
+ close(fd);
+#else
/* we use mmap() to make it easy to handle arbitrarily long
lines in preprocessor output. I have seen lines of over
100k in length, so this is well worth it */
@@ -263,7 +291,7 @@
unify((unsigned char *)map, st.st_size);
=
munmap(map, st.st_size);
-
+#endif
return 0;
}
=
Modified: trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/util.c
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/RosBE-Windows/Too=
ls/ccache-2.4/util.c?rev=3D32587&r1=3D32586&r2=3D32587&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/util.c (original)
+++ trunk/tools/RosBE/RosBE-Windows/Tools/ccache-2.4/util.c Thu Mar 6 17:3=
6:43 2008
@@ -20,6 +20,22 @@
=
static FILE *logfile;
=
+#ifdef _WIN32
+int fchmod(int fildes, mode_t mode)
+{
+ return 0;
+}
+#endif
+
+#ifndef HAVE_MKSTEMP
+/* cheap and nasty mkstemp replacement */
+int mkstemp(char *template)
+{
+ _mktemp(template);
+ return open(template, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
+}
+#endif
+
/* log a message to the CCACHE_LOGFILE location */
void cc_log(const char *format, ...)
{
@@ -155,6 +171,34 @@
}
=
/*
+ this is like strdup() but dies if the malloc fails and add quotes
+ around the argument if it contains spaces.
+*/
+char*
+x_quote_strdup(const char* s)
+{
+ /* Protect against args containing spaces in them - unicode-able ? */
+ if (strchr(s, ' ') !=3D NULL) {
+ size_t len =3D strlen(s); /* at least 1 as it holds ' ' */
+ char *new_arg =3D x_malloc(len+2*1+1); /* Make room for quoting */
+
+ /* Quote */
+ new_arg[0] =3D '"';
+ memcpy(new_arg+1, s, len);
+ new_arg[len+1] =3D '"';
+ new_arg[len+2] =3D 0;
+
+ /* Done */
+ cc_log("Quoted %s\n", new_arg);
+ return new_arg;
+ }
+ else
+ return x_strdup(s);
+}
+
+
+
+/*
this is like strdup() but dies if the malloc fails
*/
char *x_strdup(const char *s)
@@ -220,7 +264,7 @@
=
if (strlen(de->d_name) =3D=3D 0) continue;
=
- x_asprintf(&fname, "%s/%s", dir, de->d_name);
+ x_asprintf(&fname, "%s"PATH_SEP"%s", dir, de->d_name);
if (lstat(fname, &st)) {
if (errno !=3D ENOENT) {
perror(fname);
@@ -244,7 +288,7 @@
/* return the base name of a file - caller frees */
char *str_basename(const char *s)
{
- char *p =3D strrchr(s, '/');
+ char *p =3D strrchr(s, PATH_SEP_CHAR);
if (p) {
return x_strdup(p+1);
} =
@@ -257,7 +301,7 @@
{
char *p;
s =3D x_strdup(s);
- p =3D strrchr(s, '/');
+ p =3D strrchr(s, PATH_SEP_CHAR);
if (p) {
*p =3D 0;
} =
@@ -266,6 +310,9 @@
=
int lock_fd(int fd)
{
+#ifdef _WIN32
+ return _locking(fd, _LK_NBLCK, 1);
+#else
struct flock fl;
int ret;
=
@@ -281,17 +328,23 @@
ret =3D fcntl(fd, F_SETLKW, &fl);
} while (ret =3D=3D -1 && errno =3D=3D EINTR);
return ret;
-}
+#endif
+}
+
=
/* return size on disk of a file */
size_t file_size(struct stat *st)
{
+#ifdef _WIN32
+ return st->st_size;
+#else
size_t size =3D st->st_blocks * 512;
if ((size_t)st->st_size > size) {
/* probably a broken stat() call ... */
size =3D (st->st_size + 1023) & ~1023;
}
return size;
+#endif
}
=
=
@@ -351,6 +404,7 @@
a sane realpath() function, trying to cope with stupid path limits and =
a broken API
*/
+#ifndef WIN32
char *x_realpath(const char *path)
{
int maxlen;
@@ -389,6 +443,7 @@
free(ret);
return NULL;
}
+#endif
=
/* a getcwd that will returns an allocated buffer */
char *gnu_getcwd(void)
@@ -397,7 +452,7 @@
=
while (1) {
char *buffer =3D (char *)x_malloc(size);
- if (getcwd(buffer, size) =3D=3D buffer) {
+ if (_getcwd(buffer, size) =3D=3D buffer) {
return buffer;
}
free(buffer);
@@ -408,16 +463,6 @@
}
}
=
-#ifndef HAVE_MKSTEMP
-/* cheap and nasty mkstemp replacement */
-int mkstemp(char *template)
-{
- mktemp(template);
- return open(template, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600);
-}
-#endif
-
-
/* create an empty file */
int create_empty_file(const char *fname)
{
@@ -436,7 +481,18 @@
*/
const char *get_home_directory(void)
{
- const char *p =3D getenv("HOME");
+ const char *p =3D NULL;
+
+#ifdef _WIN32
+ static char szPath[MAX_PATH];
+
+ // "Documents and Settings\user\Application Data" is CSIDL_APPDATA
+ if(SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, FALSE))
+ {
+ return szPath;
+ }
+#endif
+ p =3D getenv("HOME");
if (p) {
return p;
}