(send_data): avoid calling mmap with `len == 0'. Some mmap:s rather

dislike that (Solaris) and some munmap get grumpy later.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6804 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-08-12 22:11:54 +00:00
parent f9ae8c45d6
commit 2d5a5da6a2

View File

@@ -1292,22 +1292,30 @@ send_data(FILE *instr, FILE *outstr)
char *chunk; char *chunk;
int in = fileno(instr); int in = fileno(instr);
if(fstat(in, &st) == 0 && S_ISREG(st.st_mode)) { if(fstat(in, &st) == 0 && S_ISREG(st.st_mode)) {
chunk = mmap(0, st.st_size, PROT_READ, MAP_SHARED, in, 0); /*
* mmap zero bytes has potential of loosing, don't do it.
*/
if (st.st_size > 0) {
chunk = mmap(0, st.st_size, PROT_READ,
MAP_SHARED, in, 0);
if((void *)chunk != (void *)MAP_FAILED) { if((void *)chunk != (void *)MAP_FAILED) {
cnt = st.st_size - restart_point; cnt = st.st_size - restart_point;
sec_write(fileno(outstr), sec_write(fileno(outstr),
chunk + restart_point, chunk + restart_point,
cnt); cnt);
munmap(chunk, st.st_size); if (munmap(chunk, st.st_size) < 0)
warn ("munmap");
sec_fflush(outstr); sec_fflush(outstr);
byte_count = cnt; byte_count = cnt;
transflag = 0; transflag = 0;
} }
} else {
transflag = 0;
} }
} }
#endif #endif
if(transflag){ if(transflag) {
struct stat st; struct stat st;
netfd = fileno(outstr); netfd = fileno(outstr);
@@ -1495,7 +1503,7 @@ statcmd(void)
struct sockaddr_in *sin; struct sockaddr_in *sin;
u_char *a, *p; u_char *a, *p;
lreply(211, "%s FTP server status:", hostname, version); lreply(211, "%s FTP server (%s) status:", hostname, version);
printf(" %s\r\n", version); printf(" %s\r\n", version);
printf(" Connected to %s", remotehost); printf(" Connected to %s", remotehost);
if (!isdigit(remotehost[0])) if (!isdigit(remotehost[0]))