2
0
mirror of git://github.com/lxc/lxc synced 2025-08-31 16:27:18 +00:00

file_utils: handle libcs without fmemopen()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2020-03-10 17:41:50 +01:00
parent 77c3e9a22d
commit 7fa9063089
2 changed files with 26 additions and 1 deletions

View File

@@ -701,6 +701,10 @@ AC_CHECK_FUNCS([strlcat],
AM_CONDITIONAL(HAVE_STRLCAT, true) AM_CONDITIONAL(HAVE_STRLCAT, true)
AC_DEFINE(HAVE_STRLCAT,1,[Have strlcat]), AC_DEFINE(HAVE_STRLCAT,1,[Have strlcat]),
AM_CONDITIONAL(HAVE_STRLCAT, false)) AM_CONDITIONAL(HAVE_STRLCAT, false))
AC_CHECK_FUNCS([fmemopen],
AM_CONDITIONAL(HAVE_FMEMOPEN, true)
AC_DEFINE(HAVE_FMEMOPEN,1,[Have fmemopen]),
AM_CONDITIONAL(HAVE_FMEMOPEN, false))
# HAVE_STRUCT_RTNL_LINK_STATS64={0,1} # HAVE_STRUCT_RTNL_LINK_STATS64={0,1}
AC_CHECK_TYPES([struct rtnl_link_stats64], [], [], [[#include <linux/if_link.h>]]) AC_CHECK_TYPES([struct rtnl_link_stats64], [], [], [[#include <linux/if_link.h>]])

View File

@@ -470,6 +470,7 @@ char *file_to_buf(const char *path, size_t *length)
FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer) FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer)
{ {
#ifdef HAVE_FMEMOPEN
__do_free char *buf = NULL; __do_free char *buf = NULL;
size_t len = 0; size_t len = 0;
FILE *f; FILE *f;
@@ -483,13 +484,17 @@ FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffe
return NULL; return NULL;
*caller_freed_buffer = move_ptr(buf); *caller_freed_buffer = move_ptr(buf);
return f; return f;
#else
return fopen(path, mode);
#endif
} }
FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer) FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
{ {
FILE *f;
#ifdef HAVE_FMEMOPEN
__do_free char *buf = NULL; __do_free char *buf = NULL;
size_t len = 0; size_t len = 0;
FILE *f;
buf = fd_to_buf(fd, &len); buf = fd_to_buf(fd, &len);
if (!buf) if (!buf)
@@ -500,5 +505,21 @@ FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
return NULL; return NULL;
*caller_freed_buffer = move_ptr(buf); *caller_freed_buffer = move_ptr(buf);
#else
__do_close_prot_errno int dupfd = -EBADF;
dupfd = dup(fd);
if (dupfd < 0)
return NULL;
f = fdopen(dupfd, "re");
if (!f)
return NULL;
/* Transfer ownership of fd. */
move_fd(dupfd);
#endif
return f; return f;
} }