Changed the err and warns to macros
err and warn are BSD format but they are not recommended by library developers. However their consiseness is useful! The solution is to use some macros that create xerr etc which then just map to the error() function. The next problem is error() uses program_invocation_name so we set this to program_invovation_short_name This is a global set but seems to be the convention (or at least errors are on the short name only) used everywhere else.
This commit is contained in:
57
sysctl.c
57
sysctl.c
@@ -70,7 +70,7 @@ static void slashdot(char *restrict p, char old, char new){
|
||||
while(p){
|
||||
char c = *p;
|
||||
if((*(p+1) == '/' || *(p+1) == '.') && warned) {
|
||||
warnx(_("separators should not be repeated: %s"), p);
|
||||
xwarnx(_("separators should not be repeated: %s"), p);
|
||||
warned = 0;
|
||||
}
|
||||
if(c==old) *p=new;
|
||||
@@ -156,7 +156,7 @@ static int ReadSetting(const char *restrict const name) {
|
||||
struct stat ts;
|
||||
|
||||
if (!name || !*name) {
|
||||
warnx(_("\"%s\" is an unknown key"), name);
|
||||
xwarnx(_("\"%s\" is an unknown key"), name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ static int ReadSetting(const char *restrict const name) {
|
||||
|
||||
if (stat(tmpname, &ts) < 0) {
|
||||
if (!IgnoreError) {
|
||||
warn(_("cannot stat %s"), tmpname);
|
||||
xwarn(_("cannot stat %s"), tmpname);
|
||||
rc = -1;
|
||||
}
|
||||
goto out;
|
||||
@@ -204,16 +204,16 @@ static int ReadSetting(const char *restrict const name) {
|
||||
switch(errno) {
|
||||
case ENOENT:
|
||||
if (!IgnoreError) {
|
||||
warnx(_("\"%s\" is an unknown key"), outname);
|
||||
xwarnx(_("\"%s\" is an unknown key"), outname);
|
||||
rc = -1;
|
||||
}
|
||||
break;
|
||||
case EACCES:
|
||||
warnx(_("permission denied on key '%s'"), outname);
|
||||
xwarnx(_("permission denied on key '%s'"), outname);
|
||||
rc = -1;
|
||||
break;
|
||||
default:
|
||||
warn(_("reading key \"%s\""), outname);
|
||||
xwarn(_("reading key \"%s\""), outname);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ static int ReadSetting(const char *restrict const name) {
|
||||
} else {
|
||||
switch(errno) {
|
||||
case EACCES:
|
||||
warnx(_("permission denied on key '%s'"), outname);
|
||||
xwarnx(_("permission denied on key '%s'"), outname);
|
||||
rc = -1;
|
||||
break;
|
||||
case EISDIR:{
|
||||
@@ -254,7 +254,7 @@ static int ReadSetting(const char *restrict const name) {
|
||||
goto out;
|
||||
}
|
||||
default:
|
||||
warnx(_("reading key \"%s\""), outname);
|
||||
xwarnx(_("reading key \"%s\""), outname);
|
||||
rc = -1;
|
||||
case 0:
|
||||
break;
|
||||
@@ -284,7 +284,7 @@ static int DisplayAll(const char *restrict const path) {
|
||||
dp = opendir(path);
|
||||
|
||||
if (!dp) {
|
||||
warnx(_("unable to open directory \"%s\""), path);
|
||||
xwarnx(_("unable to open directory \"%s\""), path);
|
||||
rc = -1;
|
||||
} else {
|
||||
readdir(dp); // skip .
|
||||
@@ -295,7 +295,7 @@ static int DisplayAll(const char *restrict const path) {
|
||||
sprintf(tmpdir, "%s%s", path, de->d_name);
|
||||
rc2 = stat(tmpdir, &ts);
|
||||
if (rc2 != 0) {
|
||||
warn(_("cannot stat %s"), tmpdir);
|
||||
xwarn(_("cannot stat %s"), tmpdir);
|
||||
} else {
|
||||
if (S_ISDIR(ts.st_mode)) {
|
||||
strcat(tmpdir, "/");
|
||||
@@ -333,14 +333,14 @@ static int WriteSetting(const char *setting) {
|
||||
equals = strchr(setting, '=');
|
||||
|
||||
if (!equals) {
|
||||
warnx(_("\"%s\" must be of the form name=value"), setting);
|
||||
xwarnx(_("\"%s\" must be of the form name=value"), setting);
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = equals + 1; /* point to the value in name=value */
|
||||
|
||||
if (!*name || !*value || name == equals) {
|
||||
warnx(_("Malformed setting \"%s\""), setting);
|
||||
xwarnx(_("Malformed setting \"%s\""), setting);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -359,19 +359,19 @@ static int WriteSetting(const char *setting) {
|
||||
|
||||
if (stat(tmpname, &ts) < 0) {
|
||||
if (!IgnoreError) {
|
||||
warn(_("cannot stat %s"), tmpname);
|
||||
xwarn(_("cannot stat %s"), tmpname);
|
||||
rc = -1;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((ts.st_mode & S_IWUSR) == 0) {
|
||||
warn(_("setting key \"%s\""), outname);
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (S_ISDIR(ts.st_mode)) {
|
||||
warn(_("setting key \"%s\""), outname);
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -381,28 +381,28 @@ static int WriteSetting(const char *setting) {
|
||||
switch(errno) {
|
||||
case ENOENT:
|
||||
if (!IgnoreError) {
|
||||
warnx(_("\"%s\" is an unknown key"), outname);
|
||||
xwarnx(_("\"%s\" is an unknown key"), outname);
|
||||
rc = -1;
|
||||
}
|
||||
break;
|
||||
case EACCES:
|
||||
warnx(_("permission denied on key '%s'"), outname);
|
||||
xwarnx(_("permission denied on key '%s'"), outname);
|
||||
rc = -1;
|
||||
break;
|
||||
default:
|
||||
warn(_("setting key \"%s\""), outname);
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
rc = fprintf(fp, "%s\n", value);
|
||||
if (rc < 0) {
|
||||
warn(_("setting key \"%s\""), outname);
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
fclose(fp);
|
||||
} else {
|
||||
rc=fclose(fp);
|
||||
if (rc != 0)
|
||||
warn(_("setting key \"%s\""), outname);
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
}
|
||||
if (rc==0 && !Quiet) {
|
||||
if (NameOnly) {
|
||||
@@ -461,7 +461,7 @@ static int Preload(const char *restrict const filename) {
|
||||
;
|
||||
|
||||
if (!fp) {
|
||||
warn(_("cannot open \"%s\""), filename);
|
||||
xwarn(_("cannot open \"%s\""), filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ static int Preload(const char *restrict const filename) {
|
||||
|
||||
name = strtok(t, "=");
|
||||
if (!name || !*name) {
|
||||
warnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
|
||||
xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ static int Preload(const char *restrict const filename) {
|
||||
|
||||
value = strtok(NULL, "\n\r");
|
||||
if (!value || !*value) {
|
||||
warnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
|
||||
xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -610,9 +610,10 @@ int main(int argc, char *argv[])
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
program_invocation_name = program_invocation_short_name;
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
PrintName = true;
|
||||
PrintNewline = true;
|
||||
@@ -691,11 +692,11 @@ int main(int argc, char *argv[])
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
errx(EXIT_FAILURE, _("no variables specified\n"
|
||||
xerrx(EXIT_FAILURE, _("no variables specified\n"
|
||||
"Try `%s --help' for more information."),
|
||||
program_invocation_short_name);
|
||||
if (NameOnly && Quiet)
|
||||
errx(EXIT_FAILURE, _("options -N and -q cannot coexist\n"
|
||||
xerrx(EXIT_FAILURE, _("options -N and -q cannot coexist\n"
|
||||
"Try `%s --help' for more information."),
|
||||
program_invocation_short_name);
|
||||
|
||||
|
Reference in New Issue
Block a user