10 filetype(int fd, char *typ, int ntyp)
12 int ifd[2], ofd[2], xfd[2], n;
13 char *argv[3], buf[4096];
16 if((n = readn(fd, buf, sizeof(buf))) < 0)
28 switch(rfork(RFFDG|RFPROC|RFNOWAIT)){
46 exec("/bin/file", argv);
51 if(rfork(RFFDG|RFPROC|RFNOWAIT) == 0){
54 write(ifd[0], buf, n);
63 switch(rfork(RFFDG|RFPROC|RFNOWAIT)){
70 if(write(xfd[1], buf, n) != n)
72 } while((n = read(fd, buf, sizeof(buf))) > 0);
80 if((n = readn(ofd[0], typ, ntyp-1)) < 0)
83 while(n > 0 && typ[n-1] == '\n')
105 "application/pdf", PAGE,
106 "application/postscript", PAGE,
107 "application/ghostscript", PAGE,
108 "application/troff", PAGE,
112 "message/rfc822", PLAIN,
116 if(filetype(fd, buf, sizeof(buf)) < 0)
118 for(i=0; i<nelem(tab); i++)
119 if(strncmp(buf, tab[i].typ, strlen(tab[i].typ)) == 0)