MCPcopy Create free account
hub / github.com/Motion-Project/motion / mycreate_path

Function mycreate_path

src/util.c:263–295  ·  view source on GitHub ↗

* mycreate_path * * This function creates a whole path, like mkdir -p. Example paths: * this/is/an/example/ * /this/is/an/example/ * Warning: a path *must* end with a slash! * * Parameters: * * cnt - current thread's context structure (for logging) * path - the path to create * * Returns: 0 on success, -1 on failure */

Source from the content-addressed store, hash-verified

261 * Returns: 0 on success, -1 on failure
262 */
263int mycreate_path(const char *path)
264{
265 char *start;
266 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
267
268 if (path[0] == '/') {
269 start = strchr(path + 1, '/');
270 } else {
271 start = strchr(path, '/');
272 }
273
274 while (start) {
275 char *buffer = mystrdup(path);
276 buffer[start-path] = 0x00;
277
278 if (mkdir(buffer, mode) == -1 && errno != EEXIST) {
279 MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO
280 ,_("Problem creating directory %s"), buffer);
281 free(buffer);
282 return -1;
283 }
284
285 start = strchr(start + 1, '/');
286
287 if (!start) {
288 MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("creating directory %s"), buffer);
289 }
290
291 free(buffer);
292 }
293
294 return 0;
295}
296
297/**
298 * myfopen

Callers 3

event_create_extpipeFunction · 0.85
ffmpeg_set_outputfileFunction · 0.85
myfopenFunction · 0.85

Calls 1

mystrdupFunction · 0.85

Tested by

no test coverage detected