getconf: code cleanup
This commit is contained in:
parent
1f168930d7
commit
7c98789128
188
src/getconf.c
188
src/getconf.c
|
@ -46,7 +46,74 @@ static const getconf_catalog _getconf_catalog_confstr[] =
|
|||
#endif
|
||||
};
|
||||
|
||||
static const getconf_catalog _getconf_catalog_limits[] =
|
||||
static const getconf_catalog _getconf_catalog_pathconf[] =
|
||||
{
|
||||
#ifdef _PC_2_SYMLINKS
|
||||
{ _PC_2_SYMLINKS, "POSIX2_SYMLINKS" },
|
||||
#endif
|
||||
#ifdef _PC_ALLOC_SIZE_MIN
|
||||
{ _PC_ALLOC_SIZE_MIN, "POSIX_ALLOC_SIZE_MIN" },
|
||||
#endif
|
||||
#ifdef _PC_ASYNC_IO
|
||||
{ _PC_ASYNC_IO, "_POSIX_ASYNC_IO" },
|
||||
#endif
|
||||
#ifdef _PC_CHOWN_RESTRICTED
|
||||
{ _PC_CHOWN_RESTRICTED, "POSIX_CHOWN_RESTRICTED" },
|
||||
#endif
|
||||
#ifdef _PC_FILESIZEBITS
|
||||
{ _PC_FILESIZEBITS, "FILESIZEBITS" },
|
||||
#endif
|
||||
#ifdef _PC_LINK_MAX
|
||||
{ _PC_LINK_MAX, "LINK_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_MAX_CANON
|
||||
{ _PC_MAX_CANON, "MAX_CANON" },
|
||||
#endif
|
||||
#ifdef _PC_MAX_INPUT
|
||||
{ _PC_MAX_INPUT, "MAX_INPUT" },
|
||||
#endif
|
||||
#ifdef _PC_NAME_MAX
|
||||
{ _PC_NAME_MAX, "NAME_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_NO_TRUNC
|
||||
{ _PC_NO_TRUNC, "POSIX_NO_TRUNC" },
|
||||
#endif
|
||||
#ifdef _PC_PATH_MAX
|
||||
{ _PC_PATH_MAX, "PATH_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_PIPE_BUF
|
||||
{ _PC_PIPE_BUF, "PIPE_BUF" },
|
||||
#endif
|
||||
#ifdef _PC_PRIO_IO
|
||||
{ _PC_PRIO_IO, "_POSIX_PRIO_IO" },
|
||||
#endif
|
||||
#ifdef _PC_REC_INCR_XFER_SIZE
|
||||
{ _PC_REC_INCR_XFER_SIZE,"POSIX_REC_INCR_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_MAX_XFER_SIZE
|
||||
{ _PC_REC_MAX_XFER_SIZE,"POSIX_REC_MAX_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_MIN_XFER_SIZE
|
||||
{ _PC_REC_MIN_XFER_SIZE,"POSIX_REC_MIN_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_XFER_ALIGN
|
||||
{ _PC_REC_XFER_ALIGN, "POSIX_REC_XFER_ALIGN" },
|
||||
#endif
|
||||
#ifdef _PC_SYMLINK_MAX
|
||||
{ _PC_SYMLINK_MAX, "SYMLINK_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_SYNC_IO
|
||||
{ _PC_SYNC_IO, "_POSIX_SYNC_IO" },
|
||||
#endif
|
||||
#ifdef _PC_TIMESTAMP_RESOLUTION
|
||||
{ _PC_TIMESTAMP_RESOLUTION,"_POSIX_TIMESTAMP_RESOLUTION" },
|
||||
#endif
|
||||
#ifdef _PC_VDISABLE
|
||||
{ _PC_VDISABLE, "_POSIX_VDISABLE" },
|
||||
#endif
|
||||
};
|
||||
|
||||
static const getconf_catalog _getconf_catalog_sysconf[] =
|
||||
{
|
||||
#ifdef _SC_2_C_BIND
|
||||
{ _SC_2_C_BIND, "_POSIX2_C_BIND" },
|
||||
|
@ -155,73 +222,6 @@ static const getconf_catalog _getconf_catalog_limits[] =
|
|||
#endif
|
||||
};
|
||||
|
||||
static const getconf_catalog _getconf_catalog_pathconf[] =
|
||||
{
|
||||
#ifdef _PC_2_SYMLINKS
|
||||
{ _PC_2_SYMLINKS, "POSIX2_SYMLINKS" },
|
||||
#endif
|
||||
#ifdef _PC_ALLOC_SIZE_MIN
|
||||
{ _PC_ALLOC_SIZE_MIN, "POSIX_ALLOC_SIZE_MIN" },
|
||||
#endif
|
||||
#ifdef _PC_ASYNC_IO
|
||||
{ _PC_ASYNC_IO, "_POSIX_ASYNC_IO" },
|
||||
#endif
|
||||
#ifdef _PC_CHOWN_RESTRICTED
|
||||
{ _PC_CHOWN_RESTRICTED, "POSIX_CHOWN_RESTRICTED" },
|
||||
#endif
|
||||
#ifdef _PC_FILESIZEBITS
|
||||
{ _PC_FILESIZEBITS, "FILESIZEBITS" },
|
||||
#endif
|
||||
#ifdef _PC_LINK_MAX
|
||||
{ _PC_LINK_MAX, "LINK_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_MAX_CANON
|
||||
{ _PC_MAX_CANON, "MAX_CANON" },
|
||||
#endif
|
||||
#ifdef _PC_MAX_INPUT
|
||||
{ _PC_MAX_INPUT, "MAX_INPUT" },
|
||||
#endif
|
||||
#ifdef _PC_NAME_MAX
|
||||
{ _PC_NAME_MAX, "NAME_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_NO_TRUNC
|
||||
{ _PC_NO_TRUNC, "POSIX_NO_TRUNC" },
|
||||
#endif
|
||||
#ifdef _PC_PATH_MAX
|
||||
{ _PC_PATH_MAX, "PATH_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_PIPE_BUF
|
||||
{ _PC_PIPE_BUF, "PIPE_BUF" },
|
||||
#endif
|
||||
#ifdef _PC_PRIO_IO
|
||||
{ _PC_PRIO_IO, "_POSIX_PRIO_IO" },
|
||||
#endif
|
||||
#ifdef _PC_REC_INCR_XFER_SIZE
|
||||
{ _PC_REC_INCR_XFER_SIZE,"POSIX_REC_INCR_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_MAX_XFER_SIZE
|
||||
{ _PC_REC_MAX_XFER_SIZE,"POSIX_REC_MAX_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_MIN_XFER_SIZE
|
||||
{ _PC_REC_MIN_XFER_SIZE,"POSIX_REC_MIN_XFER_SIZE" },
|
||||
#endif
|
||||
#ifdef _PC_REC_XFER_ALIGN
|
||||
{ _PC_REC_XFER_ALIGN, "POSIX_REC_XFER_ALIGN" },
|
||||
#endif
|
||||
#ifdef _PC_SYMLINK_MAX
|
||||
{ _PC_SYMLINK_MAX, "SYMLINK_MAX" },
|
||||
#endif
|
||||
#ifdef _PC_SYNC_IO
|
||||
{ _PC_SYNC_IO, "_POSIX_SYNC_IO" },
|
||||
#endif
|
||||
#ifdef _PC_TIMESTAMP_RESOLUTION
|
||||
{ _PC_TIMESTAMP_RESOLUTION,"_POSIX_TIMESTAMP_RESOLUTION" },
|
||||
#endif
|
||||
#ifdef _PC_VDISABLE
|
||||
{ _PC_VDISABLE, "_POSIX_VDISABLE" },
|
||||
#endif
|
||||
};
|
||||
|
||||
static const getconf_catalog _getconf_catalog_values[] =
|
||||
{
|
||||
#ifdef _POSIX2_BC_BASE_MAX
|
||||
|
@ -288,8 +288,8 @@ static int _usage(void);
|
|||
/* functions */
|
||||
/* getconf */
|
||||
static int _getconf_confstr(char const * var);
|
||||
static int _getconf_limits(char const * var);
|
||||
static int _getconf_pathconf(char const * var, char const * path);
|
||||
static int _getconf_sysconf(char const * var);
|
||||
static int _getconf_values(char const * var);
|
||||
|
||||
static int _getconf(char const * specification, char const * var,
|
||||
|
@ -299,7 +299,7 @@ static int _getconf(char const * specification, char const * var,
|
|||
return _getconf_pathconf(var, path);
|
||||
if(strncmp(var, "_SC_", 4) == 0)
|
||||
return _getconf_confstr(var);
|
||||
return _getconf_limits(var);
|
||||
return _getconf_sysconf(var);
|
||||
}
|
||||
|
||||
static int _getconf_confstr(char const * var)
|
||||
|
@ -329,30 +329,6 @@ static int _getconf_confstr(char const * var)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int _getconf_limits(char const * var)
|
||||
{
|
||||
size_t i;
|
||||
size_t cnt = sizeof(_getconf_catalog_limits)
|
||||
/ sizeof(*_getconf_catalog_limits);
|
||||
long value;
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
if(strcmp(_getconf_catalog_limits[i].string, var) == 0)
|
||||
break;
|
||||
if(i == cnt)
|
||||
return _getconf_values(var);
|
||||
errno = 0;
|
||||
if((value = sysconf(_getconf_catalog_limits[i].name)) < 0)
|
||||
{
|
||||
if(errno != 0)
|
||||
return _getconf_error(var, 2);
|
||||
printf("%s", "undefined\n");
|
||||
}
|
||||
else
|
||||
printf("%ld\n", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _getconf_pathconf(char const * var, char const * path)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -371,6 +347,30 @@ static int _getconf_pathconf(char const * var, char const * path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int _getconf_sysconf(char const * var)
|
||||
{
|
||||
size_t i;
|
||||
size_t cnt = sizeof(_getconf_catalog_sysconf)
|
||||
/ sizeof(*_getconf_catalog_sysconf);
|
||||
long value;
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
if(strcmp(_getconf_catalog_sysconf[i].string, var) == 0)
|
||||
break;
|
||||
if(i == cnt)
|
||||
return _getconf_values(var);
|
||||
errno = 0;
|
||||
if((value = sysconf(_getconf_catalog_sysconf[i].name)) < 0)
|
||||
{
|
||||
if(errno != 0)
|
||||
return _getconf_error(var, 2);
|
||||
printf("%s", "undefined\n");
|
||||
}
|
||||
else
|
||||
printf("%ld\n", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _getconf_values(char const * var)
|
||||
{
|
||||
size_t i;
|
||||
|
|
Loading…
Reference in New Issue
Block a user