00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <time.h>
00027 #include <ctype.h>
00028 #include <math.h>
00029 #include <errno.h>
00030 #include <unistd.h>
00031 #include <string.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #include <fcntl.h>
00035 #include <dirent.h>
00036
00037 #include "common.h"
00038
00039
00040
00041
00048 int SendFile(int fdout, int fdin, int len)
00049 {
00050 #define BSIZE 8192
00051 char buffer[BSIZE];
00052 int n,out;
00053 out=0;
00054 if (len<0)
00055 {
00056 len=4*BSIZE;
00057 }
00058 while (len!=0)
00059 {
00060 n=read(fdin,buffer,(BSIZE<len)?BSIZE:len);
00061 if (n<=0)
00062 {
00063 break;
00064 }
00065 if (n!=write(fdout,buffer,n))
00066 {
00067 PrintError("write: %m\n");
00068 break;
00069 }
00070 len-=n;
00071 out+=n;
00072 }
00073 return(out);
00074 }