From 8078b707f9d757622b028a4fd494d6f7e7e2a1ed Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 15 Mar 2019 11:23:16 -0500 Subject: getconf: Use statvfs(2) and statfs(2) on Linux This allows us to have a correct, variable NAME_MAX (and others). --- getconf/getconf.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/getconf/getconf.c b/getconf/getconf.c index 9517925..5a9da22 100644 --- a/getconf/getconf.c +++ b/getconf/getconf.c @@ -6,6 +6,10 @@ */ +#ifdef __linux__ +# include /* statvfs */ +# include /* statfs */ +#endif #include /* errno */ #include /* limit_vars */ #include /* bool type and true/false */ @@ -544,6 +548,45 @@ int do_path_var(char *environment, char *path_var, char *pathname) errno = 0; +#ifdef __linux__ + switch(path_vars[var].value) + { + case _PC_REC_XFER_ALIGN: + case _PC_ALLOC_SIZE_MIN: + { + struct statvfs vfsres; + if(statvfs(pathname, &vfsres) == 0) + { + result = vfsres.f_frsize; + printf("%ld\n", result); + return 0; + } + break; + } + case _PC_REC_MIN_XFER_SIZE: + { + struct statvfs vfsres; + if(statvfs(pathname, &vfsres) == 0) + { + result = vfsres.f_bsize; + printf("%ld\n", result); + return 0; + } + break; + } + case _PC_NAME_MAX: + { + struct statfs fsres; + if(statfs(pathname, &fsres) == 0) + { + result = fsres.f_namelen; + printf("%ld\n", result); + return 0; + } + break; + } + } +#endif result = pathconf(pathname, path_vars[var].value); if(errno != 0) { -- cgit v1.2.3-70-g09d2