| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | #ifndef V_ALPM_NATIVE_STORAGE_H |
| 3 | #define V_ALPM_NATIVE_STORAGE_H |
| 4 | #include <stdint.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <dirent.h> |
| 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
| 9 | |
| 10 | typedef struct v_alpm_storage_info { |
| 11 | uint32_t mode; |
| 12 | uint32_t uid; |
| 13 | uint32_t gid; |
| 14 | uint64_t links; |
| 15 | } v_alpm_storage_info; |
| 16 | |
| 17 | static int v_alpm_storage_stat(int directory, const char *name, v_alpm_storage_info *result) { |
| 18 | struct stat info; |
| 19 | if(fstatat(directory, name, &info, AT_SYMLINK_NOFOLLOW) != 0) { return -1; } |
| 20 | result->mode = info.st_mode; |
| 21 | result->uid = info.st_uid; |
| 22 | result->gid = info.st_gid; |
| 23 | result->links = info.st_nlink; |
| 24 | return 0; |
| 25 | } |
| 26 | static int v_alpm_storage_next(DIR *directory, char **name) { |
| 27 | struct dirent *entry; |
| 28 | errno = 0; |
| 29 | entry = readdir(directory); |
| 30 | if(!entry) { return errno ? -1 : 0; } |
| 31 | *name = entry->d_name; |
| 32 | return 1; |
| 33 | } |
| 34 | #endif |
| 35 | |