* 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 */
| 261 | * Returns: 0 on success, -1 on failure |
| 262 | */ |
| 263 | int 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 |
no test coverage detected