static char linebuf[512];
static int widx;
int i, rd, size;
- char *ptr;
size = sizeof linebuf - widx;
while(size && (rd = read(fd, linebuf + widx, size)) > 0) {
size -= rd;
}
- ptr = linebuf;
for(i=0; i<widx; i++) {
- if(*ptr == '\r' || *ptr == '\n') {
- *ptr++ = '\n';
- if(i < widx - 1 && ptr[1] == '\n') {
- *ptr++ = 0;
- }
-
- size = widx >= bsz ? bsz - 1 : widx;
+ if(linebuf[i] == '\r' || linebuf[i] == '\n') {
+ size = i >= bsz ? bsz - 1 : i;
memcpy(buf, linebuf, size);
buf[size] = 0;
- memmove(linebuf, linebuf + widx, sizeof linebuf - widx);
+ memmove(linebuf, linebuf + i + 1, sizeof linebuf - i - 1);
+ printf("ser_getline-> \"%s\"\n", buf);
return buf;
- } else {
- ++ptr;
}
}
return 0;
}
+char *ser_getline_block(int fd, char *buf, int bsz)
+{
+ if(!ser_wait(fd, -1)) {
+ return 0;
+ }
+ return ser_getline(fd, buf, bsz);
+}
+
static int baud_id(int baud)
{
switch(baud) {