Lines 17-22
Link Here
|
17 |
*/ |
17 |
*/ |
18 |
|
18 |
|
19 |
#include <config.h> |
19 |
#include <config.h> |
|
|
20 |
#include <limits.h> |
20 |
#include <stdlib.h> |
21 |
#include <stdlib.h> |
21 |
#include <string.h> |
22 |
#include <string.h> |
22 |
#include <stddef.h> |
23 |
#include <stddef.h> |
Lines 27-35
Link Here
|
27 |
#include <dirent.h> |
28 |
#include <dirent.h> |
28 |
#include <scrollkeeper.h> |
29 |
#include <scrollkeeper.h> |
29 |
|
30 |
|
30 |
#define PATHLEN 256 |
|
|
31 |
|
32 |
|
33 |
/* |
31 |
/* |
34 |
* Create a directory. Send errors to appropriate places (STDOUT and log |
32 |
* Create a directory. Send errors to appropriate places (STDOUT and log |
35 |
* file) according to command-line flags. |
33 |
* file) according to command-line flags. |
Lines 55-61
static int sk_mkdir(char *path, mode_t o
Link Here
|
55 |
*/ |
53 |
*/ |
56 |
int sk_mkdir_with_parents(char *fullpath, mode_t options, char outputprefs) |
54 |
int sk_mkdir_with_parents(char *fullpath, mode_t options, char outputprefs) |
57 |
{ |
55 |
{ |
58 |
char path[1024]; |
56 |
char path[PATH_MAX]; |
59 |
char slash[]="/"; |
57 |
char slash[]="/"; |
60 |
char delim[]="/"; |
58 |
char delim[]="/"; |
61 |
char *token, *pathcopy; |
59 |
char *token, *pathcopy; |
Lines 63-77
int sk_mkdir_with_parents(char *fullpath
Link Here
|
63 |
|
61 |
|
64 |
pathcopy = strdup(fullpath); /* Copy b/c strtok edits the string it operates on */ |
62 |
pathcopy = strdup(fullpath); /* Copy b/c strtok edits the string it operates on */ |
65 |
path[0] = '\0'; /* Initialize with end of string null character */ |
63 |
path[0] = '\0'; /* Initialize with end of string null character */ |
66 |
if (pathcopy[0] == slash[0]) sprintf(path, "/"); /* preserve any starting slash */ |
64 |
if (pathcopy[0] == slash[0]) strcpy(path, "/"); /* preserve any starting slash */ |
67 |
|
65 |
|
68 |
token = strtok (pathcopy, delim); |
66 |
token = strtok (pathcopy, delim); |
69 |
delim[0]=slash[0]; |
67 |
delim[0]=slash[0]; |
70 |
while(token != NULL) { |
68 |
while(token != NULL) { |
|
|
69 |
const int path_len = strlen(path); |
71 |
if (strlen(path) == 0 || ((strlen(path) == 1) && (path[0] == slash[0]))) { |
70 |
if (strlen(path) == 0 || ((strlen(path) == 1) && (path[0] == slash[0]))) { |
72 |
sprintf(path, "%s%s", path, token); |
71 |
strncat(path, token, sizeof(path) - path_len - 1); |
73 |
} else { |
72 |
} else { |
74 |
sprintf(path, "%s/%s", path, token); |
73 |
strncat(path, "/", sizeof(path) - path_len - 1); |
|
|
74 |
strncat(path, token, sizeof(path) - path_len - 2); |
75 |
} |
75 |
} |
76 |
if (stat(path, &buf) == -1) { |
76 |
if (stat(path, &buf) == -1) { |
77 |
if (sk_mkdir(path, options, outputprefs) != 0) { |
77 |
if (sk_mkdir(path, options, outputprefs) != 0) { |