#include #include #include #include #include #include #include #include #include "engine.h" #include "config.h" #include "utils.h" char *gethome() { char *buf; struct passwd *mypass; uid_t me; me = getuid(); mypass = getpwuid(me); buf = strdup(mypass->pw_dir); if(!buf) err_quit("No memory available\n"); return buf; } char *returnPathdir(void) { char *buf1, *buf; buf = gethome(); buf1 = calloc(PATH_MAX + 1, sizeof(char)); if(!buf1) err_quit("No memory available\n"); snprintf(buf1, PATH_MAX, "%s/.ermixer/", buf); free(buf); return buf1; } int exist(const char *pathname) { DIR *ermixer; ermixer = opendir(pathname); if(!ermixer) return ERROR; closedir(ermixer); return SUCCESS; } void createDir(const char *pathname) { fprintf(stdout, "Creating %s\n", pathname); if((mkdir(pathname, 0740)) == ERROR) { fprintf(stderr, "Unable to Create %s\n", pathname); exit(1); } fprintf(stdout, "Done\n"); } void checkDir() { char *buf = NULL; buf = returnPathdir(); if(exist(buf) == ERROR) { fprintf(stderr, "%s don't exist!!! I search to create it\n", buf); createDir(buf); } free(buf); }