X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ffilter%2Fmemstream.h;fp=src%2Fcommon%2Ffilter%2Fmemstream.h;h=0000000000000000000000000000000000000000;hp=41c768146957c8f4ee07c9c96aeeba2f64095821;hb=c9e313bc594f40a86eed237dce222c0fc99c957f;hpb=4878de5c7deb512bbdac4fdfc498907efa06fb7c diff --git a/src/common/filter/memstream.h b/src/common/filter/memstream.h deleted file mode 100644 index 41c768146..000000000 --- a/src/common/filter/memstream.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2012 (C) Mathieu Desnoyers - * - * SPDX-License-Identifier: MIT - * - */ - -#ifndef _LTTNG_CTL_MEMSTREAM_H -#define _LTTNG_CTL_MEMSTREAM_H - -#ifdef LTTNG_HAVE_FMEMOPEN -#include - -static inline -FILE *lttng_fmemopen(void *buf, size_t size, const char *mode) -{ - return fmemopen(buf, size, mode); -} - -#else /* LTTNG_HAVE_FMEMOPEN */ - -#include -#include -#include - -/* - * Fallback for systems which don't have fmemopen. Copy buffer to a - * temporary file, and use that file as FILE * input. - */ -static inline -FILE *lttng_fmemopen(void *buf, size_t size, const char *mode) -{ - char tmpname[PATH_MAX]; - size_t len; - FILE *fp; - int ret; - - /* - * Support reading only. - */ - if (strcmp(mode, "rb") != 0) { - return NULL; - } - strncpy(tmpname, "/tmp/lttng-tmp-XXXXXX", PATH_MAX); - ret = mkstemp(tmpname); - if (ret < 0) { - return NULL; - } - /* - * We need to write to the file. - */ - fp = fdopen(ret, "w+"); - if (!fp) { - goto error_unlink; - } - /* Copy the entire buffer to the file */ - len = fwrite(buf, sizeof(char), size, fp); - if (len != size) { - goto error_close; - } - ret = fseek(fp, 0L, SEEK_SET); - if (ret < 0) { - PERROR("fseek"); - goto error_close; - } - /* We keep the handle open, but can unlink the file on the VFS. */ - ret = unlink(tmpname); - if (ret < 0) { - PERROR("unlink"); - } - return fp; - -error_close: - ret = fclose(fp); - if (ret < 0) { - PERROR("close"); - } -error_unlink: - ret = unlink(tmpname); - if (ret < 0) { - PERROR("unlink"); - } - return NULL; -} - -#endif /* LTTNG_HAVE_FMEMOPEN */ - -#endif /* _LTTNG_CTL_MEMSTREAM_H */