Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F174714667
D40799.id123987.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D40799.id123987.diff
View Options
diff --git a/usr.bin/stdbuf/stdbuf.c b/usr.bin/stdbuf/stdbuf.c
--- a/usr.bin/stdbuf/stdbuf.c
+++ b/usr.bin/stdbuf/stdbuf.c
@@ -36,22 +36,38 @@
#define LIBSTDBUF "/usr/lib/libstdbuf.so"
#define LIBSTDBUF32 "/usr/lib32/libstdbuf.so"
-extern char *__progname;
+static int
+appendenv(const char *key, const char *value)
+{
+ char *curval, *newpair;
+ int ret;
+
+ curval = getenv(key);
+ if (curval == NULL)
+ ret = asprintf(&newpair, "%s=%s", key, value);
+ else
+ ret = asprintf(&newpair, "%s=%s:%s", key, curval, value);
+ if (ret > 0)
+ ret = putenv(newpair);
+ if (ret < 0)
+ warn("Failed to set environment variable: %s", key);
+ return (ret);
+}
static void
-usage(int s)
+usage(void)
{
- fprintf(stderr, "Usage: %s [-e 0|L|B|<sz>] [-i 0|L|B|<sz>] [-o 0|L|B|<sz>] "
- "<cmd> [args ...]\n", __progname);
- exit(s);
+ fprintf(stderr,
+ "usage: stdbuf [-e 0|L|B|<sz>] [-i 0|L|B|<sz>] [-o 0|L|B|<sz>] "
+ "<cmd> [args ...]\n");
+ exit(1);
}
int
main(int argc, char *argv[])
{
char *ibuf, *obuf, *ebuf;
- char *preload0, *preload1;
int i;
ibuf = obuf = ebuf = NULL;
@@ -66,9 +82,8 @@
case 'o':
obuf = optarg;
break;
- case '?':
default:
- usage(1);
+ usage();
break;
}
}
@@ -87,25 +102,8 @@
warn("Failed to set environment variable: %s=%s",
"_STDBUF_E", ebuf);
- preload0 = getenv("LD_PRELOAD");
- if (preload0 == NULL)
- i = asprintf(&preload1, "LD_PRELOAD=" LIBSTDBUF);
- else
- i = asprintf(&preload1, "LD_PRELOAD=%s:%s", preload0,
- LIBSTDBUF);
-
- if (i < 0 || putenv(preload1) == -1)
- warn("Failed to set environment variable: LD_PRELOAD");
-
- preload0 = getenv("LD_32_PRELOAD");
- if (preload0 == NULL)
- i = asprintf(&preload1, "LD_32_PRELOAD=" LIBSTDBUF32);
- else
- i = asprintf(&preload1, "LD_32_PRELOAD=%s:%s", preload0,
- LIBSTDBUF32);
-
- if (i < 0 || putenv(preload1) == -1)
- warn("Failed to set environment variable: LD_32_PRELOAD");
+ appendenv("LD_PRELOAD", LIBSTDBUF);
+ appendenv("LD_32_PRELOAD", LIBSTDBUF32);
execvp(argv[0], argv);
err(2, "%s", argv[0]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 6, 10:37 AM (6 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40293167
Default Alt Text
D40799.id123987.diff (2 KB)
Attached To
Mode
D40799: stdbuf: Code cleanup.
Attached
Detach File
Event Timeline
Log In to Comment