1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #include <string.h> 7 #include "bs_oswrap.h" 8 9 /* 10 * Note: This is a replica of 11 * libUtilv1/bs_oswrap.c:bs_create_folders_in_path() 12 * It exists here only to allow using it without requiring 13 * users to update their simulator version. 14 * It should be removed when libUtilv1 >= v1.12 becomes required 15 * or common enough otherwise 16 * 17 * If missing, attempt to create all folders in a file path 18 * Folders are expected to be separated by '/' 19 * The path is assumed to be a path to either a folder or a file, 20 * but if to a folder, it must end with a '/'. 21 * The remainder of the string after '/' will be ignored 22 * (assuming it is a file name) 23 */ _bs_create_folders_in_path(const char * path)24int _bs_create_folders_in_path(const char *path) { 25 char sep='/'; 26 char *start = (char* )path; 27 28 while (*start == sep) { 29 start++; 30 } 31 char *end_folder = strchr(start, sep); 32 33 while (end_folder != NULL) { 34 *end_folder = 0; 35 int ret = bs_createfolder(path); 36 *end_folder = sep; 37 if (ret != 0) { 38 return 1; 39 } 40 end_folder = strchr(end_folder + 1, sep); 41 } 42 return 0; 43 } 44