43 #include "EST_String.h"
44 #include "EST_io_aux.h"
52 const char *file_stuff_key =
"ft_StUfF_key";
54 static int getc_unbuffered(SOCKET_FD fd)
72 int socket_receive_file(SOCKET_FD fd,
const EST_String &filename)
80 if ((outfd=fopen(filename,
"wb")) == NULL)
82 cerr <<
"socket_receive_file: can't find file \"" <<
88 while (file_stuff_key[k] !=
'\0')
90 c = getc_unbuffered(fd);
91 if (file_stuff_key[k] == c)
93 else if ((c ==
'X') && (file_stuff_key[k+1] ==
'\0'))
95 for (i=0; i < k; i++) putc(file_stuff_key[i],outfd);
101 for (i=0; i < k; i++) putc(file_stuff_key[i],outfd);
110 int socket_send_file(SOCKET_FD fd,
const EST_String &filename)
116 FILE *ffd = fdopen(dup(fd),
"wb");
121 if ((infd=fopen(filename,
"rb")) == NULL)
123 cerr <<
"socket_send_file: can't find file \"" <<
129 while ((c=getc(infd)) != EOF)
131 if (file_stuff_key[k] == c)
135 if (file_stuff_key[k] ==
'\0')
138 const char filler=
'X';
139 send(fd,&filler,1,0);
146 send(fd,(
const char *)&c,1,0);
151 for (k=0; file_stuff_key[k] !=
'\0'; k++)
153 send(fd,file_stuff_key+k,1,0);
155 putc(file_stuff_key[k],ffd);