From: Andrew Tridgell Date: Thu, 25 Sep 2003 06:11:28 +0000 (+0200) Subject: - avoid using basename() to fix systems with that already defined X-Git-Tag: v2.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bd4ffafcfc4a233279991ea8d1f0aa97443ae14;p=thirdparty%2Fccache.git - avoid using basename() to fix systems with that already defined - add EINTR handling in lock_fd() - make sure we prototype asprintf on systems that don't have it --- diff --git a/ccache.c b/ccache.c index c4d3f695b..03e205e81 100644 --- a/ccache.c +++ b/ccache.c @@ -335,7 +335,7 @@ static void find_hash(ARGS *args) limit the basename to 10 characters in order to cope with filesystem with small maximum filename length limits */ - input_base = basename(input_file); + input_base = str_basename(input_file); tmp = strchr(input_base, '.'); if (tmp != NULL) { *tmp = 0; @@ -547,7 +547,7 @@ static void find_compiler(int argc, char **argv) orig_args = args_init(argc, argv); - base = basename(argv[0]); + base = str_basename(argv[0]); /* we might be being invoked like "ccache gcc -c foo.c" */ if (strcmp(base, MYNAME) == 0) { @@ -557,7 +557,7 @@ static void find_compiler(int argc, char **argv) /* a full path was given */ return; } - base = basename(argv[1]); + base = str_basename(argv[1]); } /* support user override of the compiler */ diff --git a/ccache.h b/ccache.h index 6eddf768c..20038a45a 100644 --- a/ccache.h +++ b/ccache.h @@ -83,7 +83,7 @@ char *x_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 *)); -char *basename(const char *s); +char *str_basename(const char *s); char *dirname(char *s); int lock_fd(int fd); size_t file_size(struct stat *st); @@ -107,6 +107,9 @@ int unify_hash(const char *fname); #ifndef HAVE_VASPRINTF int vasprintf(char **, const char *, va_list ); #endif +#ifndef HAVE_ASPRINTF +int asprintf(char **ptr, const char *format, ...); +#endif #ifndef HAVE_SNPRINTF int snprintf(char *,size_t ,const char *, ...); diff --git a/cleanup.c b/cleanup.c index 1e886427b..99312283e 100644 --- a/cleanup.c +++ b/cleanup.c @@ -52,7 +52,7 @@ static void traverse_fn(const char *fname, struct stat *st) if (!S_ISREG(st->st_mode)) return; - p = basename(fname); + p = str_basename(fname); if (strcmp(p, "stats") == 0) { free(p); return; @@ -165,7 +165,7 @@ static void wipe_fn(const char *fname, struct stat *st) if (!S_ISREG(st->st_mode)) return; - p = basename(fname); + p = str_basename(fname); if (strcmp(p, "stats") == 0) { free(p); return; diff --git a/execute.c b/execute.c index 97a29c1a7..f55fbdda5 100644 --- a/execute.c +++ b/execute.c @@ -102,7 +102,7 @@ char *find_executable(const char *name, const char *exclude_name) if (S_ISLNK(st1.st_mode)) { char *buf = x_realpath(fname); if (buf) { - char *p = basename(buf); + char *p = str_basename(buf); if (strcmp(p, exclude_name) == 0) { /* its a link to "ccache" ! */ free(p); diff --git a/util.c b/util.c index b5661bb77..6bab50d91 100644 --- a/util.c +++ b/util.c @@ -242,7 +242,7 @@ void traverse(const char *dir, void (*fn)(const char *, struct stat *)) /* return the base name of a file - caller frees */ -char *basename(const char *s) +char *str_basename(const char *s) { char *p = strrchr(s, '/'); if (p) { @@ -267,6 +267,7 @@ char *dirname(char *s) int lock_fd(int fd) { struct flock fl; + int ret; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; @@ -274,7 +275,12 @@ int lock_fd(int fd) fl.l_len = 1; fl.l_pid = 0; - return fcntl(fd, F_SETLKW, &fl); + /* not sure why we would be getting a signal here, + but one user claimed it is possible */ + do { + ret = fcntl(fd, F_SETLKW, &fl); + } while (ret == -1 && errno == EINTR); + return ret; } /* return size on disk of a file */