Commit de653570 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- Clean up net_Gets()

parent ae0c85f8
...@@ -896,45 +896,41 @@ int __net_Write( vlc_object_t *p_this, int fd, v_socket_t *p_vs, ...@@ -896,45 +896,41 @@ int __net_Write( vlc_object_t *p_this, int fd, v_socket_t *p_vs,
char *__net_Gets( vlc_object_t *p_this, int fd, v_socket_t *p_vs ) char *__net_Gets( vlc_object_t *p_this, int fd, v_socket_t *p_vs )
{ {
char *psz_line = malloc( 1024 ); char *psz_line = NULL, *ptr = NULL;
int i_line = 0; size_t i_line = 0, i_max = 0;
int i_max = 1024;
for( ;; ) for( ;; )
{ {
if( net_Read( p_this, fd, p_vs, &psz_line[i_line], 1, VLC_TRUE ) != 1 ) if( i_line == i_max )
{ {
psz_line[i_line] = '\0'; i_max += 1024;
break; psz_line = realloc( psz_line, i_max );
ptr = psz_line + i_line;
} }
i_line++;
if( psz_line[i_line-1] == '\n' ) if( net_Read( p_this, fd, p_vs, ptr, 1, VLC_TRUE ) != 1 )
{ {
psz_line[i_line] = '\0'; if( i_line == 0 )
{
free( psz_line );
return NULL;
}
break; break;
} }
if( i_line >= i_max - 1 ) if ( *ptr == '\n' )
{ break;
i_max += 1024;
psz_line = realloc( psz_line, i_max );
}
}
if( i_line <= 0 ) i_line++;
{ ptr++;
free( psz_line );
return NULL;
} }
while( i_line >= 1 && *ptr-- = '\0';
( psz_line[i_line-1] == '\n' || psz_line[i_line-1] == '\r' ) )
{ if( ( ptr > psz_line ) && ( *ptr == '\r' ) )
i_line--; *ptr = '\0';
psz_line[i_line] = '\0';
}
return psz_line; return psz_line;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment