ALSA: info: Small refactoring and a sanity check in snd_info_get_line()

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2013-03-13 12:11:13 +01:00
parent 0d861ac238
commit 0bc0ec903c
1 changed files with 9 additions and 14 deletions

View File

@ -700,25 +700,20 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
{
int c = -1;
if (snd_BUG_ON(!buffer || !buffer->buffer))
return 1;
if (len <= 0 || buffer->stop || buffer->error)
return 1;
while (--len > 0) {
c = buffer->buffer[buffer->curr++];
if (c == '\n') {
if (buffer->curr >= buffer->size)
buffer->stop = 1;
break;
}
*line++ = c;
if (buffer->curr >= buffer->size) {
buffer->stop = 1;
break;
}
}
while (c != '\n' && !buffer->stop) {
while (!buffer->stop) {
c = buffer->buffer[buffer->curr++];
if (buffer->curr >= buffer->size)
buffer->stop = 1;
if (c == '\n')
break;
if (len) {
len--;
*line++ = c;
}
}
*line = '\0';
return 0;