fix to binary transfer with ascii-xfr

Kjell M. Myksvoll kmyksvo at online.no
Tue Oct 19 21:01:02 UTC 2010


Hi,

Got hit by some problems when transferring compiled python files to
a Telit modem (model: GM862-GPS) using the 'ascii-xfr' program. That
is that the transfer didn't worked at all.

A quick look at the source of 'ascii-xfr', as it comes distributed
with the 2.4 version of 'minicom', revealed that the problem was due
to 'strlen' beeing used to find the length of the strings to be
transferred. As the compiled python code contains a lot of embedded
'\0' in it, the program consistently got the length wrong.

Modified the code into using 'ftell' to determine the length, see
patch appended below, and now the transfer apparently seems to work
without errors.

But please note that I only can claim that the patch fixes the issue
with binary transfers to Telit-modems, as I have not yet tested it
with other units.

br,
kmm




diff -b -urN orig/ascii-xfr.c new/ascii-xfr.c
--- orig/ascii-xfr.c	2010-10-19 22:56:08.364623001 +0200
+++ new/ascii-xfr.c	2010-10-19 22:58:34.064623000 +0200
@@ -60,13 +60,11 @@
 /*
  *	Output a line and delay if needed.
  */
-void lineout(char const *line)
+void lineout(char const *line, int len)
 {
   int ret;
 
   if (!cdelay) {
-    int len = strlen(line);
-
     do {
       ret = write(STDOUT_FILENO, line, len);
       if (ret < 0) {
@@ -146,13 +144,19 @@
   char line[1024];
   char *s;
   int first = 1;
+  int cur, len;
 
   if ((fp = fopen(file, "r")) == NULL) {
     perror(file);
     return -1;
   }
 
+  /* keep track of file pointer for length calculation */
+  cur = ftell(fp);
+
   while (fgets(line, sizeof(line) - 1, fp) != NULL) {
+    len = ftell(fp) - cur;
+    cur = ftell(fp);
     if (dotrans && (s = strrchr(line, '\n')) != NULL) {
       /* s now points to \n */
       /* if there's a \r before, go there */
@@ -163,9 +167,11 @@
       *s++ = '\n';
       /* terminate string */
       *s = 0;
+      /* increase length accordingly */
+      len++;
     }
-    lineout(line);
-    bdone += strlen(line);
+    lineout(line, len);
+    bdone += len;
     if (ldelay)
       ms_delay(ldelay);
     stats(first);





More information about the minicom-devel mailing list