1#include <errno.h>
2#include <sys/stat.h>
3
4#include "include/pw.h"
5
6
7[[nodiscard]] bool pw_file_size(PwValuePtr file_name, off_t* result)
8{
9 pw_assert_string(file_name);
10 PW_CSTRING(fname, file_name);
11
12 struct stat statbuf;
13
14 if (stat(fname, &statbuf) == -1) {
15 pw_set_status(PwErrno(errno));
16 return false;
17 }
18 if ( ! (statbuf.st_mode & S_IFREG)) {
19 pw_set_status(PwStatus(PW_ERROR_NOT_REGULAR_FILE));
20 return false;
21 }
22 *result = statbuf.st_size;
23 return true;
24}