Fix \r\n handling logic

This commit is contained in:
tkaden4 2018-03-05 17:05:27 -08:00
parent cfd5e5cf87
commit 2a9fa07a80

13
xcape.c
View file

@ -578,13 +578,22 @@ char *read_line (FILE *file)
}
switch (c)
{
case '\r': /* FALLTHROUGH */
case '\r':
/* check for \r\n */
{
int c = fgetc(file);
if(c != '\n'){
ungetc(c, file);
}
}
break;
case '\n': /* FALLTHROUGH */
case '\0':
line[nlen++] = '\0';
reading = 0;
break;
case EOF:
ungetc(EOF, file);
reading = 0;
break;
default:
@ -593,12 +602,12 @@ char *read_line (FILE *file)
break;
}
}
/* TODO remove extraneous \r|\n|\0 */
if(nlen == 0)
{
free (line);
return NULL;
}
/* shrink down to size */
line = realloc (line, nlen);
return line;
}