nspkg / engine / native_storage.h
34 lines · 32 sloc · 920 bytes · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
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
10typedef 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
17static 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}
26static 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