Skip to content
Snippets Groups Projects
Commit 8d3a32a9 authored by deuce's avatar deuce
Browse files

If we did not successfully send a YModem header, and we are using 1K

blocks, fall back to 128 byte blocks at the end of the file.

Stop using ((block_num-1)*(xm->block_size)) as the offset.
Use sent_bytes instead.
parent 0e8184c8
No related branches found
No related tags found
No related merge requests found
......@@ -428,6 +428,7 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start,
size_t rd;
time_t startfile;
struct stat st;
BOOL sent_header=FALSE;
if(sent!=NULL)
*sent=0;
......@@ -463,8 +464,10 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start,
block_len=strlen(block)+1+i;
for(xm->errors=0;xm->errors<=xm->max_errors && !is_cancelled(xm) && is_connected(xm);xm->errors++) {
xmodem_put_block(xm, block, block_len <=128 ? 128:1024, 0 /* block_num */);
if(xmodem_get_ack(xm,1,0))
if(xmodem_get_ack(xm,1,0)) {
sent_header=TRUE;
break;
}
}
if(xm->errors>=xm->max_errors || is_cancelled(xm)) {
lprintf(xm,LOG_ERR,"Failed to send header block");
......@@ -485,10 +488,18 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start,
&& is_connected(xm)) {
fseek(fp,sent_bytes,SEEK_SET);
memset(block,CPMEOF,xm->block_size);
if(!sent_header) {
if(xm->block_size>128) {
if((sent_bytes+xm->block_size) > st.st_size) {
lprintf(xm,LOG_INFO,"Falling back to 128 byte blocks for end of file");
xm->block_size=128;
}
}
}
if((rd=fread(block,1,xm->block_size,fp))!=xm->block_size
&& (long)(block_num*xm->block_size) < st.st_size) {
&& (long)(sent_bytes + xm->block_size) <= st.st_size) {
lprintf(xm,LOG_ERR,"READ ERROR %d instead of %d at offset %lu"
,rd,xm->block_size,(block_num-1)*(long)xm->block_size);
,rd,xm->block_size,sent_bytes);
xm->errors++;
continue;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment