Commit 4b647f996b520943832ece617a55132c6d3308da

Authored by perry.werneck@gmail.com
1 parent 8df67fe2

Trabalhando no bug relativo à transferência de arquivos binários

Showing 1 changed file with 21 additions and 8 deletions   Show diff stats
src/lib3270/ft_dft.c
... ... @@ -391,16 +391,20 @@ static void dft_get_request(H3270 *hSession)
391 391 {
392 392 if (ft->ascii_flag && ft->cr_flag)
393 393 {
  394 + // ASCII text file
  395 +
394 396 int c;
395 397  
396 398 /* Read one byte and do CR/LF translation. */
397 399 c = fgetc(ft->local_file);
398   - if (c == EOF) {
  400 + if (c == EOF)
  401 + {
399 402 break;
400 403 }
401 404 if (!ft->ft_last_cr && c == '\n')
402 405 {
403   - if (numbytes < 2) {
  406 + if (numbytes < 2)
  407 + {
404 408 /*
405 409 * Not enough room to expand NL to
406 410 * CR/LF.
... ... @@ -416,14 +420,20 @@ static void dft_get_request(H3270 *hSession)
416 420 *bufptr++ = ft->remap_flag ? ft->charset.asc2ebc[c]: c;
417 421 numbytes--;
418 422 total_read++;
419   - } else {
  423 + }
  424 + else
  425 + {
420 426 /* Binary read. */
421 427 numread = fread(bufptr, 1, numbytes, ft->local_file);
422   - if (numread <= 0) {
  428 + if (numread <= 0)
  429 + {
  430 + lib3270_write_log(hSession,"Error %s reading source file (rc=%d)",strerror(errno),errno);
423 431 break;
424 432 }
  433 +
425 434 if (ft->ascii_flag && ft->remap_flag)
426 435 {
  436 + // Remap charset
427 437 unsigned char *s = bufptr;
428 438 int i = numread;
429 439  
... ... @@ -434,10 +444,11 @@ static void dft_get_request(H3270 *hSession)
434 444 i--;
435 445 }
436 446 }
437   - bufptr += numread;
438   - numbytes -= numread;
439   - total_read += numread;
  447 + bufptr += numread;
  448 + numbytes -= numread;
  449 + total_read += numread;
440 450 }
  451 +
441 452 if (feof(ft->local_file) || ferror(ft->local_file))
442 453 {
443 454 break;
... ... @@ -476,7 +487,9 @@ static void dft_get_request(H3270 *hSession)
476 487 ft->dft_eof = 1;
477 488 }
478 489  
479   - } else {
  490 + }
  491 + else
  492 + {
480 493 trace_ds(hSession,"> WriteStructuredField FileTransferData EOF\n");
481 494 *hSession->obptr++ = HIGH8(TR_GET_REQ);
482 495 *hSession->obptr++ = TR_ERROR_REPLY;
... ...