fix to binary transfer with ascii-xfr
Adam Lackorzynski
adam at os.inf.tu-dresden.de
Tue Oct 26 07:51:30 UTC 2010
On Tue Oct 19, 2010 at 23:02:49 +0200, Kjell M. Myksvoll wrote:
> 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.
Could not test either but that's what I've applied. Thanks!
diff -r 3678fccc24a3 src/ascii-xfr.c
--- a/src/ascii-xfr.c Sat Sep 11 22:36:30 2010 +0200
+++ b/src/ascii-xfr.c Tue Oct 26 09:45:51 2010 +0200
@@ -60,13 +60,11 @@
/*
* Output a line and delay if needed.
*/
-void lineout(char const *line)
+static 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,26 +144,36 @@
char line[1024];
char *s;
int first = 1;
+ long cur, len;
if ((fp = fopen(file, "r")) == NULL) {
perror(file);
return -1;
}
- while (fgets(line, sizeof(line) - 1, fp) != NULL) {
+ cur = 0;
+
+ while (fgets(line, sizeof(line) - 2, fp) != NULL) {
+ long c = ftell(fp);
+ len = c - cur;
+ cur = c;
if (dotrans && (s = strrchr(line, '\n')) != NULL) {
/* s now points to \n */
/* if there's a \r before, go there */
if (s > line && *(s - 1) == '\r')
- s--;
+ {
+ s--;
+ len--;
+ }
/* end of line */
*s++ = '\r';
*s++ = '\n';
/* terminate string */
*s = 0;
+ len++;
}
- lineout(line);
- bdone += strlen(line);
+ lineout(line, len);
+ bdone += len;
if (ldelay)
ms_delay(ldelay);
stats(first);
Adam
--
Adam adam at os.inf.tu-dresden.de
Lackorzynski http://os.inf.tu-dresden.de/~adam/
More information about the minicom-devel
mailing list