mirror of
https://gitlab.freedesktop.org/emersion/libdisplay-info.git
synced 2024-12-25 21:59:08 +01:00
info: Use memory-stream API for di_info_parse_edid
Avoids a bunch of duplicated code here. Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
parent
c63ca40ef7
commit
12923cc3bc
1 changed files with 11 additions and 14 deletions
25
info.c
25
info.c
|
@ -16,18 +16,15 @@ pnp_id_table(const char *key);
|
|||
struct di_info *
|
||||
di_info_parse_edid(const void *data, size_t size)
|
||||
{
|
||||
struct memory_stream failure_msg;
|
||||
struct di_edid *edid;
|
||||
struct di_info *info;
|
||||
char *failure_msg = NULL;
|
||||
size_t failure_msg_size;
|
||||
FILE *failure_msg_file;
|
||||
char *failure_msg_str = NULL;
|
||||
|
||||
failure_msg_file = open_memstream(&failure_msg,
|
||||
&failure_msg_size);
|
||||
if (!failure_msg_file)
|
||||
if (!memory_stream_open(&failure_msg))
|
||||
return NULL;
|
||||
|
||||
edid = _di_edid_parse(data, size, failure_msg_file);
|
||||
edid = _di_edid_parse(data, size, failure_msg.fp);
|
||||
if (!edid)
|
||||
goto err_failure_msg_file;
|
||||
|
||||
|
@ -37,13 +34,14 @@ di_info_parse_edid(const void *data, size_t size)
|
|||
|
||||
info->edid = edid;
|
||||
|
||||
if (fflush(failure_msg_file) != 0)
|
||||
if (fflush(failure_msg.fp) != 0)
|
||||
goto err_info;
|
||||
fclose(failure_msg_file);
|
||||
if (failure_msg && failure_msg[0] != '\0')
|
||||
info->failure_msg = failure_msg;
|
||||
|
||||
failure_msg_str = memory_stream_close(&failure_msg);
|
||||
if (failure_msg_str && failure_msg_str[0] != '\0')
|
||||
info->failure_msg = failure_msg_str;
|
||||
else
|
||||
free(failure_msg);
|
||||
free(failure_msg_str);
|
||||
|
||||
return info;
|
||||
|
||||
|
@ -52,8 +50,7 @@ err_info:
|
|||
err_edid:
|
||||
_di_edid_destroy(edid);
|
||||
err_failure_msg_file:
|
||||
fclose(failure_msg_file);
|
||||
free(failure_msg);
|
||||
memory_stream_cleanup(&failure_msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue