]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
use realpath() to handle multiple levels of symlinks
authorAndrew Tridgell <tridge@samba.org>
Sun, 31 Mar 2002 05:01:05 +0000 (07:01 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sun, 31 Mar 2002 05:01:05 +0000 (07:01 +0200)
README
ccache.c
ccache.h
util.c

diff --git a/README b/README
index 4baf89eabfd2e89b2c69519ffd8570649a4347a3..8cd244bdf558b784743a7e81dcac25f1bba2e022 100644 (file)
--- a/README
+++ b/README
@@ -151,9 +151,5 @@ please let me know.
 ===================
 Andrew Tridgell
 http://samba.org/~tridge/
+bugs@ccache.samba.org
 March 2002
-
-PS: I get far too much email to answer, so don't be surprised if you
-have a hard time getting hold of me. You might try the
-#samba-technical IRC channel on irc.openprojects.net if you need me
-quickly.
index 265aa0c1082fe7582be5249f744d7384d5133f44..d4270124fb45c869071ecfeeccb24769a838627c 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -368,22 +368,19 @@ static void find_compiler(int argc, char **argv)
                    lstat(fname, &st1) == 0 &&
                    stat(fname, &st2) == 0 &&
                    S_ISREG(st2.st_mode)) {
-                       char buf[1024];
-                       int len;
-
                        /* if its a symlink then ensure it doesn't
                            point at something called "ccache" */
                        if (S_ISLNK(st1.st_mode)) {
-                               char *p;
-                               len = readlink(fname, buf, sizeof(buf));
-                               if (len != -1 && len < (int)sizeof(buf)) {
-                                       buf[len] = 0;
-                                       p = basename(buf);
+                               char *buf = x_realpath(fname);
+                               if (buf) {
+                                       char *p = basename(buf);
                                        if (strcmp(p, MYNAME) == 0) {
                                                /* its a link to "ccache" ! */
                                                free(p);
+                                               free(buf);
                                                continue;
                                        }
+                                       free(buf);
                                        free(p);
                                }
                        }
index 354b47324b9b1d8db286643e2e4a5586f887537b..908bc30b4996334781477522dbc7daf79dd52763 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -18,6 +18,7 @@
 #include <utime.h>
 #include <stdarg.h>
 #include <dirent.h>
+#include <limits.h>
 
 #define STATUS_NOTFOUND 3
 #define STATUS_FATAL 4
@@ -76,6 +77,7 @@ char *dirname(char *s);
 int lock_fd(int fd);
 size_t file_size(struct stat *st);
 int safe_open(const char *fname);
+char *x_realpath(const char *path);
 
 void stats_update(enum stats stat);
 void stats_zero(void);
diff --git a/util.c b/util.c
index 7ef5baee4e8c5468d66fd2e7d86c7dc89952bfc5..2a155d219670e04c57c02ad42165caab56c02fd2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -295,3 +295,33 @@ size_t value_units(const char *s)
        }
        return v;
 }
+
+
+/*
+  a sane realpath() function, trying to cope with stupid path limits and 
+  a broken API
+*/
+char *x_realpath(const char *path)
+{
+       int maxlen;
+       char *ret, *p;
+#ifdef PATH_MAX
+       maxlen = PATH_MAX;
+#elif defined(MAXPATHLEN)
+       maxlen = MAXPATHLEN;
+#elif defined(_PC_PATH_MAX)
+       maxlen = pathconf(path, _PC_PATH_MAX);
+#endif
+       if (maxlen < 4096) maxlen = 4096;
+       
+       ret = x_malloc(maxlen);
+       
+       p = realpath(path, ret);
+       if (p) {
+               p = x_strdup(p);
+               free(ret);
+               return p;
+       }
+       free(ret);
+       return NULL;
+}