Exemple #1
0
/*
 * Create pipe with either write- _or_ read-semantics.  Fortunately for us,
 * on SYS_MSDOS, we don't need both at the same instant.
 */
int
inout_popen(FILE **fr, FILE **fw, char *cmd)
{
    char *type = (fw != 0) ? "w" : "r";
    static FILE *pp[2] =
    {0, 0};
    int fd;

    TRACE(("inout_popen(fr=%p, fw=%p, cmd='%s')\n", fr, fw, cmd));

    ffstatus = file_is_pipe;
    fileeof = FALSE;
    append_libdir_to_path();

    /* Create the file that will hold the pipe's content */
    if ((fd = createTemp(type)) >= 0) {
        if (fw == 0) {
            *fr = pp[0] = readPipe(cmd, -1, fd);
            myWrtr = 0;
            myPipe = &pp[0];	/* "fr" may be stack-based. */
            myCmds = 0;
        } else {
            *fw = pp[1] = fdopen(fd, type);
            myPipe = fr;
            myWrtr = &pp[1];	/* "fw" may be stack-based. */
            myCmds = strmalloc(cmd);
        }
    }
    return TRUE;
}
Exemple #2
0
int
inout_popen(FILE **fr, FILE **fw, char *cmd)
{
    TRACE(("inout_popen(fr=%p, fw=%p, cmd='%s')\n", fr, fw, cmd));

    ffstatus = file_is_pipe;
    fileeof = FALSE;
    append_libdir_to_path();
#ifdef GMDW32PIPES
    if (global_g_val(GMDW32PIPES))
        return (native_inout_popen(fr, fw, cmd));
#endif
    return (tmp_inout_popen(fr, fw, cmd));
}
Exemple #3
0
int
inout_popen(FILE **fr, FILE **fw, char *cmd)
{
    int rp[2];
    int wp[2];

    if (pipe(rp))
        return FALSE;
    if (pipe(wp))
        return FALSE;

    pipe_pid = softfork();
    if (pipe_pid < 0)
        return FALSE;

    ffstatus = file_is_pipe;
    fileeof = FALSE;
    if (pipe_pid) {		/* parent */

        if (fr) {
            *fr = fdopen(rp[0], "r");
            if (*fr == NULL) {
                (void) fprintf(stderr, "fdopen r failed\n");
                abort();
            }
        } else {
            (void) close(rp[0]);
        }
        (void) close(rp[1]);

        if (fw) {
            *fw = fdopen(wp[1], "w");
            if (*fw == NULL) {
                (void) fprintf(stderr, "fdopen w failed\n");
                abort();
            }
        } else {
            (void) close(wp[1]);
        }
        (void) close(wp[0]);
        return TRUE;

    } else {			/* child */

        beginDisplay();
        append_libdir_to_path();
        if (fw) {
            (void) close(0);
            if (dup(wp[0]) != 0) {
                IGNORE_RC(write(2, "dup 0 failed\r\n", (size_t) 15));
                exit(-1);
            }
        }
        (void) close(wp[1]);
        if (fr) {
            (void) close(1);
            if (dup(rp[1]) != 1) {
                IGNORE_RC(write(2, "dup 1 failed\r\n", (size_t) 15));
                exit(-1);
            }
            (void) close(2);
            if (dup(rp[1]) != 2) {
                IGNORE_RC(write(1, "dup 2 failed\r\n", (size_t) 15));
                exit(-1);
            }
        } else {
            (void) close(rp[1]);
        }
        (void) close(rp[0]);
        exec_sh_c(cmd);
        endofDisplay();

    }
    return TRUE;
}