[PATCH] stdio: Add %m
Shaun Jackman
sjackman at gmail.com
Tue Jun 20 12:44:47 PDT 2006
On 6/20/06, Rob Landley <rob at landley.net> wrote:
> The difference between bb_error_msg() and bb_perror_msg() is that the p
> version appends the equivalent of ": %m" to its output, except it uses
> strerror() (see libbb/vperror_msg.c for the implementation). So if you can
> shoehorn various error messages to use our libbb macros instead of trying to
> do the strerror() themselves, that'll take care of at least some of the
> problem.
...
Agreed. I like this solution best. Consider this [PATCH 1/11] shell:
Remove %m. I'll leave it up to other concerned citizens to contribute
the remaining ten patches.
$ grep -rl %m . |grep c$ |sed 's/[/][^/]*$//' |sort -u
./coreutils
./e2fsprogs
./init
./libbb
./loginutils
./miscutils
./networking
./networking/udhcp
./scripts
./shell
./sysklogd
Cheers,
Shaun
2006-06-20 Shaun Jackman <sjackman at gmail.com>
* shell/hush.c: Call bb_perror_msg instead of printf("%m").
* shell/lash.c: Ditto.
Index: hush.c
===================================================================
--- hush.c (revision 15341)
+++ hush.c (working copy)
@@ -665,7 +665,7 @@
} else
res = -1;
if (res)
- fprintf(stderr, "read: %m\n");
+ bb_perror_msg("read");
free(var); /* So not move up to avoid breaking errno */
return res;
} else {
Index: lash.c
===================================================================
--- lash.c (revision 15341)
+++ lash.c (working copy)
@@ -236,7 +236,7 @@
else
newdir = child->argv[1];
if (chdir(newdir)) {
- printf("cd: %s: %m\n", newdir);
+ bb_perror_msg("cd: %s", newdir);
return EXIT_FAILURE;
}
cwd = xgetcwd((char *)cwd);
@@ -386,7 +386,7 @@
}
res = putenv(v);
if (res)
- fprintf(stderr, "export: %m\n");
+ bb_perror_msg("export");
#ifdef CONFIG_FEATURE_SH_FANCY_PROMPT
if (strncmp(v, "PS1=", 4)==0)
PS1 = getenv("PS1");
@@ -428,7 +428,7 @@
if((s = strdup(string)))
res = putenv(s);
if (res)
- fprintf(stderr, "read: %m\n");
+ bb_perror_msg("read");
}
else
fgets(string, sizeof(string), stdin);
@@ -1279,7 +1279,7 @@
/* Do not use bb_perror_msg_and_die() here, since we must not
* call exit() but should call _exit() instead */
- fprintf(stderr, "%s: %m\n", child->argv[0]);
+ bb_perror_msg("%s", child->argv[0]);
_exit(EXIT_FAILURE);
}
-------------- next part --------------
2006-06-20 Shaun Jackman <sjackman at gmail.com>
* shell/hush.c: Call bb_perror_msg instead of printf("%m").
* shell/lash.c: Ditto.
Index: shell/hush.c
===================================================================
--- shell/hush.c (revision 15341)
+++ shell/hush.c (working copy)
@@ -665,7 +665,7 @@
} else
res = -1;
if (res)
- fprintf(stderr, "read: %m\n");
+ bb_perror_msg("read");
free(var); /* So not move up to avoid breaking errno */
return res;
} else {
Index: shell/lash.c
===================================================================
--- shell/lash.c (revision 15341)
+++ shell/lash.c (working copy)
@@ -236,7 +236,7 @@
else
newdir = child->argv[1];
if (chdir(newdir)) {
- printf("cd: %s: %m\n", newdir);
+ bb_perror_msg("cd: %s", newdir);
return EXIT_FAILURE;
}
cwd = xgetcwd((char *)cwd);
@@ -386,7 +386,7 @@
}
res = putenv(v);
if (res)
- fprintf(stderr, "export: %m\n");
+ bb_perror_msg("export");
#ifdef CONFIG_FEATURE_SH_FANCY_PROMPT
if (strncmp(v, "PS1=", 4)==0)
PS1 = getenv("PS1");
@@ -428,7 +428,7 @@
if((s = strdup(string)))
res = putenv(s);
if (res)
- fprintf(stderr, "read: %m\n");
+ bb_perror_msg("read");
}
else
fgets(string, sizeof(string), stdin);
@@ -1279,7 +1279,7 @@
/* Do not use bb_perror_msg_and_die() here, since we must not
* call exit() but should call _exit() instead */
- fprintf(stderr, "%s: %m\n", child->argv[0]);
+ bb_perror_msg("%s", child->argv[0]);
_exit(EXIT_FAILURE);
}
More information about the busybox
mailing list