8 typedef struct Pipe Pipe
;
24 pipewrite(int fd
, void *buf
, int len
)
38 err
= write(fd
, p
, n
);
50 return p
- (uchar
*)buf
;
54 closepipe(Ufile
*file
)
56 Pipe
*pipe
= (Pipe
*)file
;
59 freebufproc(pipe
->bufproc
);
65 bufprocpipe(Pipe
*pipe
)
67 if(pipe
->bufproc
== nil
)
68 pipe
->bufproc
= newbufproc(pipe
->fd
);
73 pollpipe(Ufile
*file
, void *tab
)
75 Pipe
*pipe
= (Pipe
*)file
;
77 return pollbufproc(bufprocpipe(pipe
), pipe
, tab
);
81 readpipe(Ufile
*file
, void *buf
, int len
, vlong
)
83 Pipe
*pipe
= (Pipe
*)file
;
86 if((pipe
->mode
& O_NONBLOCK
) || (pipe
->bufproc
!= nil
)){
87 ret
= readbufproc(bufprocpipe(pipe
), buf
, len
, 0, (pipe
->mode
& O_NONBLOCK
));
91 ret
= read(pipe
->fd
, buf
, len
);
97 pipe
->atime
= time(nil
);
102 writepipe(Ufile
*file
, void *buf
, int len
, vlong
)
104 Pipe
*pipe
= (Pipe
*)file
;
107 ret
= pipewrite(pipe
->fd
, buf
, len
);
109 pipe
->mtime
= time(nil
);
114 ioctlpipe(Ufile
*file
, int cmd
, void *arg
)
116 Pipe
*pipe
= (Pipe
*)file
;
127 if((r
= nreadablebufproc(bufprocpipe(pipe
))) < 0){
137 int sys_pipe(int *fds
)
142 static int ino
= 0x1234;
144 trace("sys_pipe(%p)", fds
);
150 file
= kmallocz(sizeof(Pipe
), 1);
156 file
->atime
= file
->mtime
= time(nil
);
157 if((fd
= newfd(file
, 0)) < 0){
170 fillstat(Pipe
*pipe
, Ustat
*s
)
173 s
->mode
= 0666 | S_IFIFO
;
174 s
->uid
= current
->uid
;
175 s
->gid
= current
->gid
;
176 s
->atime
= pipe
->atime
;
177 s
->mtime
= pipe
->mtime
;
182 fstatpipe(Ufile
*file
, Ustat
*s
)
184 Pipe
*pipe
= (Pipe
*)file
;
189 static Udev pipedev
=
199 void pipedevinit(void)
201 devtab
[PIPEDEV
] = &pipedev
;