summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 117e270)
raw | patch | inline | side by side (parent: 117e270)
author | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 3 Jun 2010 01:33:57 +0000 (21:33 -0400) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 3 Jun 2010 01:34:51 +0000 (21:34 -0400) |
tig.c | patch | blob | history |
index f364930235546fc7c22bcc7e9a596097a94ad67e..54fab4526c5beb5d00fd1f20a5fa196302827bf0 100644 (file)
--- a/tig.c
+++ b/tig.c
};
struct io {
- pid_t pid; /* PID of spawned process. */
int pipe; /* Pipe end for reading or writing. */
+ pid_t pid; /* PID of spawned process. */
int error; /* Error status. */
char *buf; /* Read buffer. */
size_t bufalloc; /* Allocated buffer size. */
unsigned int eof:1; /* Has end of file been reached. */
};
-static void
-io_reset(struct io *io)
-{
- io->pipe = -1;
- io->pid = 0;
- io->buf = io->bufpos = NULL;
- io->bufalloc = io->bufsize = 0;
- io->error = 0;
- io->eof = 0;
-}
+#define IO_INIT(fd) { fd }
static void
io_init(struct io *io)
{
- io_reset(io);
+ memset(io, 0, sizeof(*io));
+ io->pipe = -1;
}
static bool
if (io->pipe != -1)
close(io->pipe);
free(io->buf);
- io_reset(io);
+ io_init(io);
while (pid > 0) {
int status;
static bool
io_complete(enum io_type type, const char **argv, const char *dir, int fd)
{
- struct io io = {};
+ struct io io = IO_INIT(fd);
- io_init(&io);
- io.pipe = fd;
return io_start(&io, type, dir, argv) && io_done(&io);
}
static bool
io_run_buf(const char **argv, char buf[], size_t bufsize)
{
- struct io io = {};
+ struct io io = IO_INIT(-1);
- io_init(&io);
return io_start(&io, IO_RD, NULL, argv) && io_read_buf(&io, buf, bufsize);
}
io_run_load(const char **argv, const char *separators,
int (*read_property)(char *, size_t, char *, size_t))
{
- struct io io = {};
+ struct io io = IO_INIT(-1);
- io_init(&io);
if (!io_start(&io, IO_RD, NULL, argv))
return ERR;
return io_load(&io, separators, read_property);