diff options
author | Stefan Bühler <stbuehler@web.de> | 2015-02-08 19:10:44 +0000 |
---|---|---|
committer | Stefan Bühler <stbuehler@web.de> | 2015-02-08 19:10:44 +0000 |
commit | ad3e93ea96d1cbaab00d07245dbd02f790060f85 (patch) | |
tree | ff1dab6ccb2f2cd95c2c668b290ed3b1ffc6022b /src/proc_open.c | |
parent | adfa06de996944b495b878540464dd6e74563052 (diff) | |
download | lighttpd-git-ad3e93ea96d1cbaab00d07245dbd02f790060f85.tar.gz |
Use buffer API to read and modify "used" member
- a lot of code tried to handle manually adding terminating zeroes and
keeping track of the correct "used" count.
Replaced all "external" usages with simple wrapper functions:
* buffer_string_is_empty (used <= 1), buffer_is_empty (used == 0);
prefer buffer_string_is_empty
* buffer_string_set_length
* buffer_string_length
* CONST_BUF_LEN() macro
- removed "static" buffer hacks (buffers pointing to constant/stack
memory instead of malloc()ed data)
- buffer_append_strftime(): refactor buffer+strftime uses
- li_tohex(): no need for a buffer for binary-to-hex conversion:
the output data length is easy to predict
- remove "-Winline" from extra warnings: the "inline" keyword just
supresses the warning about unused but defined (static) functions;
don't care whether it actually gets inlined or not.
From: Stefan Bühler <stbuehler@web.de>
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2979 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/proc_open.c')
-rw-r--r-- | src/proc_open.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/proc_open.c b/src/proc_open.c index c29b9c6b..167027a2 100644 --- a/src/proc_open.c +++ b/src/proc_open.c @@ -284,8 +284,7 @@ static void proc_read_fd_to_buffer(int fd, buffer *b) { if ((s = read(fd, (void *)(b->ptr + buffer_string_length(b)), buffer_string_space(b))) <= 0) { break; } - b->used += s; - b->ptr[b->used-1] = '\0'; + buffer_commit(b, s); } } /* }}} */ @@ -298,7 +297,7 @@ int proc_open_buffer(const char *command, buffer *in, buffer *out, buffer *err) } if (in) { - if (write(proc.in.fd, (void *)in->ptr, in->used) < 0) { + if (write(proc.in.fd, CONST_BUF_LEN(in)) < 0) { perror("error writing pipe"); return -1; } @@ -315,7 +314,7 @@ int proc_open_buffer(const char *command, buffer *in, buffer *out, buffer *err) } else { buffer *tmp = buffer_init(); proc_read_fd_to_buffer(proc.err.fd, tmp); - if (tmp->used > 0 && write(2, (void*)tmp->ptr, tmp->used) < 0) { + if (!buffer_string_is_empty(tmp) && write(2, CONST_BUF_LEN(tmp)) < 0) { perror("error writing pipe"); buffer_free(tmp); return -1; |