commit: 1b6301ea49cfc12272182aab88d5a93b9bf5ce03
parent b2f246b5a879de21b1ae08b2498fdc29fe11c7af
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 17 Mar 2025 19:54:26 +0100
cmd/getconf: fix error messages
Diffstat:
M | cmd/getconf.c | 111 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
1 file changed, 57 insertions(+), 54 deletions(-)
diff --git a/cmd/getconf.c b/cmd/getconf.c
@@ -20,19 +20,19 @@
static int
print_system_var(const char *var)
{
- for(size_t name = 0; name < (sizeof(confstr_vars) / sizeof(*confstr_vars)); name++)
+ for(size_t i = 0; i < (sizeof(confstr_vars) / sizeof(*confstr_vars)); i++)
{
- if(strcmp(confstr_vars[name].name, var) != 0) continue;
+ if(strcmp(confstr_vars[i].name, var) != 0) continue;
errno = 0;
- size_t buflen = confstr(confstr_vars[name].value, (char *)NULL, 0);
+ size_t buflen = confstr(confstr_vars[i].value, (char *)NULL, 0);
if(buflen == 0)
{
if(errno != 0)
{
fprintf(stderr,
- "getconf: error: confstr(%zd /* \"%s\" */, NULL, 0): %s\n",
- name,
+ "getconf: error: confstr(%d /* \"%s\" */, NULL, 0): %s\n",
+ confstr_vars[i].value,
var,
strerror(errno));
return 1;
@@ -54,14 +54,14 @@ print_system_var(const char *var)
}
errno = 0;
- size_t ret = confstr(confstr_vars[name].value, buf, buflen);
+ size_t ret = confstr(confstr_vars[i].value, buf, buflen);
if(ret == 0)
{
if(errno != 0)
{
fprintf(stderr,
- "getconf: error: confstr(%zd /* \"%s\" */, buf, %zd): %s\n",
- name,
+ "getconf: error: confstr(%d /* \"%s\" */, buf, %zd): %s\n",
+ confstr_vars[i].value,
var,
buflen,
strerror(errno));
@@ -79,20 +79,23 @@ print_system_var(const char *var)
return 0;
}
- for(size_t name = 0; name < (sizeof(sysconf_vars) / sizeof(*sysconf_vars)); name++)
+ for(size_t i = 0; i < (sizeof(sysconf_vars) / sizeof(*sysconf_vars)); i++)
{
- if(strcmp(sysconf_vars[name].name, var) != 0) continue;
+ if(strcmp(sysconf_vars[i].name, var) != 0) continue;
errno = 0;
- long ret = sysconf((int)(sysconf_vars[name].value));
+ long ret = sysconf((int)(sysconf_vars[i].value));
if(ret == -1 && errno != 0)
{
- fprintf(
- stderr, "getconf: error: sysconf(%zd /* \"%s\" */): %s\n", name, var, strerror(errno));
+ fprintf(stderr,
+ "getconf: error: sysconf(%d /* \"%s\" */): %s\n",
+ sysconf_vars[i].value,
+ var,
+ strerror(errno));
return 1;
}
- if(ret == -1) ret = sysconf_vars[name].limit_h;
+ if(ret == -1) ret = sysconf_vars[i].limit_h;
if(ret == -1)
{
@@ -104,11 +107,11 @@ print_system_var(const char *var)
return 0;
}
- for(size_t name = 0; name < (sizeof(limits_vars) / sizeof(*limits_vars)); name++)
+ for(size_t i = 0; i < (sizeof(limits_vars) / sizeof(*limits_vars)); i++)
{
- if(strcmp(limits_vars[name].name, var) != 0) continue;
+ if(strcmp(limits_vars[i].name, var) != 0) continue;
- long ret = limits_vars[name].limit_h;
+ long ret = limits_vars[i].limit_h;
if(ret == -1)
{
@@ -154,25 +157,25 @@ main(int argc, char *argv[])
{
char *buf = NULL;
size_t buflen = 0;
- for(size_t name = 0; name < (sizeof(confstr_vars) / sizeof(*confstr_vars)); name++)
+ for(size_t i = 0; i < (sizeof(confstr_vars) / sizeof(*confstr_vars)); i++)
{
errno = 0;
- size_t buflen_ret = confstr(confstr_vars[name].value, (char *)NULL, 0);
+ size_t buflen_ret = confstr(confstr_vars[i].value, (char *)NULL, 0);
if(buflen_ret == 0)
{
if(errno != 0)
{
fprintf(stderr,
- "getconf: error: confstr(%zd /* \"%s\" */, NULL, 0): %s\n",
- name,
- confstr_vars[name].name,
+ "getconf: error: confstr(%d /* \"%s\" */, NULL, 0): %s\n",
+ confstr_vars[i].value,
+ confstr_vars[i].name,
strerror(errno));
free(buf);
return 1;
}
/* undefined */
- printf("%s\n", confstr_vars[name].name);
+ printf("%s\n", confstr_vars[i].name);
continue;
}
@@ -194,15 +197,15 @@ main(int argc, char *argv[])
}
errno = 0;
- size_t ret = confstr(confstr_vars[name].value, buf, buflen);
+ size_t ret = confstr(confstr_vars[i].value, buf, buflen);
if(ret == 0)
{
if(errno != 0)
{
fprintf(stderr,
- "getconf: error: confstr(%zd /* \"%s\" */, buf, %zd): %s\n",
- name,
- confstr_vars[name].name,
+ "getconf: error: confstr(%d /* \"%s\" */, buf, %zd): %s\n",
+ confstr_vars[i].value,
+ confstr_vars[i].name,
buflen,
strerror(errno));
free(buf);
@@ -210,78 +213,78 @@ main(int argc, char *argv[])
}
/* undefined */
- printf("%s\n", confstr_vars[name].name);
+ printf("%s\n", confstr_vars[i].name);
continue;
}
- printf("%s = ", confstr_vars[name].name);
+ printf("%s = ", confstr_vars[i].name);
fwrite(buf, buflen_ret, 1, stdout);
printf("\n");
}
free(buf);
- for(size_t name = 0; name < (sizeof(sysconf_vars) / sizeof(*sysconf_vars)); name++)
+ for(size_t i = 0; i < (sizeof(sysconf_vars) / sizeof(*sysconf_vars)); i++)
{
errno = 0;
- long ret = sysconf((int)(sysconf_vars[name].value));
+ long ret = sysconf((int)(sysconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
- "getconf: error: sysconf(%zd /* \"%s\" */): %s\n",
- name,
- argv[0],
+ "getconf: error: sysconf(%d /* \"%s\" */): %s\n",
+ confstr_vars[i].value,
+ confstr_vars[i].name,
strerror(errno));
return 1;
}
- if(ret == -1) ret = sysconf_vars[name].limit_h;
+ if(ret == -1) ret = sysconf_vars[i].limit_h;
if(ret == -1)
{
/* undefined */
- printf("%s\n", sysconf_vars[name].name);
+ printf("%s\n", sysconf_vars[i].name);
continue;
}
- printf("%s = %ld\n", sysconf_vars[name].name, ret);
+ printf("%s = %ld\n", sysconf_vars[i].name, ret);
}
- for(size_t name = 0; name < (sizeof(limits_vars) / sizeof(*limits_vars)); name++)
+ for(size_t i = 0; i < (sizeof(limits_vars) / sizeof(*limits_vars)); i++)
{
- long ret = limits_vars[name].limit_h;
+ long ret = limits_vars[i].limit_h;
if(ret == -1)
{
/* undefined */
- printf("%s\n", limits_vars[name].name);
+ printf("%s\n", limits_vars[i].name);
continue;
}
- printf("%s = %ld\n", limits_vars[name].name, ret);
+ printf("%s = %ld\n", limits_vars[i].name, ret);
}
return 0;
}
else if(!o_all && argc == 2)
{
- for(size_t name = 0; name < (sizeof(pathconf_vars) / sizeof(*pathconf_vars)); name++)
+ for(size_t i = 0; i < (sizeof(pathconf_vars) / sizeof(*pathconf_vars)); i++)
{
- if(strcmp(pathconf_vars[name].name, argv[0]) != 0) continue;
+ if(strcmp(pathconf_vars[i].name, argv[0]) != 0) continue;
errno = 0;
- long ret = pathconf(argv[1], (int)(pathconf_vars[name].value));
+ long ret = pathconf(argv[1], (int)(pathconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
- "getconf: error: pathconf(\"%s\", %zd /* \"%s\" */): %s\n",
+ "getconf: error: pathconf(\"%s\", %d /* \"%s\" */): %s\n",
argv[1],
- name,
+ pathconf_vars[i].value,
argv[0],
strerror(errno));
return 1;
}
- if(ret == -1) ret = sysconf_vars[name].limit_h;
+ if(ret == -1) ret = sysconf_vars[i].limit_h;
printf("%ld\n", ret);
return 0;
@@ -292,23 +295,23 @@ main(int argc, char *argv[])
}
else if(o_all && argc == 1)
{
- for(size_t name = 0; name < (sizeof(pathconf_vars) / sizeof(*pathconf_vars)); name++)
+ for(size_t i = 0; i < (sizeof(pathconf_vars) / sizeof(*pathconf_vars)); i++)
{
errno = 0;
- long ret = pathconf(argv[1], (int)(pathconf_vars[name].value));
+ long ret = pathconf(argv[0], (int)(pathconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
- "getconf: error: pathconf(\"%s\", %zd /* \"%s\" */): %s\n",
- argv[1],
- name,
+ "getconf: error: pathconf(\"%s\", %d /* \"%s\" */): %s\n",
argv[0],
+ pathconf_vars[i].value,
+ pathconf_vars[i].name,
strerror(errno));
return 1;
}
- if(ret == -1) ret = sysconf_vars[name].limit_h;
+ if(ret == -1) ret = sysconf_vars[i].limit_h;
- printf("%s = %ld\n", pathconf_vars[name].name, ret);
+ printf("%s = %ld\n", pathconf_vars[i].name, ret);
}
return 0;