mirror of
https://gitlab.freedesktop.org/emersion/libdisplay-info.git
synced 2024-12-25 21:59:08 +01:00
c63ca40ef7
Signed-off-by: Joshua Ashton <joshua@froggi.es>
36 lines
510 B
C
36 lines
510 B
C
#include <stdlib.h>
|
|
|
|
#include "memory-stream.h"
|
|
|
|
bool
|
|
memory_stream_open(struct memory_stream *m)
|
|
{
|
|
*m = (struct memory_stream){ 0 };
|
|
m->fp = open_memstream(&m->str, &m->str_len);
|
|
|
|
return m->fp != NULL;
|
|
}
|
|
|
|
char *
|
|
memory_stream_close(struct memory_stream *m)
|
|
{
|
|
char *str;
|
|
int ret;
|
|
|
|
ret = fclose(m->fp);
|
|
str = m->str;
|
|
*m = (struct memory_stream){ 0 };
|
|
|
|
if (ret != 0) {
|
|
free(str);
|
|
str = NULL;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
void
|
|
memory_stream_cleanup(struct memory_stream *m)
|
|
{
|
|
free(memory_stream_close(m));
|
|
}
|