Lines Matching defs:ctx
88 struct context ctx;
93 ctx.c_ident = doread ? "read" : "write";
94 ctx.c_read = doread;
95 if (pipe(ctx.c_pipe) == -1)
97 if (pipe(ctx.c_cv) == -1)
100 ctx.c_bufsiz = ctx.c_read ? 1 : BIG_PIPE_SIZE;
101 ctx.c_buf = malloc(ctx.c_bufsiz);
102 if (ctx.c_buf == NULL)
106 ctx.c_id = i + 1;
107 pids[i] = block_proc(&ctx);
114 if (ctx.c_read)
115 n = write(ctx.c_pipe[1], &c, 1);
117 n = read(ctx.c_pipe[0], &c, 1);
119 err(1, "%s", ctx.c_ident);
121 errx(1, "%s: %ld != 1", ctx.c_ident, n);
124 (void)read(ctx.c_cv[0], &c, 1);
136 if (ctx.c_read)
137 close(ctx.c_pipe[1]);
139 close(ctx.c_pipe[0]);
157 block_proc(const struct context *ctx)
165 int rp = ctx->c_pipe[0];
166 int wp = ctx->c_pipe[1];
168 if (ctx->c_read)
177 if (ctx->c_read)
178 n = read(rp, ctx->c_buf, ctx->c_bufsiz);
180 n = write(wp, ctx->c_buf, ctx->c_bufsiz);
183 ctx->c_id, ctx->c_ident, n);
187 err(1, "[%d] %s", ctx->c_id, ctx->c_ident);
193 (void)write(ctx->c_cv[1], &c, 1);