1 #ifndef _LTTNG_CTL_MEMSTREAM_H
2 #define _LTTNG_CTL_MEMSTREAM_H
5 * src/lib/lttng-ctl/memstream.h
7 * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * memstream compatibility layer.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #ifdef LTTNG_HAVE_FMEMOPEN
26 FILE *lttng_fmemopen(void *buf
, size_t size
, const char *mode
)
28 return fmemopen(buf
, size
, mode
);
31 #else /* LTTNG_HAVE_FMEMOPEN */
37 * Fallback for systems which don't have fmemopen. Copy buffer to a
38 * temporary file, and use that file as FILE * input.
41 FILE *lttng_fmemopen(void *buf
, size_t size
, const char *mode
)
43 char tmpname
[PATH_MAX
];
49 * Support reading only.
51 if (strcmp(mode
, "rb") != 0) {
54 strncpy(tmpname
, "/tmp/lttng-tmp-XXXXXX", PATH_MAX
);
55 ret
= mkstemp(tmpname
);
60 * We need to write to the file.
62 fp
= fdopen(ret
, "w+");
66 /* Copy the entire buffer to the file */
67 len
= fwrite(buf
, sizeof(char), size
, fp
);
71 ret
= fseek(fp
, 0L, SEEK_SET
);
76 /* We keep the handle open, but can unlink the file on the VFS. */
77 ret
= unlink(tmpname
);
89 ret
= unlink(tmpname
);
96 #endif /* LTTNG_HAVE_FMEMOPEN */
98 #endif /* _LTTNG_CTL_MEMSTREAM_H */
This page took 0.034469 seconds and 4 git commands to generate.