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:
@@ -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>]])
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user