/* . * L__ Procedures * | L__ 1h_workout.you86 * | L__ 15m_workout.you86 * | L__ math_homework.you86 * | L__ grocery_shopping.you86 * | * L__ DailyStack * L__ 02.09.2021 * L__ ParentProcedures.you86 * L__ result-1h_workout.png * L__ result-math_homework.docx */ #include #include #include #include #include #include #define ROOT_DIR "/Documents/You86/" #define PROCEDURES_DIR ROOT_DIR"Procedures/" #define DAILY_STACK_DIR ROOT_DIR"DailyStack/" void createDir(char *); void initFiles() { createDir(ROOT_DIR); createDir(PROCEDURES_DIR); createDir(DAILY_STACK_DIR); } void createDir(char *p_path) { char *p_tilde = getenv("HOME"); int tildeLen = strlen(p_tilde), pathLen = strlen(p_path); char fullPath[tildeLen + pathLen]; for (int i = 0; i < tildeLen + pathLen; i++) fullPath[i] = (i < tildeLen) ? p_tilde[i] : p_path[i - tildeLen]; int ret = mkdir(fullPath, S_IRWXU); if (ret == -1) { switch (errno) { case EEXIST: return; case EACCES : printf("The parent directory does not allow write for %s", fullPath); break; case ENAMETOOLONG: printf("Pathname \"%s\" is too long", fullPath); break; default: perror("mkdir"); printf("Path: \"%s\"\n", fullPath); break; } exit(EXIT_FAILURE); } }