path.c (976e3645923bdd2fe7893aae33fd7a21098bfb28) | path.c (41204da4c16071be9090940b18f566832d46becc) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * I'm tired of doing "vsnprintf()" etc just to open a 4 * file, so here's a "return static buffer with printf" 5 * interface for paths. 6 * 7 * It's obviously not thread-safe. Sue me. But it's quite 8 * useful for doing things like --- 72 unchanged lines hidden (view full) --- 81} 82 83/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ 84bool is_directory(const char *base_path, const struct dirent *dent) 85{ 86 char path[PATH_MAX]; 87 struct stat st; 88 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * I'm tired of doing "vsnprintf()" etc just to open a 4 * file, so here's a "return static buffer with printf" 5 * interface for paths. 6 * 7 * It's obviously not thread-safe. Sue me. But it's quite 8 * useful for doing things like --- 72 unchanged lines hidden (view full) --- 81} 82 83/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */ 84bool is_directory(const char *base_path, const struct dirent *dent) 85{ 86 char path[PATH_MAX]; 87 struct stat st; 88 |
89 sprintf(path, "%s/%s", base_path, dent->d_name); | 89 snprintf(path, sizeof(path), "%s/%s", base_path, dent->d_name); |
90 if (stat(path, &st)) 91 return false; 92 93 return S_ISDIR(st.st_mode); 94} | 90 if (stat(path, &st)) 91 return false; 92 93 return S_ISDIR(st.st_mode); 94} |
95 96bool is_executable_file(const char *base_path, const struct dirent *dent) 97{ 98 char path[PATH_MAX]; 99 struct stat st; 100 101 snprintf(path, sizeof(path), "%s/%s", base_path, dent->d_name); 102 if (stat(path, &st)) 103 return false; 104 105 return !S_ISDIR(st.st_mode) && (st.st_mode & S_IXUSR); 106} |
|