MCPcopy Create free account
hub / github.com/Entware/Entware / make_parent_dir

Function make_parent_dir

scripts/config/confdata.c:93–125  ·  view source on GitHub ↗

* Create the parent directory of the given path. * * For example, if 'include/config/auto.conf' is given, create 'include/config'. */

Source from the content-addressed store, hash-verified

91 * For example, if 'include/config/auto.conf' is given, create 'include/config'.
92 */
93static int make_parent_dir(const char *path)
94{
95 char tmp[PATH_MAX + 1];
96 char *p;
97
98 strncpy(tmp, path, sizeof(tmp));
99 tmp[sizeof(tmp) - 1] = 0;
100
101 /* Remove the base name. Just return if nothing is left */
102 p = strrchr(tmp, '/');
103 if (!p)
104 return 0;
105 *(p + 1) = 0;
106
107 /* Just in case it is an absolute path */
108 p = tmp;
109 while (*p == '/')
110 p++;
111
112 while ((p = strchr(p, '/'))) {
113 *p = 0;
114
115 /* skip if the directory exists */
116 if (!is_dir(tmp) && mkdir(tmp, 0755))
117 return -1;
118
119 *p = '/';
120 while (*p == '/')
121 p++;
122 }
123
124 return 0;
125}
126
127static char depfile_path[PATH_MAX];
128static size_t depfile_prefix_len;

Callers 3

conf_writeFunction · 0.85
conf_write_autoconf_cmdFunction · 0.85
__conf_write_autoconfFunction · 0.85

Calls 1

is_dirFunction · 0.85

Tested by

no test coverage detected