version 1.1.1.1, 2013/10/14 10:32:48
|
version 1.1.1.2, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "proc_open.h" |
#include "proc_open.h" |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
Line 280 static void proc_read_fd_to_buffer(int fd, buffer *b)
|
Line 282 static void proc_read_fd_to_buffer(int fd, buffer *b)
|
ssize_t s; |
ssize_t s; |
|
|
for (;;) { |
for (;;) { |
buffer_prepare_append(b, 512); | buffer_string_prepare_append(b, 1024); |
if ((s = read(fd, (void *)(b->ptr + b->used), 512 - 1)) <= 0) { | if ((s = read(fd, (void *)(b->ptr + buffer_string_length(b)), buffer_string_space(b))) <= 0) { |
break; |
break; |
} |
} |
b->used += s; | buffer_commit(b, s); |
} |
} |
b->ptr[b->used] = '\0'; |
|
} |
} |
/* }}} */ |
/* }}} */ |
/* {{{ proc_open_buffer */ |
/* {{{ proc_open_buffer */ |
Line 298 int proc_open_buffer(const char *command, buffer *in,
|
Line 299 int proc_open_buffer(const char *command, buffer *in,
|
} |
} |
|
|
if (in) { |
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"); |
perror("error writing pipe"); |
return -1; |
return -1; |
} |
} |
Line 315 int proc_open_buffer(const char *command, buffer *in,
|
Line 316 int proc_open_buffer(const char *command, buffer *in,
|
} else { |
} else { |
buffer *tmp = buffer_init(); |
buffer *tmp = buffer_init(); |
proc_read_fd_to_buffer(proc.err.fd, tmp); |
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"); |
perror("error writing pipe"); |
buffer_free(tmp); |
buffer_free(tmp); |
return -1; |
return -1; |