goto cleanup;
}
- char *pos = reply; /* The current start of searching */
- char *end = pos + strlen(reply); /* The end of the reply string */
+ char *pos; /* The current start of searching */
+ char *next = reply; /* The start of the next line */
char *eol; /* The character which ends the current line */
+ char *end = reply + strlen(reply); /* The end of the reply string */
+
+ while (next) {
+ pos = next;
- while (pos < end) {
/* Split the output into lines */
eol = memchr(pos, '\n', end - pos);
- if (eol == NULL)
+ if (eol == NULL) {
eol = end;
+ next = NULL;
+ } else {
+ next = eol + 1;
+ }
+
+ /* Ignore all whitespace immediately before eol */
+ while (eol > pos && c_isspace(*(eol-1)))
+ eol -= 1;
/* Look for 'filename=pty:' */
#define NEEDLE "filename=pty:"
/* If it's not there we can ignore this line */
if (!needle)
- goto next;
+ continue;
/* id is everthing from the beginning of the line to the ':'
* find ':' and turn it into a terminator */
char *colon = memchr(pos, ':', needle - pos);
if (colon == NULL)
- goto next;
+ continue;
*colon = '\0';
char *id = pos;
goto cleanup;
}
#undef NEEDLE
-
- next:
- pos = eol + 1;
}
ret = 0;