.
This commit is contained in:
commit
aae369b9c8
9 changed files with 334 additions and 0 deletions
31
send_stdin.c
Normal file
31
send_stdin.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#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;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue