| 182 | } |
| 183 | |
| 184 | int getPathInfo(const char *path, uint64_t *size, uint32_t *folders, |
| 185 | uint32_t *files, int (* handler)(const char *path)) { |
| 186 | SceUID dfd = sceIoDopen(path); |
| 187 | if (dfd >= 0) { |
| 188 | int res = 0; |
| 189 | |
| 190 | do { |
| 191 | SceIoDirent dir; |
| 192 | memset(&dir, 0, sizeof(SceIoDirent)); |
| 193 | |
| 194 | res = sceIoDread(dfd, &dir); |
| 195 | if (res > 0) { |
| 196 | char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2); |
| 197 | snprintf(new_path, MAX_PATH_LENGTH, "%s%s%s", path, hasEndSlash(path) ? "" : "/", dir.d_name); |
| 198 | |
| 199 | if (handler && handler(new_path)) { |
| 200 | free(new_path); |
| 201 | continue; |
| 202 | } |
| 203 | |
| 204 | if (SCE_S_ISDIR(dir.d_stat.st_mode)) { |
| 205 | int ret = getPathInfo(new_path, size, folders, files, handler); |
| 206 | if (ret <= 0) { |
| 207 | free(new_path); |
| 208 | sceIoDclose(dfd); |
| 209 | return ret; |
| 210 | } |
| 211 | } else { |
| 212 | if (size) |
| 213 | (*size) += dir.d_stat.st_size; |
| 214 | |
| 215 | if (files) |
| 216 | (*files)++; |
| 217 | } |
| 218 | |
| 219 | free(new_path); |
| 220 | } |
| 221 | } while (res > 0); |
| 222 | |
| 223 | sceIoDclose(dfd); |
| 224 | |
| 225 | if (folders) |
| 226 | (*folders)++; |
| 227 | } else { |
| 228 | if (handler && handler(path)) |
| 229 | return 1; |
| 230 | |
| 231 | if (size) { |
| 232 | SceIoStat stat; |
| 233 | memset(&stat, 0, sizeof(SceIoStat)); |
| 234 | |
| 235 | int res = sceIoGetstat(path, &stat); |
| 236 | if (res < 0) |
| 237 | return res; |
| 238 | |
| 239 | (*size) += stat.st_size; |
| 240 | } |
| 241 |
no test coverage detected