===================
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.
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);
}
}
#include <utime.h>
#include <stdarg.h>
#include <dirent.h>
+#include <limits.h>
#define STATUS_NOTFOUND 3
#define STATUS_FATAL 4
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);
}
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;
+}