diff options
| author | Sean Eric Fagan <sef@FreeBSD.org> | 2000-02-15 20:25:47 +0000 |
|---|---|---|
| committer | Sean Eric Fagan <sef@FreeBSD.org> | 2000-02-15 20:25:47 +0000 |
| commit | 05d5ca35873dcfda726c27fdedc6ba7ffafc08dd (patch) | |
| tree | b41a6b1775abb0ea06340c977544223592222000 /usr.bin | |
| parent | 2c6610f343df65a0dc1f4b2c2f088c1a636792c8 (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/truss/syscalls.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index bdd087bbf50c..1b98cba1cfc6 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -115,10 +115,12 @@ get_syscall(const char *name) { char * get_string(int procfd, void *offset, int max) { char *buf; - int size, len, c; + int size, len, c, fd; FILE *p; - if ((p = fdopen(procfd, "r")) == NULL) + if ((fd = dup(procfd)) == -1) + err(1, "dup"); + if ((p = fdopen(fd, "r")) == NULL) err(1, "fdopen"); buf = malloc( size = (max ? max : 64 ) ); len = 0; @@ -130,15 +132,18 @@ get_string(int procfd, void *offset, int max) { break; } if (len == size) { - char *tmp = buf; + char *tmp; tmp = realloc(buf, size+64); if (tmp == NULL) { buf[len] = 0; + fclose(p); return buf; } size += 64; + buf = tmp; } } + fclose(p); return buf; } |
