31 lines
652 B
C
31 lines
652 B
C
#include <libowfat/errmsg.h>
|
|
|
|
#include "pipeshare.h"
|
|
|
|
int send_stdin(int64 fd)
|
|
{
|
|
char buf[8192];
|
|
int r;
|
|
uint64 readpos=0,writepos=0;
|
|
int eof=0;
|
|
for(;;){
|
|
if(eof && writepos>=readpos)break;
|
|
if(!eof && readpos < sizeof buf) {
|
|
r=io_tryread(0,buf+readpos,(sizeof buf)-readpos);
|
|
if(r<=-2){carpsys("read stdin");return 0;}
|
|
if(r==0)eof=1;
|
|
if(r>0)readpos+=r;
|
|
}
|
|
if(writepos<readpos){
|
|
r=io_trywrite(fd,buf+writepos,readpos-writepos);
|
|
if(r<=-2){carpsys("write");return 0;}
|
|
if(r>0){
|
|
writepos+=r;
|
|
if(writepos==readpos)
|
|
readpos=writepos=0;
|
|
}
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|