mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
Rearrange internal header files.
This commit rearranges the internal header files. "src/guestfs-internal.h" is just for the library, as before. "src/guestfs-internal-frontend.h" is for use by all library, bindings, tools C code, but NOT the daemon. "src/guestfs-internal-all.h" is for use by all C code including the daemon. This is just code motion, but it has some important consequences: (1) We can use the CLEANUP_* macros in bindings and tools code. (2) We can get rid of TMP_TEMPLATE_ON_STACK. (3) We will (in future) be able to stop bindings and tools code from using the safe_* allocation functions (which are NOT safe to use outside the library alone).
This commit is contained in:
@@ -196,7 +196,10 @@ guestfsd_LDADD = \
|
||||
$(LIBINTL) \
|
||||
$(SERVENT_LIB)
|
||||
|
||||
guestfsd_CPPFLAGS = -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib
|
||||
guestfsd_CPPFLAGS = \
|
||||
-I$(top_srcdir)/gnulib/lib \
|
||||
-I$(top_builddir)/gnulib/lib \
|
||||
-I$(top_builddir)/src
|
||||
guestfsd_CFLAGS = \
|
||||
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
|
||||
$(AUGEAS_CFLAGS) \
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "guestfs_protocol.h"
|
||||
|
||||
#include "guestfs-internal-all.h"
|
||||
|
||||
/*-- in guestfsd.c --*/
|
||||
extern int verbose;
|
||||
|
||||
@@ -389,26 +391,6 @@ is_zero (const char *buffer, size_t size)
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(x) /* empty */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_FREE __attribute__((cleanup(cleanup_free)))
|
||||
#define CLEANUP_FREE_STRING_LIST \
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
int
|
||||
run_display (const char *cmd, size_t argc, char *argv[])
|
||||
{
|
||||
TMP_TEMPLATE_ON_STACK (filename);
|
||||
TMP_TEMPLATE_ON_STACK (g, filename);
|
||||
char *remote;
|
||||
const char *display;
|
||||
char buf[256];
|
||||
|
||||
@@ -39,7 +39,7 @@ static int copy_attributes (const char *src, const char *dest);
|
||||
int
|
||||
run_edit (const char *cmd, size_t argc, char *argv[])
|
||||
{
|
||||
TMP_TEMPLATE_ON_STACK (filename);
|
||||
TMP_TEMPLATE_ON_STACK (g, filename);
|
||||
char buf[256];
|
||||
const char *editor;
|
||||
char *remotefilename, *newname;
|
||||
|
||||
@@ -1812,7 +1812,7 @@ file_in (const char *arg)
|
||||
static char *
|
||||
file_in_heredoc (const char *endmarker)
|
||||
{
|
||||
TMP_TEMPLATE_ON_STACK (template);
|
||||
TMP_TEMPLATE_ON_STACK (g, template);
|
||||
int fd;
|
||||
size_t markerlen;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
25
fish/fish.h
25
fish/fish.h
@@ -21,31 +21,10 @@
|
||||
|
||||
#include <guestfs.h>
|
||||
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
#include "fish-cmds.h"
|
||||
|
||||
#ifndef SOCK_CLOEXEC
|
||||
#define SOCK_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#define _(str) dgettext(PACKAGE, (str))
|
||||
#define N_(str) dgettext(PACKAGE, (str))
|
||||
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
|
||||
#define TMP_TEMPLATE_ON_STACK(var) \
|
||||
char *ttos_tmpdir = guestfs_get_tmpdir (g); \
|
||||
char var[strlen (ttos_tmpdir) + 32]; \
|
||||
sprintf (var, "%s/guestfishXXXXXX", ttos_tmpdir); \
|
||||
free (ttos_tmpdir)
|
||||
|
||||
/* in fish.c */
|
||||
extern guestfs_h *g;
|
||||
extern int read_only;
|
||||
|
||||
@@ -101,7 +101,7 @@ run_hexedit (const char *cmd, size_t argc, char *argv[])
|
||||
int r;
|
||||
struct stat oldstat, newstat;
|
||||
char buf[BUFSIZ];
|
||||
TMP_TEMPLATE_ON_STACK (tmp);
|
||||
TMP_TEMPLATE_ON_STACK (g, tmp);
|
||||
int fd = mkstemp (tmp);
|
||||
if (fd == -1) {
|
||||
perror ("mkstemp");
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
int
|
||||
run_more (const char *cmd, size_t argc, char *argv[])
|
||||
{
|
||||
TMP_TEMPLATE_ON_STACK (filename);
|
||||
TMP_TEMPLATE_ON_STACK (g, filename);
|
||||
char buf[256];
|
||||
char *remote;
|
||||
const char *pager;
|
||||
|
||||
@@ -19,40 +19,7 @@
|
||||
#ifndef OPTIONS_H
|
||||
#define OPTIONS_H
|
||||
|
||||
#ifndef _
|
||||
#define _(str) dgettext(PACKAGE, (str))
|
||||
#endif
|
||||
#ifndef N_
|
||||
#define N_(str) dgettext(PACKAGE, (str))
|
||||
#endif
|
||||
|
||||
#ifndef STREQ
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#endif
|
||||
#ifndef STRCASEEQ
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#endif
|
||||
#ifndef STRNEQ
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#endif
|
||||
#ifndef STRCASENEQ
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#endif
|
||||
#ifndef STREQLEN
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#endif
|
||||
#ifndef STRCASEEQLEN
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#endif
|
||||
#ifndef STRNEQLEN
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#endif
|
||||
#ifndef STRCASENEQLEN
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#endif
|
||||
#ifndef STRPREFIX
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
#endif
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
/* Provided by guestfish or guestmount. */
|
||||
extern guestfs_h *g;
|
||||
|
||||
@@ -25,18 +25,7 @@
|
||||
#ifndef GUESTMOUNT_H_
|
||||
#define GUESTMOUNT_H_
|
||||
|
||||
#define _(str) dgettext(PACKAGE, (str))
|
||||
#define N_(str) dgettext(PACKAGE, (str))
|
||||
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
static inline char *
|
||||
bad_cast (char const *s)
|
||||
|
||||
@@ -690,11 +690,6 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
|
||||
|
||||
/* Private functions. */
|
||||
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_malloc (guestfs_h *g, size_t nbytes);
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_calloc (guestfs_h *g, size_t n, size_t s);
|
||||
extern GUESTFS_DLL_PUBLIC char *guestfs___safe_strdup (guestfs_h *g, const char *str);
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size);
|
||||
|
||||
extern GUESTFS_DLL_PUBLIC int guestfs___for_each_disk (guestfs_h *g, /* virDomainPtr */ void *dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data);
|
||||
|
||||
";
|
||||
@@ -1650,11 +1645,22 @@ and generate_linker_script () =
|
||||
(* Unofficial parts of the API: the bindings code use these
|
||||
* functions, so it is useful to export them.
|
||||
*)
|
||||
"guestfs___cleanup_free";
|
||||
"guestfs___cleanup_free_string_list";
|
||||
"guestfs___cleanup_hash_free";
|
||||
"guestfs___cleanup_unlink_free";
|
||||
(*
|
||||
"guestfs___cleanup_xmlBufferFree";
|
||||
"guestfs___cleanup_xmlFreeDoc";
|
||||
"guestfs___cleanup_xmlFreeTextWriter";
|
||||
"guestfs___cleanup_xmlXPathFreeContext";
|
||||
"guestfs___cleanup_xmlXPathFreeObject";
|
||||
*)
|
||||
"guestfs___for_each_disk";
|
||||
"guestfs___safe_calloc";
|
||||
"guestfs___safe_malloc";
|
||||
"guestfs___safe_strdup";
|
||||
"guestfs___safe_memdup";
|
||||
"guestfs___for_each_disk";
|
||||
] in
|
||||
let functions =
|
||||
List.flatten (
|
||||
|
||||
@@ -549,6 +549,7 @@ and generate_java_c () =
|
||||
|
||||
#include \"com_redhat_et_libguestfs_GuestFS.h\"
|
||||
#include \"guestfs.h\"
|
||||
#include \"guestfs-internal-frontend.h\"
|
||||
|
||||
/* This is the opaque data passed between _set_event_callback and
|
||||
* the C wrapper which calls the Java event callback.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* libguestfs
|
||||
* Copyright (C) 2009-2012 Red Hat Inc.
|
||||
* Copyright (C) 2009-2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* libguestfs
|
||||
* Copyright (C) 2009-2012 Red Hat Inc.
|
||||
* Copyright (C) 2009-2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -19,6 +19,8 @@
|
||||
#ifndef GUESTFS_OCAML_C_H
|
||||
#define GUESTFS_OCAML_C_H
|
||||
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
#define Guestfs_val(v) (*((guestfs_h **)Data_custom_val(v)))
|
||||
extern void ocaml_guestfs_raise_error (guestfs_h *g, const char *func)
|
||||
Noreturn;
|
||||
@@ -27,14 +29,4 @@ extern void ocaml_guestfs_raise_closed (const char *func)
|
||||
extern char **ocaml_guestfs_strings_val (guestfs_h *g, value sv);
|
||||
extern void ocaml_guestfs_free_strings (char **r);
|
||||
|
||||
# ifdef __GNUC__
|
||||
# ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__((__unused__))
|
||||
# endif
|
||||
#else
|
||||
# ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* GUESTFS_OCAML_C_H */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* libguestfs python bindings
|
||||
* Copyright (C) 2009-2012 Red Hat Inc.
|
||||
* Copyright (C) 2009-2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* libguestfs python bindings
|
||||
* Copyright (C) 2009-2012 Red Hat Inc.
|
||||
* Copyright (C) 2009-2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -20,6 +20,7 @@
|
||||
#define guestfs_py_h
|
||||
|
||||
#include "guestfs.h"
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
#if PY_VERSION_HEX < 0x02050000
|
||||
typedef int Py_ssize_t;
|
||||
|
||||
65
src/guestfs-internal-all.h
Normal file
65
src/guestfs-internal-all.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* libguestfs
|
||||
* Copyright (C) 2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* NB: This contains ONLY definitions which are shared by libguestfs
|
||||
* daemon, library, bindings and tools (ie. ALL C code).
|
||||
*/
|
||||
|
||||
#ifndef GUESTFS_INTERNAL_ALL_H_
|
||||
#define GUESTFS_INTERNAL_ALL_H_
|
||||
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
#define STRSUFFIX(a,b) (strlen((a)) >= strlen((b)) && STREQ((a)+strlen((a))-strlen((b)),(b)))
|
||||
|
||||
#ifndef SOCK_CLOEXEC
|
||||
#define SOCK_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define UNIX_PATH_MAX 104
|
||||
#else
|
||||
#define UNIX_PATH_MAX 108
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define xdr_uint32_t xdr_u_int32_t
|
||||
#endif
|
||||
|
||||
#ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(x) /* empty */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
#endif /* GUESTFS_INTERNAL_ALL_H_ */
|
||||
117
src/guestfs-internal-frontend.h
Normal file
117
src/guestfs-internal-frontend.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/* libguestfs
|
||||
* Copyright (C) 2013 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* NB: This contains ONLY definitions which are shared by libguestfs
|
||||
* library, bindings and tools (NOT the daemon).
|
||||
*
|
||||
* If a definition is only needed by a single component of libguestfs,
|
||||
* then it should NOT be here!
|
||||
*
|
||||
* The daemon does NOT use this header. If you need a place to put
|
||||
* something shared with absolutely everything including the daemon,
|
||||
* put it in 'src/guestfs-internal-all.h'.
|
||||
*/
|
||||
|
||||
#ifndef GUESTFS_INTERNAL_FRONTEND_H_
|
||||
#define GUESTFS_INTERNAL_FRONTEND_H_
|
||||
|
||||
#include "guestfs-internal-all.h"
|
||||
|
||||
#define _(str) dgettext(PACKAGE, (str))
|
||||
#define N_(str) dgettext(PACKAGE, (str))
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_FREE __attribute__((cleanup(guestfs___cleanup_free)))
|
||||
#define CLEANUP_FREE_STRING_LIST \
|
||||
__attribute__((cleanup(guestfs___cleanup_free_string_list)))
|
||||
#define CLEANUP_HASH_FREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_hash_free)))
|
||||
#define CLEANUP_UNLINK_FREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_unlink_free)))
|
||||
#ifdef HAVE_LIBXML2
|
||||
#define CLEANUP_XMLBUFFERFREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlBufferFree)))
|
||||
#define CLEANUP_XMLFREEDOC \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlFreeDoc)))
|
||||
#define CLEANUP_XMLFREETEXTWRITER \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlFreeTextWriter)))
|
||||
#define CLEANUP_XMLXPATHFREECONTEXT \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlXPathFreeContext)))
|
||||
#define CLEANUP_XMLXPATHFREEOBJECT \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlXPathFreeObject)))
|
||||
#endif
|
||||
#else
|
||||
#define CLEANUP_FREE
|
||||
#define CLEANUP_FREE_STRING_LIST
|
||||
#define CLEANUP_HASH_FREE
|
||||
#define CLEANUP_UNLINK_FREE
|
||||
#ifdef HAVE_LIBXML2
|
||||
#define CLEANUP_XMLBUFFERFREE
|
||||
#define CLEANUP_XMLFREEDOC
|
||||
#define CLEANUP_XMLFREETEXTWRITER
|
||||
#define CLEANUP_XMLXPATHFREECONTEXT
|
||||
#define CLEANUP_XMLXPATHFREEOBJECT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define TMP_TEMPLATE_ON_STACK(g,var) \
|
||||
char *ttos_tmpdir = guestfs_get_tmpdir (g); \
|
||||
char var[strlen (ttos_tmpdir) + 32]; \
|
||||
sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir); \
|
||||
free (ttos_tmpdir)
|
||||
|
||||
/* NB: At some point we will stop exporting these safe_* allocation
|
||||
* functions outside the library, so don't use them in new tools or
|
||||
* bindings code.
|
||||
*/
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_malloc (guestfs_h *g, size_t nbytes);
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_calloc (guestfs_h *g, size_t n, size_t s);
|
||||
extern GUESTFS_DLL_PUBLIC char *guestfs___safe_strdup (guestfs_h *g, const char *str);
|
||||
extern GUESTFS_DLL_PUBLIC void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size);
|
||||
extern void *guestfs___safe_realloc (guestfs_h *g, void *ptr, size_t nbytes);
|
||||
extern char *guestfs___safe_strdup (guestfs_h *g, const char *str);
|
||||
extern char *guestfs___safe_strndup (guestfs_h *g, const char *str, size_t n);
|
||||
extern void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size);
|
||||
extern char *guestfs___safe_asprintf (guestfs_h *g, const char *fs, ...)
|
||||
__attribute__((format (printf,2,3)));
|
||||
|
||||
#define safe_calloc guestfs___safe_calloc
|
||||
#define safe_malloc guestfs___safe_malloc
|
||||
#define safe_realloc guestfs___safe_realloc
|
||||
#define safe_strdup guestfs___safe_strdup
|
||||
#define safe_strndup guestfs___safe_strndup
|
||||
#define safe_memdup guestfs___safe_memdup
|
||||
#define safe_asprintf guestfs___safe_asprintf
|
||||
|
||||
/* These functions are used internally by the CLEANUP_* macros.
|
||||
* Don't call them directly.
|
||||
*/
|
||||
extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_free (void *ptr);
|
||||
extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_free_string_list (void *ptr);
|
||||
extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_hash_free (void *ptr);
|
||||
extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_unlink_free (void *ptr);
|
||||
|
||||
#ifdef HAVE_LIBXML2
|
||||
extern void guestfs___cleanup_xmlBufferFree (void *ptr);
|
||||
extern void guestfs___cleanup_xmlFreeDoc (void *ptr);
|
||||
extern void guestfs___cleanup_xmlFreeTextWriter (void *ptr);
|
||||
extern void guestfs___cleanup_xmlXPathFreeContext (void *ptr);
|
||||
extern void guestfs___cleanup_xmlXPathFreeObject (void *ptr);
|
||||
#endif
|
||||
|
||||
#endif /* GUESTFS_INTERNAL_FRONTEND_H_ */
|
||||
@@ -34,23 +34,7 @@
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
#ifndef SOCK_CLOEXEC
|
||||
#define SOCK_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#define STREQ(a,b) (strcmp((a),(b)) == 0)
|
||||
#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
|
||||
#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
|
||||
#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
|
||||
#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
|
||||
#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
|
||||
#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
|
||||
#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
|
||||
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
||||
#define STRSUFFIX(a,b) (strlen((a)) >= strlen((b)) && STREQ((a)+strlen((a))-strlen((b)),(b)))
|
||||
|
||||
#define _(str) dgettext(PACKAGE, (str))
|
||||
#define N_(str) dgettext(PACKAGE, (str))
|
||||
#include "guestfs-internal-frontend.h"
|
||||
|
||||
#if ENABLE_PROBES
|
||||
#include <sys/sdt.h>
|
||||
@@ -72,60 +56,6 @@
|
||||
#define TRACE4(name, arg1, arg2, arg3, arg4)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ATTRIBUTE_CLEANUP
|
||||
#define CLEANUP_FREE __attribute__((cleanup(guestfs___cleanup_free)))
|
||||
#define CLEANUP_FREE_STRING_LIST \
|
||||
__attribute__((cleanup(guestfs___cleanup_free_string_list)))
|
||||
#define CLEANUP_HASH_FREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_hash_free)))
|
||||
#define CLEANUP_UNLINK_FREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_unlink_free)))
|
||||
#ifdef HAVE_LIBXML2
|
||||
#define CLEANUP_XMLBUFFERFREE \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlBufferFree)))
|
||||
#define CLEANUP_XMLFREEDOC \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlFreeDoc)))
|
||||
#define CLEANUP_XMLFREETEXTWRITER \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlFreeTextWriter)))
|
||||
#define CLEANUP_XMLXPATHFREECONTEXT \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlXPathFreeContext)))
|
||||
#define CLEANUP_XMLXPATHFREEOBJECT \
|
||||
__attribute__((cleanup(guestfs___cleanup_xmlXPathFreeObject)))
|
||||
#endif
|
||||
#else
|
||||
#define CLEANUP_FREE
|
||||
#define CLEANUP_FREE_STRING_LIST
|
||||
#define CLEANUP_HASH_FREE
|
||||
#define CLEANUP_UNLINK_FREE
|
||||
#ifdef HAVE_LIBXML2
|
||||
#define CLEANUP_XMLBUFFERFREE
|
||||
#define CLEANUP_XMLFREEDOC
|
||||
#define CLEANUP_XMLFREETEXTWRITER
|
||||
#define CLEANUP_XMLXPATHFREECONTEXT
|
||||
#define CLEANUP_XMLXPATHFREEOBJECT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define TMP_TEMPLATE_ON_STACK(g,var) \
|
||||
char *ttos_tmpdir = guestfs_get_tmpdir (g); \
|
||||
char var[strlen (ttos_tmpdir) + 32]; \
|
||||
sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir); \
|
||||
free (ttos_tmpdir)
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define UNIX_PATH_MAX 104
|
||||
#else
|
||||
#define UNIX_PATH_MAX 108
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define xdr_uint32_t xdr_u_int32_t
|
||||
#endif
|
||||
|
||||
/* Some limits on what the inspection code will read, for safety. */
|
||||
|
||||
/* Small text configuration files.
|
||||
@@ -492,38 +422,6 @@ struct guestfs_message_header;
|
||||
struct guestfs_message_error;
|
||||
struct guestfs_progress;
|
||||
|
||||
/* alloc.c */
|
||||
extern void *guestfs___safe_realloc (guestfs_h *g, void *ptr, size_t nbytes);
|
||||
extern char *guestfs___safe_strdup (guestfs_h *g, const char *str);
|
||||
extern char *guestfs___safe_strndup (guestfs_h *g, const char *str, size_t n);
|
||||
extern void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size);
|
||||
extern char *guestfs___safe_asprintf (guestfs_h *g, const char *fs, ...)
|
||||
__attribute__((format (printf,2,3)));
|
||||
|
||||
#define safe_calloc guestfs___safe_calloc
|
||||
#define safe_malloc guestfs___safe_malloc
|
||||
#define safe_realloc guestfs___safe_realloc
|
||||
#define safe_strdup guestfs___safe_strdup
|
||||
#define safe_strndup guestfs___safe_strndup
|
||||
#define safe_memdup guestfs___safe_memdup
|
||||
#define safe_asprintf guestfs___safe_asprintf
|
||||
|
||||
/* These functions are used internally by the CLEANUP_* macros.
|
||||
* Don't call them directly.
|
||||
*/
|
||||
extern void guestfs___cleanup_free (void *ptr);
|
||||
extern void guestfs___cleanup_free_string_list (void *ptr);
|
||||
extern void guestfs___cleanup_hash_free (void *ptr);
|
||||
extern void guestfs___cleanup_unlink_free (void *ptr);
|
||||
|
||||
#ifdef HAVE_LIBXML2
|
||||
extern void guestfs___cleanup_xmlBufferFree (void *ptr);
|
||||
extern void guestfs___cleanup_xmlFreeDoc (void *ptr);
|
||||
extern void guestfs___cleanup_xmlFreeTextWriter (void *ptr);
|
||||
extern void guestfs___cleanup_xmlXPathFreeContext (void *ptr);
|
||||
extern void guestfs___cleanup_xmlXPathFreeObject (void *ptr);
|
||||
#endif
|
||||
|
||||
/* errors.c */
|
||||
extern void guestfs___init_error_handler (guestfs_h *g);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user