return strcmp((*a)->d_name, (*b)->d_name);
}
-static void recurse(const char *path) {
+static void recurse(const char *path_or_buf) {
static char *buf;
static int buf_allocd;
struct dirent **namelist, *const *de;
char *subpathp;
+ const char *path_or_0= path_or_buf==buf ? 0 : path_or_buf;
int nentries, pathl, esave, buf_want, i;
- pathl= strlen(path);
+ pathl= strlen(path_or_buf);
recurse_maxlen= 2;
- nentries= scandir(path, &namelist, recurse_filter, recurse_compar);
+ nentries= scandir(path_or_buf, &namelist, recurse_filter, recurse_compar);
esave= errno;
+
buf_want= pathl+1+recurse_maxlen+1;
if (buf_want > buf_allocd) {
buf= mrealloc(buf, buf_want);
buf_allocd= buf_want;
}
- strcpy(buf,path);
+ /* NOTE that path_or_buf is invalid after this point because
+ * it might have been realloc'd ! */
+ if (path_or_0) strcpy(buf,path_or_0);
+
buf[pathl]= '/';
subpathp= buf+pathl+1;
if (nentries < 0) {
return;
}
for (i=0, de=namelist; i<nentries; i++, de++) {
+ fprintf(stderr,
+ "buf=%p \"%s\" path=%p \"%s\" subpathp-buf=%ld d_name=\"%s\"\n",
+ buf,buf,path_or_0,path_or_0,(long)(subpathp-buf),(*de)->d_name);
strcpy(subpathp, (*de)->d_name);
node(buf);
free(*de);
+chiark-utils (4.1.4) unstable; urgency=low
+
+ summer bugfix:
+ * `buf' is used reentrantely by recurse() and sometimes is the `path'
+ argument to recurse; cope appropriately.
+
+ -- Ian Jackson <ian@davenant.greenend.org.uk> Sat, 5 Aug 2006 15:34:03 +0100
+
chiark-utils (4.1.3) unstable; urgency=low
backup snap remountrocp fixes: