2023-10-31 09:53:32 +00:00
|
|
|
#ifndef _GET_STAT_H
|
|
|
|
#define _GET_STAT_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
int mu_get_stat(const char *prog_name, const char *path, struct stat *stat_path) {
|
|
|
|
if (stat(path, stat_path)) {
|
2023-11-12 10:02:52 +00:00
|
|
|
if (prog_name != NULL)
|
2023-12-23 13:45:31 +00:00
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog_name, path, strerror(errno));
|
2023-11-12 10:02:52 +00:00
|
|
|
|
2023-10-31 09:53:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mu_get_lstat(const char *prog_name, const char *path, struct stat *stat_path) {
|
|
|
|
if (lstat(path, stat_path)) {
|
2023-11-12 10:02:52 +00:00
|
|
|
if (prog_name != NULL)
|
2023-12-23 13:45:31 +00:00
|
|
|
fprintf(stderr, "%s: %s: %s\n", prog_name, path, strerror(errno));
|
2023-11-12 10:02:52 +00:00
|
|
|
|
2023-10-31 09:53:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-26 17:06:39 +00:00
|
|
|
int mu_get_stats(const char *restrict prog_name, int flag, const char *restrict path, struct stat *restrict stat_path) {
|
2023-11-19 08:41:47 +00:00
|
|
|
if (flag)
|
|
|
|
return mu_get_lstat(prog_name, path, stat_path);
|
|
|
|
|
|
|
|
else
|
|
|
|
return mu_get_stat(prog_name, path, stat_path);
|
|
|
|
}
|
|
|
|
|
2023-10-31 09:53:32 +00:00
|
|
|
#endif
|