summaryrefslogtreecommitdiff
path: root/distrib/special/disknames
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-02-14 22:53:02 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-02-14 22:53:02 +0000
commit8a4069122158ffe200ea9ab0a4015b2f6b8f9f69 (patch)
treebd39d756a65c24d32dfc49f741649d86e42c8dfb /distrib/special/disknames
parent7779a164331ea0d4fdac89c39636177a6279ac11 (diff)
append \n at end of line, and make this more normal userland code
Diffstat (limited to 'distrib/special/disknames')
-rw-r--r--distrib/special/disknames/disknames.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/distrib/special/disknames/disknames.c b/distrib/special/disknames/disknames.c
index bc7de9b3096..7e529dd79b7 100644
--- a/distrib/special/disknames/disknames.c
+++ b/distrib/special/disknames/disknames.c
@@ -1,11 +1,14 @@
#include <sys/param.h>
#include <sys/sysctl.h>
-#include <sys/malloc.h>
+#include <sys/uio.h>
+#include <unistd.h>
#include <stdlib.h>
int
-main() {
+main(int argc, char *argv[])
+{
+ struct iovec iov[2];
int mib[2];
size_t len;
char *p;
@@ -14,10 +17,14 @@ main() {
mib[1] = HW_DISKNAMES;
if (sysctl(mib, 2, NULL, &len, NULL, 0) != -1)
- if ((p = (char *)malloc(len)) != NULL)
+ if ((p = malloc(len)) != NULL)
if (sysctl(mib, 2, p, &len, NULL, 0) != -1) {
- write(1, p, len);
- _exit(0);
- }
- _exit(1);
+ iov[0].iov_base = p;
+ iov[0].iov_len = len;
+ iov[1].iov_base = "\n";
+ iov[1].iov_len = 1;
+ writev(STDOUT_FILENO, iov, 2);
+ exit(0);
+ }
+ exit(1);
}