From 2124ffa4985a69339ad91046c1bb2842f61a9ace Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 16 Jul 2023 14:07:33 +0300 Subject: [PATCH] (mc_stat, mc_lstat): define via macro. Signed-off-by: Andrew Borodin --- lib/vfs/interface.c | 59 +++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index 6546f6040..3d43b3919 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -542,47 +542,32 @@ mc_closedir (DIR * dirp) /* --------------------------------------------------------------------------------------------- */ -int -mc_stat (const vfs_path_t * vpath, struct stat *buf) -{ - int result = -1; - const vfs_path_element_t *path_element; +/* *INDENT-OFF* */ - if (vpath == NULL) - return (-1); - - path_element = vfs_path_get_by_index (vpath, -1); - if (vfs_path_element_valid (path_element)) - { - result = path_element->class->stat ? path_element->class->stat (vpath, buf) : -1; - if (result == -1) - errno = path_element->class->name ? vfs_ferrno (path_element->class) : ENOTSUP; - } - - return result; +#define MC_STATOP(name) \ +int mc_##name (const vfs_path_t *vpath, struct stat *buf) \ +{ \ + int result = -1; \ + const vfs_path_element_t *path_element; \ +\ + if (vpath == NULL) \ + return (-1); \ +\ + path_element = vfs_path_get_by_index (vpath, -1); \ + if (vfs_path_element_valid (path_element)) \ + { \ + result = path_element->class->name ? path_element->class->name (vpath, buf) : -1; \ + if (result == -1) \ + errno = path_element->class->name ? vfs_ferrno (path_element->class) : ENOTSUP; \ + } \ +\ + return result; \ } -/* --------------------------------------------------------------------------------------------- */ +MC_STATOP (stat) +MC_STATOP (lstat) -int -mc_lstat (const vfs_path_t * vpath, struct stat *buf) -{ - int result = -1; - const vfs_path_element_t *path_element; - - if (vpath == NULL) - return (-1); - - path_element = vfs_path_get_by_index (vpath, -1); - if (vfs_path_element_valid (path_element)) - { - result = path_element->class->lstat ? path_element->class->lstat (vpath, buf) : -1; - if (result == -1) - errno = path_element->class->name ? vfs_ferrno (path_element->class) : ENOTSUP; - } - - return result; -} +/* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */