tforgot this - plan9port - [fork] Plan 9 from user space (HTM) git clone git://src.adamsgaard.dk/plan9port (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 0df4c01ecab67c56ef701997189a281bc3cb303d (DIR) parent 1a8bd157b665a7ef92f490430ba6b1eb7484b1e6 (HTM) Author: rsc <devnull@localhost> Date: Tue, 14 Feb 2006 19:44:29 +0000 forgot this Diffstat: M src/cmd/upas/marshal/marshal.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) --- (DIR) diff --git a/src/cmd/upas/marshal/marshal.c b/src/cmd/upas/marshal/marshal.c t@@ -813,6 +813,18 @@ printinreplyto(Biobuf *out, char *dir) return Bprint(out, "In-Reply-To: %s\n", buf); } +int +mopen(char *file, int mode) +{ + int fd; + + if((fd = open(file, mode)) >= 0) + return fd; + if(strncmp(file, "Mail/", 5) == 0 && mountmail() >= 0 && (fd = fsopenfd(mailfs, file+5, mode)) >= 0) + return fd; + return -1; +} + Attach* mkattach(char *file, char *type, int inline) { t@@ -824,11 +836,8 @@ mkattach(char *file, char *type, int inline) if(file == nil) return nil; - if((fd = open(file, OREAD)) < 0) - if(strncmp(file, "Mail/", 5) != 0 || mountmail() < 0 || (fd = fsopenfd(mailfs, file+5, OREAD)) < 0){ - fprint(2, "%s: %s can't read file\n", argv0, file); + if((fd = mopen(file, OREAD)) < 0) return nil; - } a = emalloc(sizeof(*a)); a->fd = fd; a->path = file; t@@ -877,11 +886,12 @@ mkattach(char *file, char *type, int inline) if(pipe(pfd) < 0) return a; - xfd[0] = pfd[0]; + xfd[0] = mopen(file, OREAD); xfd[1] = pfd[0]; xfd[2] = dup(2, -1); - if((pid=threadspawnl(xfd, unsharp("#9/bin/file"), "file", "-m", file, nil)) < 0){ + if((pid=threadspawnl(xfd, unsharp("#9/bin/file"), "file", "-m", nil)) < 0){ close(xfd[0]); + close(xfd[1]); close(xfd[2]); return a; } t@@ -892,6 +902,7 @@ mkattach(char *file, char *type, int inline) ftype[n-1] = 0; a->type = estrdup(ftype); } +fprint(2, "got type %s\n", a->type); close(pfd[1]); procwait(pid);