lib9: add write function that withstands interrupts

This commit is contained in:
Russ Cox 2008-07-04 12:38:26 -04:00
parent fc9fc9c831
commit cab935a0ba
3 changed files with 26 additions and 0 deletions

View file

@ -793,6 +793,7 @@ extern int p9waitpid(void);
extern long write(int, void*, long);
extern long writev(int, IOchunk*, int);
*/
extern long p9write(int, void*, long);
/* extern int wstat(char*, uchar*, int); give up */
extern ulong rendezvous(ulong, ulong);
@ -813,6 +814,7 @@ extern ulong rendezvous(ulong, ulong);
#define open p9open
#define pipe p9pipe
#define waitfor p9waitfor
#define write p9write
#endif
extern Dir* dirstat(char*);

View file

@ -157,6 +157,7 @@ LIB9OFILES=\
unsharp.$O\
wait.$O\
waitpid.$O\
write.$O\
OFILES=\
$LIB9OFILES\

23
src/lib9/write.c Normal file
View file

@ -0,0 +1,23 @@
#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>
long
p9write(int f, void *av, long n)
{
char *a;
long m, t;
a = av;
t = 0;
while(t < n){
m = write(f, a+t, n-t);
if(m <= 0){
if(t == 0)
return m;
break;
}
t += m;
}
return t;
}