version 1.8, 1999/12/04 01:04:14 |
version 1.9, 1999/12/04 21:00:03 |
|
|
Reg1 char *filename; |
Reg1 char *filename; |
bool striplast; |
bool striplast; |
{ |
{ |
char tmpbuf[256]; |
char *tmpbuf; |
Reg2 char *s = tmpbuf; |
|
char *dirv[20]; /* Point to the NULs between elements. */ |
|
Reg3 int i; |
|
Reg4 int dirvp = 0; /* Number of finished entries in dirv. */ |
|
|
|
/* Copy `filename' into `tmpbuf' with a NUL instead of a slash |
if ((tmpbuf = strdup(filename)) == NULL) |
between the directories. */ |
fatal1("out of memory\n"); |
while (*filename) { |
|
if (*filename == '/') { |
if (striplast) { |
filename++; |
char *s = strrchr(tmpbuf, '/'); |
dirv[dirvp++] = s; |
if (s == NULL) |
*s++ = '\0'; |
return; /* nothing to be done */ |
} |
*s = '\0'; |
else { |
|
*s++ = *filename++; |
|
} |
|
} |
} |
*s = '\0'; |
|
dirv[dirvp] = s; |
|
if (striplast) |
|
dirvp--; |
|
if (dirvp < 0) |
|
return; |
|
|
|
strcpy(buf, "mkdir"); |
strcpy(buf, "/bin/mkdir -p "); |
s = buf; |
if (strlcat(buf, tmpbuf, sizeof(buf)) >= sizeof(buf)) |
for (i=0; i<=dirvp; i++) { |
fatal2("buffer too small to hold %.20s...\n", tmpbuf); |
struct stat sbuf; |
|
|
|
if (stat(tmpbuf, &sbuf) && errno == ENOENT) { |
if (system(buf)) |
while (*s) s++; |
pfatal2("%.40s failed", buf); |
*s++ = ' '; |
|
strcpy(s, tmpbuf); |
|
} |
|
*dirv[i] = '/'; |
|
} |
|
if (s != buf) |
|
system(buf); |
|
} |
} |
|
|
/* Make filenames more reasonable. */ |
/* Make filenames more reasonable. */ |