Removed utils_split(), strtok_r() is now used instead

This commit is contained in:
Scoopta
2019-11-04 22:41:53 -08:00
parent 2ab1c53b4d
commit 07cb2a65a7
5 changed files with 33 additions and 52 deletions

View File

@@ -135,17 +135,16 @@ void wofi_drun_init() {
data_dirs = "/usr/local/share:/usr/share";
}
char* dirs = utils_concat(3, data_home, ":", data_dirs);
char* original_dirs = dirs;
free(data_home);
size_t colon_count = utils_split(dirs, ':');
for(size_t count = 0; count < colon_count; ++count) {
char* app_dir = utils_concat(2, dirs, "/applications");
char* save_ptr;
char* str = strtok_r(dirs, ":", &save_ptr);
do {
char* app_dir = utils_concat(2, str, "/applications");
insert_dir(app_dir, cached, entries);
dirs += strlen(dirs) + 1;
free(app_dir);
}
free(original_dirs);
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
free(dirs);
map_free(cached);
map_free(entries);
}

View File

@@ -36,19 +36,20 @@ void wofi_run_init() {
free(cache);
char* path = strdup(getenv("PATH"));
char* original_path = path;
size_t colon_count = utils_split(path, ':');
for(size_t count = 0; count < colon_count; ++count) {
DIR* dir = opendir(path);
char* save_ptr;
char* str = strtok_r(path, ":", &save_ptr);
do {
DIR* dir = opendir(str);
if(dir == NULL) {
goto cont;
continue;
}
struct dirent* entry;
while((entry = readdir(dir)) != NULL) {
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
char* full_path = utils_concat(3, path, "/", entry->d_name);
char* full_path = utils_concat(3, str, "/", entry->d_name);
struct stat info;
stat(full_path, &info);
if(access(full_path, X_OK) == 0 && S_ISREG(info.st_mode) && !map_contains(cached, full_path)) {
@@ -59,10 +60,8 @@ void wofi_run_init() {
free(full_path);
}
closedir(dir);
cont:
path += strlen(path) + 1;
}
free(original_path);
} while((str = strtok_r(NULL, ":", &save_ptr)) != NULL);
free(path);
map_free(cached);
}