mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
added copies of libs so can be built standalone
(This used to be ctdb commit 0bf6e6cb371bb946ea8cc1d8c7a23a41ea715832)
This commit is contained in:
parent
16d2ca6fa0
commit
e1797cf6be
@ -12,7 +12,7 @@ srcdir = @srcdir@
|
||||
builddir = @builddir@
|
||||
EXTRA_OBJ=@EXTRA_OBJ@
|
||||
|
||||
CFLAGS=-g -I$(srcdir)/include -Iinclude -I$(srcdir) \
|
||||
CFLAGS=-g -I$(srcdir)/include -Iinclude -Ilib/util -I$(srcdir) \
|
||||
-I@tallocdir@ -I@tdbdir@/include -I@libreplacedir@ \
|
||||
-DLIBDIR=\"$(libdir)\" -DSHLIBEXT=\"@SHLIBEXT@\" -DUSE_MMAP=1 @CFLAGS@
|
||||
|
||||
@ -21,7 +21,7 @@ LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ -lpopt @INFINIBAND_LIBS@
|
||||
EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
|
||||
|
||||
CTDB_COMMON_OBJ = common/ctdb.o common/util.o common/ctdb_util.o \
|
||||
common/ctdb_call.o common/ctdb_ltdb.o lib/util/idtree.o
|
||||
common/ctdb_call.o common/ctdb_ltdb.o lib/util/idtree.o lib/util/db_wrap.o
|
||||
|
||||
CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "system/network.h"
|
||||
#include "system/filesys.h"
|
||||
#include "../include/ctdb_private.h"
|
||||
#include "db_wrap.h"
|
||||
|
||||
|
||||
/*
|
||||
attach to a specific database
|
||||
@ -34,7 +36,7 @@ int ctdb_attach(struct ctdb_context *ctdb, const char *name, int tdb_flags,
|
||||
/* when we have a separate daemon this will need to be a real
|
||||
file, not a TDB_INTERNAL, so the parent can access it to
|
||||
for ltdb bypass */
|
||||
ctdb->ltdb = tdb_open(name, 0, /* tdb_flags */ TDB_INTERNAL, open_flags, mode);
|
||||
ctdb->ltdb = tdb_wrap_open(ctdb, name, 0, TDB_INTERNAL, open_flags, mode);
|
||||
if (ctdb->ltdb == NULL) {
|
||||
ctdb_set_error(ctdb, "Failed to open tdb %s\n", name);
|
||||
return -1;
|
||||
@ -76,7 +78,7 @@ int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
|
||||
{
|
||||
TDB_DATA rec;
|
||||
|
||||
rec = tdb_fetch(ctdb->ltdb, key);
|
||||
rec = tdb_fetch(ctdb->ltdb->tdb, key);
|
||||
if (rec.dsize < sizeof(*header)) {
|
||||
/* return an initial header */
|
||||
free(rec.dptr);
|
||||
@ -115,8 +117,8 @@ int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key,
|
||||
|
||||
memcpy(rec.dptr, header, sizeof(*header));
|
||||
memcpy(rec.dptr + sizeof(*header), data.dptr, data.dsize);
|
||||
|
||||
ret = tdb_store(ctdb->ltdb, key, rec, TDB_REPLACE);
|
||||
|
||||
ret = tdb_store(ctdb->ltdb->tdb, key, rec, TDB_REPLACE);
|
||||
talloc_free(rec.dptr);
|
||||
|
||||
return ret;
|
||||
|
@ -89,7 +89,7 @@ struct ctdb_context {
|
||||
struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
|
||||
struct ctdb_registered_call *calls; /* list of registered calls */
|
||||
char *err_msg;
|
||||
struct tdb_context *ltdb;
|
||||
struct tdb_wrap *ltdb;
|
||||
const struct ctdb_methods *methods; /* transport methods */
|
||||
const struct ctdb_upcalls *upcalls; /* transport upcalls */
|
||||
void *private; /* private to transport */
|
||||
|
46
ctdb/lib/popt/CHANGES
Normal file
46
ctdb/lib/popt/CHANGES
Normal file
@ -0,0 +1,46 @@
|
||||
1.5 -> 1.6
|
||||
- add ability to perform callbacks for every, not just first, match.
|
||||
|
||||
1.3 -> 1.5
|
||||
- heavy dose of const's
|
||||
- poptParseArgvString() now NULL terminates the list
|
||||
|
||||
1.2.3 -> 1.3
|
||||
- added support for single -
|
||||
- misc bug fixes
|
||||
- portability improvements
|
||||
|
||||
1.2.2 -> 1.2.3
|
||||
- fixed memset() in help message generation (Dale Hawkins)
|
||||
- added extern "C" stuff to popt.h for C++ compilers (Dale Hawkins)
|
||||
- const'ified poptParseArgvString (Jeff Garzik)
|
||||
|
||||
1.2.1 -> 1.2.2
|
||||
- fixed bug in chaind alias happens which seems to have only
|
||||
affected --triggers in rpm
|
||||
- added POPT_ARG_VAL
|
||||
- popt.3 installed by default
|
||||
|
||||
1.2 -> 1.2.1
|
||||
- added POPT_ARG_INTL_DOMAIN (Elliot Lee)
|
||||
- updated Makefile's to be more GNUish (Elliot Lee)
|
||||
|
||||
1.1 -> 1.2
|
||||
- added popt.3 man page (Robert Lynch)
|
||||
- don't use mmap anymore (its lack of portability isn't worth the
|
||||
trouble)
|
||||
- added test script
|
||||
- added support for exec
|
||||
- removed support for *_POPT_ALIASES env variable -- it was a bad
|
||||
idea
|
||||
- reorganized into multiple source files
|
||||
- added automatic help generation, POPT_AUTOHELP
|
||||
- added table callbacks
|
||||
- added table inclusion
|
||||
- updated man page for new features
|
||||
- added test scripts
|
||||
|
||||
1.0 -> 1.1
|
||||
- moved to autoconf (Fred Fish)
|
||||
- added STRERROR replacement (Norbert Warmuth)
|
||||
- added const keywords (Bruce Perens)
|
22
ctdb/lib/popt/COPYING
Normal file
22
ctdb/lib/popt/COPYING
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (c) 1998 Red Hat Software
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the X Consortium shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings
|
||||
in this Software without prior written authorization from the X Consortium.
|
18
ctdb/lib/popt/README
Normal file
18
ctdb/lib/popt/README
Normal file
@ -0,0 +1,18 @@
|
||||
This is the popt command line option parsing library. While it is similiar
|
||||
to getopt(3), it contains a number of enhancements, including:
|
||||
|
||||
1) popt is fully reentrant
|
||||
2) popt can parse arbitrary argv[] style arrays while
|
||||
getopt(2) makes this quite difficult
|
||||
3) popt allows users to alias command line arguments
|
||||
4) popt provides convience functions for parsing strings
|
||||
into argv[] style arrays
|
||||
|
||||
popt is used by rpm, the Red Hat install program, and many other Red Hat
|
||||
utilities, all of which provide excellent examples of how to use popt.
|
||||
Complete documentation on popt is available in popt.ps (included in this
|
||||
tarball), which is excerpted with permission from the book "Linux
|
||||
Application Development" by Michael K. Johnson and Erik Troan (availble
|
||||
from Addison Wesley in May, 1998).
|
||||
|
||||
Comments on popt should be addressed to ewt@redhat.com.
|
50
ctdb/lib/popt/findme.c
Normal file
50
ctdb/lib/popt/findme.c
Normal file
@ -0,0 +1,50 @@
|
||||
/** \ingroup popt
|
||||
* \file popt/findme.c
|
||||
*/
|
||||
|
||||
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#include "system.h"
|
||||
#include "findme.h"
|
||||
|
||||
const char * findProgramPath(const char * argv0) {
|
||||
char * path = getenv("PATH");
|
||||
char * pathbuf;
|
||||
char * start, * chptr;
|
||||
char * buf;
|
||||
|
||||
if (argv0 == NULL) return NULL; /* XXX can't happen */
|
||||
/* If there is a / in the argv[0], it has to be an absolute path */
|
||||
if (strchr(argv0, '/'))
|
||||
return xstrdup(argv0);
|
||||
|
||||
if (path == NULL) return NULL;
|
||||
|
||||
start = pathbuf = alloca(strlen(path) + 1);
|
||||
buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
|
||||
if (buf == NULL) return NULL; /* XXX can't happen */
|
||||
strcpy(pathbuf, path);
|
||||
|
||||
chptr = NULL;
|
||||
/*@-branchstate@*/
|
||||
do {
|
||||
if ((chptr = strchr(start, ':')))
|
||||
*chptr = '\0';
|
||||
sprintf(buf, "%s/%s", start, argv0);
|
||||
|
||||
if (!access(buf, X_OK))
|
||||
return buf;
|
||||
|
||||
if (chptr)
|
||||
start = chptr + 1;
|
||||
else
|
||||
start = NULL;
|
||||
} while (start && *start);
|
||||
/*@=branchstate@*/
|
||||
|
||||
free(buf);
|
||||
|
||||
return NULL;
|
||||
}
|
20
ctdb/lib/popt/findme.h
Normal file
20
ctdb/lib/popt/findme.h
Normal file
@ -0,0 +1,20 @@
|
||||
/** \ingroup popt
|
||||
* \file popt/findme.h
|
||||
*/
|
||||
|
||||
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#ifndef H_FINDME
|
||||
#define H_FINDME
|
||||
|
||||
/**
|
||||
* Return absolute path to executable by searching PATH.
|
||||
* @param argv0 name of executable
|
||||
* @return (malloc'd) absolute path to executable (or NULL)
|
||||
*/
|
||||
/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0)
|
||||
/*@*/;
|
||||
|
||||
#endif
|
43
ctdb/lib/popt/libpopt.m4
Normal file
43
ctdb/lib/popt/libpopt.m4
Normal file
@ -0,0 +1,43 @@
|
||||
dnl Check to see if we should use the included popt
|
||||
|
||||
INCLUDED_POPT=auto
|
||||
AC_ARG_WITH(included-popt,
|
||||
[ --with-included-popt use bundled popt library, not from system],
|
||||
[ INCLUDED_POPT=$withval ])
|
||||
|
||||
AC_SUBST(POPT_LIBS)
|
||||
AC_SUBST(POPT_CFLAGS)
|
||||
|
||||
if test x"$INCLUDED_POPT" != x"yes"; then
|
||||
AC_CHECK_HEADERS(popt.h)
|
||||
AC_CHECK_LIB(popt, poptGetContext, [ POPT_LIBS="-lpopt" ])
|
||||
if test x"$ac_cv_header_popt_h" = x"no" -o x"$ac_cv_lib_popt_poptGetContext" = x"no"; then
|
||||
INCLUDED_POPT=yes
|
||||
POPT_CFLAGS=""
|
||||
else
|
||||
INCLUDED_POPT=no
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(whether to use included popt)
|
||||
AC_MSG_RESULT($INCLUDED_POPT)
|
||||
if test x"$INCLUDED_POPT" != x"no"; then
|
||||
dnl find the popt sources. This is meant to work both for
|
||||
dnl popt standalone builds, and builds of packages using popt
|
||||
poptdir=""
|
||||
poptpaths="$srcdir $srcdir/lib/popt $srcdir/popt $srcdir/../popt"
|
||||
for d in $poptpaths; do
|
||||
if test -f "$d/popt.c"; then
|
||||
poptdir="$d"
|
||||
POPT_CFLAGS="-I$d"
|
||||
AC_SUBST(poptdir)
|
||||
break
|
||||
fi
|
||||
done
|
||||
if test x"$poptdir" = "x"; then
|
||||
AC_MSG_ERROR([cannot find popt source in $poptpaths])
|
||||
fi
|
||||
POPTOBJ="popt.o findme.o poptconfig.o popthelp.o poptparse.o"
|
||||
AC_SUBST(POPTOBJ)
|
||||
AC_CHECK_HEADERS([float.h alloca.h])
|
||||
fi
|
1238
ctdb/lib/popt/popt.c
Normal file
1238
ctdb/lib/popt/popt.c
Normal file
File diff suppressed because it is too large
Load Diff
541
ctdb/lib/popt/popt.h
Normal file
541
ctdb/lib/popt/popt.h
Normal file
@ -0,0 +1,541 @@
|
||||
/** \file popt/popt.h
|
||||
* \ingroup popt
|
||||
*/
|
||||
|
||||
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#ifndef H_POPT
|
||||
#define H_POPT
|
||||
|
||||
#include <stdio.h> /* for FILE * */
|
||||
|
||||
#define POPT_OPTION_DEPTH 10
|
||||
|
||||
/** \ingroup popt
|
||||
* \name Arg type identifiers
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_ARG_NONE 0 /*!< no arg */
|
||||
#define POPT_ARG_STRING 1 /*!< arg will be saved as string */
|
||||
#define POPT_ARG_INT 2 /*!< arg will be converted to int */
|
||||
#define POPT_ARG_LONG 3 /*!< arg will be converted to long */
|
||||
#define POPT_ARG_INCLUDE_TABLE 4 /*!< arg points to table */
|
||||
#define POPT_ARG_CALLBACK 5 /*!< table-wide callback... must be
|
||||
set first in table; arg points
|
||||
to callback, descrip points to
|
||||
callback data to pass */
|
||||
#define POPT_ARG_INTL_DOMAIN 6 /*!< set the translation domain
|
||||
for this table and any
|
||||
included tables; arg points
|
||||
to the domain string */
|
||||
#define POPT_ARG_VAL 7 /*!< arg should take value val */
|
||||
#define POPT_ARG_FLOAT 8 /*!< arg will be converted to float */
|
||||
#define POPT_ARG_DOUBLE 9 /*!< arg will be converted to double */
|
||||
|
||||
#define POPT_ARG_MASK 0x0000FFFF
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name Arg modifiers
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_ARGFLAG_ONEDASH 0x80000000 /*!< allow -longoption */
|
||||
#define POPT_ARGFLAG_DOC_HIDDEN 0x40000000 /*!< don't show in help/usage */
|
||||
#define POPT_ARGFLAG_STRIP 0x20000000 /*!< strip this arg from argv(only applies to long args) */
|
||||
#define POPT_ARGFLAG_OPTIONAL 0x10000000 /*!< arg may be missing */
|
||||
|
||||
#define POPT_ARGFLAG_OR 0x08000000 /*!< arg will be or'ed */
|
||||
#define POPT_ARGFLAG_NOR 0x09000000 /*!< arg will be nor'ed */
|
||||
#define POPT_ARGFLAG_AND 0x04000000 /*!< arg will be and'ed */
|
||||
#define POPT_ARGFLAG_NAND 0x05000000 /*!< arg will be nand'ed */
|
||||
#define POPT_ARGFLAG_XOR 0x02000000 /*!< arg will be xor'ed */
|
||||
#define POPT_ARGFLAG_NOT 0x01000000 /*!< arg will be negated */
|
||||
#define POPT_ARGFLAG_LOGICALOPS \
|
||||
(POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR)
|
||||
|
||||
#define POPT_BIT_SET (POPT_ARG_VAL|POPT_ARGFLAG_OR)
|
||||
/*!< set arg bit(s) */
|
||||
#define POPT_BIT_CLR (POPT_ARG_VAL|POPT_ARGFLAG_NAND)
|
||||
/*!< clear arg bit(s) */
|
||||
|
||||
#define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000 /*!< show default value in --help */
|
||||
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name Callback modifiers
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_CBFLAG_PRE 0x80000000 /*!< call the callback before parse */
|
||||
#define POPT_CBFLAG_POST 0x40000000 /*!< call the callback after parse */
|
||||
#define POPT_CBFLAG_INC_DATA 0x20000000 /*!< use data from the include line,
|
||||
not the subtable */
|
||||
#define POPT_CBFLAG_SKIPOPTION 0x10000000 /*!< don't callback with option */
|
||||
#define POPT_CBFLAG_CONTINUE 0x08000000 /*!< continue callbacks with option */
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name Error return values
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_ERROR_NOARG -10 /*!< missing argument */
|
||||
#define POPT_ERROR_BADOPT -11 /*!< unknown option */
|
||||
#define POPT_ERROR_OPTSTOODEEP -13 /*!< aliases nested too deeply */
|
||||
#define POPT_ERROR_BADQUOTE -15 /*!< error in paramter quoting */
|
||||
#define POPT_ERROR_ERRNO -16 /*!< errno set, use strerror(errno) */
|
||||
#define POPT_ERROR_BADNUMBER -17 /*!< invalid numeric value */
|
||||
#define POPT_ERROR_OVERFLOW -18 /*!< number too large or too small */
|
||||
#define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */
|
||||
#define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */
|
||||
#define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name poptBadOption() flags
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_BADOPTION_NOALIAS (1 << 0) /*!< don't go into an alias */
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name poptGetContext() flags
|
||||
*/
|
||||
/*@{*/
|
||||
#define POPT_CONTEXT_NO_EXEC (1 << 0) /*!< ignore exec expansions */
|
||||
#define POPT_CONTEXT_KEEP_FIRST (1 << 1) /*!< pay attention to argv[0] */
|
||||
#define POPT_CONTEXT_POSIXMEHARDER (1 << 2) /*!< options can't follow args */
|
||||
#define POPT_CONTEXT_ARG_OPTS (1 << 4) /*!< return args as options with value 0 */
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
*/
|
||||
struct poptOption {
|
||||
/*@observer@*/ /*@null@*/ const char * longName; /*!< may be NULL */
|
||||
char shortName; /*!< may be '\0' */
|
||||
int argInfo;
|
||||
/*@shared@*/ /*@null@*/ void * arg; /*!< depends on argInfo */
|
||||
int val; /*!< 0 means don't return, just update flag */
|
||||
/*@observer@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */
|
||||
/*@observer@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */
|
||||
};
|
||||
|
||||
/** \ingroup popt
|
||||
* A popt alias argument for poptAddAlias().
|
||||
*/
|
||||
struct poptAlias {
|
||||
/*@owned@*/ /*@null@*/ const char * longName; /*!< may be NULL */
|
||||
char shortName; /*!< may be '\0' */
|
||||
int argc;
|
||||
/*@owned@*/ const char ** argv; /*!< must be free()able */
|
||||
};
|
||||
|
||||
/** \ingroup popt
|
||||
* A popt alias or exec argument for poptAddItem().
|
||||
*/
|
||||
/*@-exporttype@*/
|
||||
typedef struct poptItem_s {
|
||||
struct poptOption option; /*!< alias/exec name(s) and description. */
|
||||
int argc; /*!< (alias) no. of args. */
|
||||
/*@owned@*/ const char ** argv; /*!< (alias) args, must be free()able. */
|
||||
} * poptItem;
|
||||
/*@=exporttype@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* \name Auto-generated help/usage
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* Empty table marker to enable displaying popt alias/exec options.
|
||||
*/
|
||||
/*@-exportvar@*/
|
||||
/*@unchecked@*/ /*@observer@*/
|
||||
extern struct poptOption poptAliasOptions[];
|
||||
/*@=exportvar@*/
|
||||
#define POPT_AUTOALIAS { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \
|
||||
0, "Options implemented via popt alias/exec:", NULL },
|
||||
|
||||
/**
|
||||
* Auto help table options.
|
||||
*/
|
||||
/*@-exportvar@*/
|
||||
/*@unchecked@*/ /*@observer@*/
|
||||
extern struct poptOption poptHelpOptions[];
|
||||
/*@=exportvar@*/
|
||||
#define POPT_AUTOHELP { NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
|
||||
0, "Help options:", NULL },
|
||||
|
||||
#define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
|
||||
/*@}*/
|
||||
|
||||
/** \ingroup popt
|
||||
*/
|
||||
/*@-exporttype@*/
|
||||
typedef /*@abstract@*/ struct poptContext_s * poptContext;
|
||||
/*@=exporttype@*/
|
||||
|
||||
/** \ingroup popt
|
||||
*/
|
||||
#ifndef __cplusplus
|
||||
/*@-exporttype -typeuse@*/
|
||||
typedef struct poptOption * poptOption;
|
||||
/*@=exporttype =typeuse@*/
|
||||
#endif
|
||||
|
||||
/*@-exportconst@*/
|
||||
enum poptCallbackReason {
|
||||
POPT_CALLBACK_REASON_PRE = 0,
|
||||
POPT_CALLBACK_REASON_POST = 1,
|
||||
POPT_CALLBACK_REASON_OPTION = 2
|
||||
};
|
||||
/*@=exportconst@*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*@-type@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Table callback prototype.
|
||||
* @param con context
|
||||
* @param reason reason for callback
|
||||
* @param opt option that triggered callback
|
||||
* @param arg @todo Document.
|
||||
* @param data @todo Document.
|
||||
*/
|
||||
typedef void (*poptCallbackType) (poptContext con,
|
||||
enum poptCallbackReason reason,
|
||||
/*@null@*/ const struct poptOption * opt,
|
||||
/*@null@*/ const char * arg,
|
||||
/*@null@*/ const void * data)
|
||||
/*@*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Initialize popt context.
|
||||
* @param name
|
||||
* @param argc no. of arguments
|
||||
* @param argv argument array
|
||||
* @param options address of popt option table
|
||||
* @param flags or'd POPT_CONTEXT_* bits
|
||||
* @return initialized popt context
|
||||
*/
|
||||
/*@only@*/ /*@null@*/ poptContext poptGetContext(
|
||||
/*@dependent@*/ /*@keep@*/ const char * name,
|
||||
int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
|
||||
/*@dependent@*/ /*@keep@*/ const struct poptOption * options,
|
||||
int flags)
|
||||
/*@*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Reinitialize popt context.
|
||||
* @param con context
|
||||
*/
|
||||
/*@-exportlocal@*/
|
||||
void poptResetContext(/*@null@*/poptContext con)
|
||||
/*@modifies con @*/;
|
||||
/*@=exportlocal@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Return value of next option found.
|
||||
* @param con context
|
||||
* @return next option val, -1 on last item, POPT_ERROR_* on error
|
||||
*/
|
||||
int poptGetNextOpt(/*@null@*/poptContext con)
|
||||
/*@globals fileSystem, internalState @*/
|
||||
/*@modifies con, fileSystem, internalState @*/;
|
||||
|
||||
/*@-redecl@*/
|
||||
/** \ingroup popt
|
||||
* Return next option argument (if any).
|
||||
* @param con context
|
||||
* @return option argument, NULL if no more options are available
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Return current option's argument.
|
||||
* @param con context
|
||||
* @return option argument, NULL if no more options are available
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Peek at current option's argument.
|
||||
* @param con context
|
||||
* @return option argument
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con)
|
||||
/*@*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Return remaining arguments.
|
||||
* @param con context
|
||||
* @return argument array, terminated with NULL
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Return the option which caused the most recent error.
|
||||
* @param con context
|
||||
* @param flags
|
||||
* @return offending option
|
||||
*/
|
||||
/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags)
|
||||
/*@*/;
|
||||
/*@=redecl@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Destroy context.
|
||||
* @param con context
|
||||
* @return NULL always
|
||||
*/
|
||||
/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Add arguments to context.
|
||||
* @param con context
|
||||
* @param argv argument array, NULL terminated
|
||||
* @return 0 on success, POPT_ERROR_OPTSTOODEEP on failure
|
||||
*/
|
||||
int poptStuffArgs(poptContext con, /*@keep@*/ const char ** argv)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Add alias to context.
|
||||
* @todo Pass alias by reference, not value.
|
||||
* @deprecated Use poptAddItem instead.
|
||||
* @param con context
|
||||
* @param alias alias to add
|
||||
* @param flags (unused)
|
||||
* @return 0 on success
|
||||
*/
|
||||
/*@unused@*/
|
||||
int poptAddAlias(poptContext con, struct poptAlias alias, int flags)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Add alias/exec item to context.
|
||||
* @param con context
|
||||
* @param newItem alias/exec item to add
|
||||
* @param flags 0 for alias, 1 for exec
|
||||
* @return 0 on success
|
||||
*/
|
||||
int poptAddItem(poptContext con, poptItem newItem, int flags)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Read configuration file.
|
||||
* @param con context
|
||||
* @param fn file name to read
|
||||
* @return 0 on success, POPT_ERROR_ERRNO on failure
|
||||
*/
|
||||
int poptReadConfigFile(poptContext con, const char * fn)
|
||||
/*@globals fileSystem, internalState @*/
|
||||
/*@modifies con->execs, con->numExecs,
|
||||
fileSystem, internalState @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Read default configuration from /etc/popt and $HOME/.popt.
|
||||
* @param con context
|
||||
* @param useEnv (unused)
|
||||
* @return 0 on success, POPT_ERROR_ERRNO on failure
|
||||
*/
|
||||
int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
|
||||
/*@globals fileSystem, internalState @*/
|
||||
/*@modifies con->execs, con->numExecs,
|
||||
fileSystem, internalState @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Duplicate an argument array.
|
||||
* @note: The argument array is malloc'd as a single area, so only argv must
|
||||
* be free'd.
|
||||
*
|
||||
* @param argc no. of arguments
|
||||
* @param argv argument array
|
||||
* @retval argcPtr address of returned no. of arguments
|
||||
* @retval argvPtr address of returned argument array
|
||||
* @return 0 on success, POPT_ERROR_NOARG on failure
|
||||
*/
|
||||
int poptDupArgv(int argc, /*@null@*/ const char **argv,
|
||||
/*@null@*/ /*@out@*/ int * argcPtr,
|
||||
/*@null@*/ /*@out@*/ const char *** argvPtr)
|
||||
/*@modifies *argcPtr, *argvPtr @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Parse a string into an argument array.
|
||||
* The parse allows ', ", and \ quoting, but ' is treated the same as " and
|
||||
* both may include \ quotes.
|
||||
* @note: The argument array is malloc'd as a single area, so only argv must
|
||||
* be free'd.
|
||||
*
|
||||
* @param s string to parse
|
||||
* @retval argcPtr address of returned no. of arguments
|
||||
* @retval argvPtr address of returned argument array
|
||||
*/
|
||||
int poptParseArgvString(const char * s,
|
||||
/*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr)
|
||||
/*@modifies *argcPtr, *argvPtr @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Parses an input configuration file and returns an string that is a
|
||||
* command line. For use with popt. You must free the return value when done.
|
||||
*
|
||||
* Given the file:
|
||||
\verbatim
|
||||
# this line is ignored
|
||||
# this one too
|
||||
aaa
|
||||
bbb
|
||||
ccc
|
||||
bla=bla
|
||||
|
||||
this_is = fdsafdas
|
||||
bad_line=
|
||||
reall bad line
|
||||
reall bad line = again
|
||||
5555= 55555
|
||||
test = with lots of spaces
|
||||
\endverbatim
|
||||
*
|
||||
* The result is:
|
||||
\verbatim
|
||||
--aaa --bbb --ccc --bla="bla" --this_is="fdsafdas" --5555="55555" --test="with lots of spaces"
|
||||
\endverbatim
|
||||
*
|
||||
* Passing this to poptParseArgvString() yields an argv of:
|
||||
\verbatim
|
||||
'--aaa'
|
||||
'--bbb'
|
||||
'--ccc'
|
||||
'--bla=bla'
|
||||
'--this_is=fdsafdas'
|
||||
'--5555=55555'
|
||||
'--test=with lots of spaces'
|
||||
\endverbatim
|
||||
*
|
||||
* @bug NULL is returned if file line is too long.
|
||||
* @bug Silently ignores invalid lines.
|
||||
*
|
||||
* @param fp file handle to read
|
||||
* @param *argstrp return string of options (malloc'd)
|
||||
* @param flags unused
|
||||
* @return 0 on success
|
||||
* @see poptParseArgvString
|
||||
*/
|
||||
/*@-fcnuse@*/
|
||||
int poptConfigFileToString(FILE *fp, /*@out@*/ char ** argstrp, int flags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, *argstrp, fileSystem @*/;
|
||||
/*@=fcnuse@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Return formatted error string for popt failure.
|
||||
* @param error popt error
|
||||
* @return error string
|
||||
*/
|
||||
/*@-redecl@*/
|
||||
/*@observer@*/ const char *poptStrerror(const int error)
|
||||
/*@*/;
|
||||
/*@=redecl@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Limit search for executables.
|
||||
* @param con context
|
||||
* @param path single path to search for executables
|
||||
* @param allowAbsolute absolute paths only?
|
||||
*/
|
||||
void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
|
||||
/*@modifies con @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Print detailed description of options.
|
||||
* @param con context
|
||||
* @param fp ouput file handle
|
||||
* @param flags (unused)
|
||||
*/
|
||||
void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Print terse description of options.
|
||||
* @param con context
|
||||
* @param fp ouput file handle
|
||||
* @param flags (unused)
|
||||
*/
|
||||
void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/;
|
||||
|
||||
/** \ingroup popt
|
||||
* Provide text to replace default "[OPTION...]" in help/usage output.
|
||||
* @param con context
|
||||
* @param text replacement text
|
||||
*/
|
||||
/*@-fcnuse@*/
|
||||
void poptSetOtherOptionHelp(poptContext con, const char * text)
|
||||
/*@modifies con @*/;
|
||||
/*@=fcnuse@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Return argv[0] from context.
|
||||
* @param con context
|
||||
* @return argv[0]
|
||||
*/
|
||||
/*@-redecl -fcnuse@*/
|
||||
/*@observer@*/ const char * poptGetInvocationName(poptContext con)
|
||||
/*@*/;
|
||||
/*@=redecl =fcnuse@*/
|
||||
|
||||
/** \ingroup popt
|
||||
* Shuffle argv pointers to remove stripped args, returns new argc.
|
||||
* @param con context
|
||||
* @param argc no. of args
|
||||
* @param argv arg vector
|
||||
* @return new argc
|
||||
*/
|
||||
/*@-fcnuse@*/
|
||||
int poptStrippedArgv(poptContext con, int argc, char ** argv)
|
||||
/*@modifies *argv @*/;
|
||||
/*@=fcnuse@*/
|
||||
|
||||
/**
|
||||
* Save a long, performing logical operation with value.
|
||||
* @warning Alignment check may be too strict on certain platorms.
|
||||
* @param arg integer pointer, aligned on int boundary.
|
||||
* @param argInfo logical operation (see POPT_ARGFLAG_*)
|
||||
* @param aLong value to use
|
||||
* @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
|
||||
*/
|
||||
/*@-incondefs@*/
|
||||
int poptSaveLong(/*@null@*/ long * arg, int argInfo, long aLong)
|
||||
/*@modifies *arg @*/
|
||||
/*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
|
||||
/*@=incondefs@*/
|
||||
|
||||
/**
|
||||
* Save an integer, performing logical operation with value.
|
||||
* @warning Alignment check may be too strict on certain platorms.
|
||||
* @param arg integer pointer, aligned on int boundary.
|
||||
* @param argInfo logical operation (see POPT_ARGFLAG_*)
|
||||
* @param aLong value to use
|
||||
* @return 0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION
|
||||
*/
|
||||
/*@-incondefs@*/
|
||||
int poptSaveInt(/*@null@*/ int * arg, int argInfo, long aLong)
|
||||
/*@modifies *arg @*/
|
||||
/*@requires maxSet(arg) >= 0 /\ maxRead(arg) == 0 @*/;
|
||||
/*@=incondefs@*/
|
||||
|
||||
/*@=type@*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
190
ctdb/lib/popt/poptconfig.c
Normal file
190
ctdb/lib/popt/poptconfig.c
Normal file
@ -0,0 +1,190 @@
|
||||
/** \ingroup popt
|
||||
* \file popt/poptconfig.c
|
||||
*/
|
||||
|
||||
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#include "system.h"
|
||||
#include "poptint.h"
|
||||
|
||||
/*@-compmempass@*/ /* FIX: item->option.longName kept, not dependent. */
|
||||
static void configLine(poptContext con, char * line)
|
||||
/*@modifies con @*/
|
||||
{
|
||||
/*@-type@*/
|
||||
int nameLength = strlen(con->appName);
|
||||
/*@=type@*/
|
||||
const char * entryType;
|
||||
const char * opt;
|
||||
poptItem item = alloca(sizeof(*item));
|
||||
int i, j;
|
||||
|
||||
/*@-boundswrite@*/
|
||||
memset(item, 0, sizeof(*item));
|
||||
|
||||
/*@-type@*/
|
||||
if (strncmp(line, con->appName, nameLength)) return;
|
||||
/*@=type@*/
|
||||
|
||||
line += nameLength;
|
||||
if (*line == '\0' || !isspace(*line)) return;
|
||||
|
||||
while (*line != '\0' && isspace(*line)) line++;
|
||||
entryType = line;
|
||||
while (*line == '\0' || !isspace(*line)) line++;
|
||||
*line++ = '\0';
|
||||
|
||||
while (*line != '\0' && isspace(*line)) line++;
|
||||
if (*line == '\0') return;
|
||||
opt = line;
|
||||
while (*line == '\0' || !isspace(*line)) line++;
|
||||
*line++ = '\0';
|
||||
|
||||
while (*line != '\0' && isspace(*line)) line++;
|
||||
if (*line == '\0') return;
|
||||
|
||||
/*@-temptrans@*/ /* FIX: line alias is saved */
|
||||
if (opt[0] == '-' && opt[1] == '-')
|
||||
item->option.longName = opt + 2;
|
||||
else if (opt[0] == '-' && opt[2] == '\0')
|
||||
item->option.shortName = opt[1];
|
||||
/*@=temptrans@*/
|
||||
|
||||
if (poptParseArgvString(line, &item->argc, &item->argv)) return;
|
||||
|
||||
/*@-modobserver@*/
|
||||
item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN;
|
||||
for (i = 0, j = 0; i < item->argc; i++, j++) {
|
||||
const char * f;
|
||||
if (!strncmp(item->argv[i], "--POPTdesc=", sizeof("--POPTdesc=")-1)) {
|
||||
f = item->argv[i] + sizeof("--POPTdesc=");
|
||||
if (f[0] == '$' && f[1] == '"') f++;
|
||||
item->option.descrip = f;
|
||||
item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
|
||||
j--;
|
||||
} else
|
||||
if (!strncmp(item->argv[i], "--POPTargs=", sizeof("--POPTargs=")-1)) {
|
||||
f = item->argv[i] + sizeof("--POPTargs=");
|
||||
if (f[0] == '$' && f[1] == '"') f++;
|
||||
item->option.argDescrip = f;
|
||||
item->option.argInfo &= ~POPT_ARGFLAG_DOC_HIDDEN;
|
||||
item->option.argInfo |= POPT_ARG_STRING;
|
||||
j--;
|
||||
} else
|
||||
if (j != i)
|
||||
item->argv[j] = item->argv[i];
|
||||
}
|
||||
if (j != i) {
|
||||
item->argv[j] = NULL;
|
||||
item->argc = j;
|
||||
}
|
||||
/*@=modobserver@*/
|
||||
/*@=boundswrite@*/
|
||||
|
||||
/*@-nullstate@*/ /* FIX: item->argv[] may be NULL */
|
||||
if (!strcmp(entryType, "alias"))
|
||||
(void) poptAddItem(con, item, 0);
|
||||
else if (!strcmp(entryType, "exec"))
|
||||
(void) poptAddItem(con, item, 1);
|
||||
/*@=nullstate@*/
|
||||
}
|
||||
/*@=compmempass@*/
|
||||
|
||||
int poptReadConfigFile(poptContext con, const char * fn)
|
||||
{
|
||||
const char * file, * chptr, * end;
|
||||
char * buf;
|
||||
/*@dependent@*/ char * dst;
|
||||
int fd, rc;
|
||||
off_t fileLength;
|
||||
|
||||
fd = open(fn, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
|
||||
|
||||
fileLength = lseek(fd, 0, SEEK_END);
|
||||
if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
|
||||
rc = errno;
|
||||
(void) close(fd);
|
||||
/*@-mods@*/
|
||||
errno = rc;
|
||||
/*@=mods@*/
|
||||
return POPT_ERROR_ERRNO;
|
||||
}
|
||||
|
||||
file = alloca(fileLength + 1);
|
||||
if (read(fd, (char *)file, fileLength) != fileLength) {
|
||||
rc = errno;
|
||||
(void) close(fd);
|
||||
/*@-mods@*/
|
||||
errno = rc;
|
||||
/*@=mods@*/
|
||||
return POPT_ERROR_ERRNO;
|
||||
}
|
||||
if (close(fd) == -1)
|
||||
return POPT_ERROR_ERRNO;
|
||||
|
||||
/*@-boundswrite@*/
|
||||
dst = buf = alloca(fileLength + 1);
|
||||
|
||||
chptr = file;
|
||||
end = (file + fileLength);
|
||||
/*@-infloops@*/ /* LCL: can't detect chptr++ */
|
||||
while (chptr < end) {
|
||||
switch (*chptr) {
|
||||
case '\n':
|
||||
*dst = '\0';
|
||||
dst = buf;
|
||||
while (*dst && isspace(*dst)) dst++;
|
||||
if (*dst && *dst != '#')
|
||||
configLine(con, dst);
|
||||
chptr++;
|
||||
/*@switchbreak@*/ break;
|
||||
case '\\':
|
||||
*dst++ = *chptr++;
|
||||
if (chptr < end) {
|
||||
if (*chptr == '\n')
|
||||
dst--, chptr++;
|
||||
/* \ at the end of a line does not insert a \n */
|
||||
else
|
||||
*dst++ = *chptr++;
|
||||
}
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
*dst++ = *chptr++;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
/*@=infloops@*/
|
||||
/*@=boundswrite@*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
|
||||
{
|
||||
char * fn, * home;
|
||||
int rc;
|
||||
|
||||
/*@-type@*/
|
||||
if (!con->appName) return 0;
|
||||
/*@=type@*/
|
||||
|
||||
rc = poptReadConfigFile(con, "/etc/popt");
|
||||
if (rc) return rc;
|
||||
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
||||
if (getuid() != geteuid()) return 0;
|
||||
#endif
|
||||
|
||||
if ((home = getenv("HOME"))) {
|
||||
fn = alloca(strlen(home) + 20);
|
||||
strcpy(fn, home);
|
||||
strcat(fn, "/.popt");
|
||||
rc = poptReadConfigFile(con, fn);
|
||||
if (rc) return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
742
ctdb/lib/popt/popthelp.c
Normal file
742
ctdb/lib/popt/popthelp.c
Normal file
@ -0,0 +1,742 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/*@-type@*/
|
||||
/** \ingroup popt
|
||||
* \file popt/popthelp.c
|
||||
*/
|
||||
|
||||
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#include "system.h"
|
||||
#include "poptint.h"
|
||||
|
||||
/**
|
||||
* Display arguments.
|
||||
* @param con context
|
||||
* @param foo (unused)
|
||||
* @param key option(s)
|
||||
* @param arg (unused)
|
||||
* @param data (unused)
|
||||
*/
|
||||
static void displayArgs(poptContext con,
|
||||
/*@unused@*/ enum poptCallbackReason foo,
|
||||
struct poptOption * key,
|
||||
/*@unused@*/ const char * arg, /*@unused@*/ void * data)
|
||||
/*@globals fileSystem@*/
|
||||
/*@modifies fileSystem@*/
|
||||
{
|
||||
if (key->shortName == '?')
|
||||
poptPrintHelp(con, stdout, 0);
|
||||
else
|
||||
poptPrintUsage(con, stdout, 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifdef NOTYET
|
||||
/*@unchecked@*/
|
||||
static int show_option_defaults = 0;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Empty table marker to enable displaying popt alias/exec options.
|
||||
*/
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
struct poptOption poptAliasOptions[] = {
|
||||
POPT_TABLEEND
|
||||
};
|
||||
|
||||
/**
|
||||
* Auto help table options.
|
||||
*/
|
||||
/*@-castfcnptr@*/
|
||||
/*@observer@*/ /*@unchecked@*/
|
||||
struct poptOption poptHelpOptions[] = {
|
||||
{ NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL },
|
||||
{ "help", '?', 0, NULL, '?', N_("Show this help message"), NULL },
|
||||
{ "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL },
|
||||
#ifdef NOTYET
|
||||
{ "defaults", '\0', POPT_ARG_NONE, &show_option_defaults, 0,
|
||||
N_("Display option defaults in message"), NULL },
|
||||
#endif
|
||||
POPT_TABLEEND
|
||||
} ;
|
||||
/*@=castfcnptr@*/
|
||||
|
||||
/**
|
||||
* @param table option(s)
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ static const char *const
|
||||
getTableTranslationDomain(/*@null@*/ const struct poptOption *table)
|
||||
/*@*/
|
||||
{
|
||||
const struct poptOption *opt;
|
||||
|
||||
if (table != NULL)
|
||||
for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
|
||||
if (opt->argInfo == POPT_ARG_INTL_DOMAIN)
|
||||
return opt->arg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
/*@observer@*/ /*@null@*/ static const char *const
|
||||
getArgDescrip(const struct poptOption * opt,
|
||||
/*@-paramuse@*/ /* FIX: i18n macros disabled with lclint */
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@=paramuse@*/
|
||||
/*@*/
|
||||
{
|
||||
if (!(opt->argInfo & POPT_ARG_MASK)) return NULL;
|
||||
|
||||
if (opt == (poptHelpOptions + 1) || opt == (poptHelpOptions + 2))
|
||||
if (opt->argDescrip) return POPT_(opt->argDescrip);
|
||||
|
||||
if (opt->argDescrip) return D_(translation_domain, opt->argDescrip);
|
||||
|
||||
switch (opt->argInfo & POPT_ARG_MASK) {
|
||||
case POPT_ARG_NONE: return POPT_("NONE");
|
||||
#ifdef DYING
|
||||
case POPT_ARG_VAL: return POPT_("VAL");
|
||||
#else
|
||||
case POPT_ARG_VAL: return NULL;
|
||||
#endif
|
||||
case POPT_ARG_INT: return POPT_("INT");
|
||||
case POPT_ARG_LONG: return POPT_("LONG");
|
||||
case POPT_ARG_STRING: return POPT_("STRING");
|
||||
case POPT_ARG_FLOAT: return POPT_("FLOAT");
|
||||
case POPT_ARG_DOUBLE: return POPT_("DOUBLE");
|
||||
default: return POPT_("ARG");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display default value for an option.
|
||||
* @param lineLength
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
* @return
|
||||
*/
|
||||
static /*@only@*/ /*@null@*/ char *
|
||||
singleOptionDefaultValue(int lineLength,
|
||||
const struct poptOption * opt,
|
||||
/*@-paramuse@*/ /* FIX: i18n macros disabled with lclint */
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@=paramuse@*/
|
||||
/*@*/
|
||||
{
|
||||
const char * defstr = D_(translation_domain, "default");
|
||||
char * le = malloc(4*lineLength + 1);
|
||||
char * l = le;
|
||||
|
||||
if (le == NULL) return NULL; /* XXX can't happen */
|
||||
/*@-boundswrite@*/
|
||||
*le = '\0';
|
||||
*le++ = '(';
|
||||
strcpy(le, defstr); le += strlen(le);
|
||||
*le++ = ':';
|
||||
*le++ = ' ';
|
||||
if (opt->arg) /* XXX programmer error */
|
||||
switch (opt->argInfo & POPT_ARG_MASK) {
|
||||
case POPT_ARG_VAL:
|
||||
case POPT_ARG_INT:
|
||||
{ long aLong = *((int *)opt->arg);
|
||||
le += sprintf(le, "%ld", aLong);
|
||||
} break;
|
||||
case POPT_ARG_LONG:
|
||||
{ long aLong = *((long *)opt->arg);
|
||||
le += sprintf(le, "%ld", aLong);
|
||||
} break;
|
||||
case POPT_ARG_FLOAT:
|
||||
{ double aDouble = *((float *)opt->arg);
|
||||
le += sprintf(le, "%g", aDouble);
|
||||
} break;
|
||||
case POPT_ARG_DOUBLE:
|
||||
{ double aDouble = *((double *)opt->arg);
|
||||
le += sprintf(le, "%g", aDouble);
|
||||
} break;
|
||||
case POPT_ARG_STRING:
|
||||
{ const char * s = *(const char **)opt->arg;
|
||||
if (s == NULL) {
|
||||
strcpy(le, "null"); le += strlen(le);
|
||||
} else {
|
||||
size_t slen = 4*lineLength - (le - l) - sizeof("\"...\")");
|
||||
*le++ = '"';
|
||||
strncpy(le, s, slen); le[slen] = '\0'; le += strlen(le);
|
||||
if (slen < strlen(s)) {
|
||||
strcpy(le, "..."); le += strlen(le);
|
||||
}
|
||||
*le++ = '"';
|
||||
}
|
||||
} break;
|
||||
case POPT_ARG_NONE:
|
||||
default:
|
||||
l = _free(l);
|
||||
return NULL;
|
||||
/*@notreached@*/ break;
|
||||
}
|
||||
*le++ = ')';
|
||||
*le = '\0';
|
||||
/*@=boundswrite@*/
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display help text for an option.
|
||||
* @param fp output file handle
|
||||
* @param maxLeftCol
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static void singleOptionHelp(FILE * fp, int maxLeftCol,
|
||||
const struct poptOption * opt,
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
int indentLength = maxLeftCol + 5;
|
||||
int lineLength = 79 - indentLength;
|
||||
const char * help = D_(translation_domain, opt->descrip);
|
||||
const char * argDescrip = getArgDescrip(opt, translation_domain);
|
||||
int helpLength;
|
||||
char * defs = NULL;
|
||||
char * left;
|
||||
int nb = maxLeftCol + 1;
|
||||
|
||||
/* Make sure there's more than enough room in target buffer. */
|
||||
if (opt->longName) nb += strlen(opt->longName);
|
||||
if (argDescrip) nb += strlen(argDescrip);
|
||||
|
||||
/*@-boundswrite@*/
|
||||
left = malloc(nb);
|
||||
if (left == NULL) return; /* XXX can't happen */
|
||||
left[0] = '\0';
|
||||
left[maxLeftCol] = '\0';
|
||||
|
||||
if (opt->longName && opt->shortName)
|
||||
sprintf(left, "-%c, %s%s", opt->shortName,
|
||||
((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
|
||||
opt->longName);
|
||||
else if (opt->shortName != '\0')
|
||||
sprintf(left, "-%c", opt->shortName);
|
||||
else if (opt->longName)
|
||||
sprintf(left, "%s%s",
|
||||
((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
|
||||
opt->longName);
|
||||
if (!*left) goto out;
|
||||
|
||||
if (argDescrip) {
|
||||
char * le = left + strlen(left);
|
||||
|
||||
if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
|
||||
*le++ = '[';
|
||||
|
||||
/* Choose type of output */
|
||||
/*@-branchstate@*/
|
||||
if (opt->argInfo & POPT_ARGFLAG_SHOW_DEFAULT) {
|
||||
defs = singleOptionDefaultValue(lineLength, opt, translation_domain);
|
||||
if (defs) {
|
||||
char * t = malloc((help ? strlen(help) : 0) +
|
||||
strlen(defs) + sizeof(" "));
|
||||
if (t) {
|
||||
char * te = t;
|
||||
*te = '\0';
|
||||
if (help) {
|
||||
strcpy(te, help); te += strlen(te);
|
||||
}
|
||||
*te++ = ' ';
|
||||
strcpy(te, defs);
|
||||
defs = _free(defs);
|
||||
}
|
||||
defs = t;
|
||||
}
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
if (opt->argDescrip == NULL) {
|
||||
switch (opt->argInfo & POPT_ARG_MASK) {
|
||||
case POPT_ARG_NONE:
|
||||
break;
|
||||
case POPT_ARG_VAL:
|
||||
#ifdef NOTNOW /* XXX pug ugly nerdy output */
|
||||
{ long aLong = opt->val;
|
||||
int ops = (opt->argInfo & POPT_ARGFLAG_LOGICALOPS);
|
||||
int negate = (opt->argInfo & POPT_ARGFLAG_NOT);
|
||||
|
||||
/* Don't bother displaying typical values */
|
||||
if (!ops && (aLong == 0L || aLong == 1L || aLong == -1L))
|
||||
break;
|
||||
*le++ = '[';
|
||||
switch (ops) {
|
||||
case POPT_ARGFLAG_OR:
|
||||
*le++ = '|';
|
||||
/*@innerbreak@*/ break;
|
||||
case POPT_ARGFLAG_AND:
|
||||
*le++ = '&';
|
||||
/*@innerbreak@*/ break;
|
||||
case POPT_ARGFLAG_XOR:
|
||||
*le++ = '^';
|
||||
/*@innerbreak@*/ break;
|
||||
default:
|
||||
/*@innerbreak@*/ break;
|
||||
}
|
||||
*le++ = '=';
|
||||
if (negate) *le++ = '~';
|
||||
/*@-formatconst@*/
|
||||
le += sprintf(le, (ops ? "0x%lx" : "%ld"), aLong);
|
||||
/*@=formatconst@*/
|
||||
*le++ = ']';
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case POPT_ARG_INT:
|
||||
case POPT_ARG_LONG:
|
||||
case POPT_ARG_FLOAT:
|
||||
case POPT_ARG_DOUBLE:
|
||||
case POPT_ARG_STRING:
|
||||
*le++ = '=';
|
||||
strcpy(le, argDescrip); le += strlen(le);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*le++ = '=';
|
||||
strcpy(le, argDescrip); le += strlen(le);
|
||||
}
|
||||
if (opt->argInfo & POPT_ARGFLAG_OPTIONAL)
|
||||
*le++ = ']';
|
||||
*le = '\0';
|
||||
}
|
||||
/*@=boundswrite@*/
|
||||
|
||||
if (help)
|
||||
fprintf(fp," %-*s ", maxLeftCol, left);
|
||||
else {
|
||||
fprintf(fp," %s\n", left);
|
||||
goto out;
|
||||
}
|
||||
|
||||
left = _free(left);
|
||||
if (defs) {
|
||||
help = defs; defs = NULL;
|
||||
}
|
||||
|
||||
helpLength = strlen(help);
|
||||
/*@-boundsread@*/
|
||||
while (helpLength > lineLength) {
|
||||
const char * ch;
|
||||
char format[16];
|
||||
|
||||
ch = help + lineLength - 1;
|
||||
while (ch > help && !isspace(*ch)) ch--;
|
||||
if (ch == help) break; /* give up */
|
||||
while (ch > (help + 1) && isspace(*ch)) ch--;
|
||||
ch++;
|
||||
|
||||
sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
|
||||
/*@-formatconst@*/
|
||||
fprintf(fp, format, help, " ");
|
||||
/*@=formatconst@*/
|
||||
help = ch;
|
||||
while (isspace(*help) && *help) help++;
|
||||
helpLength = strlen(help);
|
||||
}
|
||||
/*@=boundsread@*/
|
||||
|
||||
if (helpLength) fprintf(fp, "%s\n", help);
|
||||
|
||||
out:
|
||||
/*@-dependenttrans@*/
|
||||
defs = _free(defs);
|
||||
/*@=dependenttrans@*/
|
||||
left = _free(left);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static int maxArgWidth(const struct poptOption * opt,
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@*/
|
||||
{
|
||||
int max = 0;
|
||||
int len = 0;
|
||||
const char * s;
|
||||
|
||||
if (opt != NULL)
|
||||
while (opt->longName || opt->shortName || opt->arg) {
|
||||
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
|
||||
if (opt->arg) /* XXX program error */
|
||||
len = maxArgWidth(opt->arg, translation_domain);
|
||||
if (len > max) max = len;
|
||||
} else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
|
||||
len = sizeof(" ")-1;
|
||||
if (opt->shortName != '\0') len += sizeof("-X")-1;
|
||||
if (opt->shortName != '\0' && opt->longName) len += sizeof(", ")-1;
|
||||
if (opt->longName) {
|
||||
len += ((opt->argInfo & POPT_ARGFLAG_ONEDASH)
|
||||
? sizeof("-")-1 : sizeof("--")-1);
|
||||
len += strlen(opt->longName);
|
||||
}
|
||||
|
||||
s = getArgDescrip(opt, translation_domain);
|
||||
if (s)
|
||||
len += sizeof("=")-1 + strlen(s);
|
||||
if (opt->argInfo & POPT_ARGFLAG_OPTIONAL) len += sizeof("[]")-1;
|
||||
if (len > max) max = len;
|
||||
}
|
||||
|
||||
opt++;
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display popt alias and exec help.
|
||||
* @param fp output file handle
|
||||
* @param items alias/exec array
|
||||
* @param nitems no. of alias/exec entries
|
||||
* @param left
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static void itemHelp(FILE * fp,
|
||||
/*@null@*/ poptItem items, int nitems, int left,
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
poptItem item;
|
||||
int i;
|
||||
|
||||
if (items != NULL)
|
||||
for (i = 0, item = items; i < nitems; i++, item++) {
|
||||
const struct poptOption * opt;
|
||||
opt = &item->option;
|
||||
if ((opt->longName || opt->shortName) &&
|
||||
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
|
||||
singleOptionHelp(fp, left, opt, translation_domain);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display help text for a table of options.
|
||||
* @param con context
|
||||
* @param fp output file handle
|
||||
* @param table option(s)
|
||||
* @param left
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static void singleTableHelp(poptContext con, FILE * fp,
|
||||
/*@null@*/ const struct poptOption * table, int left,
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
const struct poptOption * opt;
|
||||
const char *sub_transdom;
|
||||
|
||||
if (table == poptAliasOptions) {
|
||||
itemHelp(fp, con->aliases, con->numAliases, left, NULL);
|
||||
itemHelp(fp, con->execs, con->numExecs, left, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (table != NULL)
|
||||
for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
|
||||
if ((opt->longName || opt->shortName) &&
|
||||
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
|
||||
singleOptionHelp(fp, left, opt, translation_domain);
|
||||
}
|
||||
|
||||
if (table != NULL)
|
||||
for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
|
||||
if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_INCLUDE_TABLE)
|
||||
continue;
|
||||
sub_transdom = getTableTranslationDomain(opt->arg);
|
||||
if (sub_transdom == NULL)
|
||||
sub_transdom = translation_domain;
|
||||
|
||||
if (opt->descrip)
|
||||
fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
|
||||
|
||||
singleTableHelp(con, fp, opt->arg, left, sub_transdom);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param con context
|
||||
* @param fp output file handle
|
||||
*/
|
||||
static int showHelpIntro(poptContext con, FILE * fp)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
int len = 6;
|
||||
const char * fn;
|
||||
|
||||
fprintf(fp, POPT_("Usage:"));
|
||||
if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
|
||||
/*@-boundsread@*/
|
||||
/*@-nullderef@*/ /* LCL: wazzup? */
|
||||
fn = con->optionStack->argv[0];
|
||||
/*@=nullderef@*/
|
||||
/*@=boundsread@*/
|
||||
if (fn == NULL) return len;
|
||||
if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
|
||||
fprintf(fp, " %s", fn);
|
||||
len += strlen(fn) + 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void poptPrintHelp(poptContext con, FILE * fp, /*@unused@*/ int flags)
|
||||
{
|
||||
int leftColWidth;
|
||||
|
||||
(void) showHelpIntro(con, fp);
|
||||
if (con->otherHelp)
|
||||
fprintf(fp, " %s\n", con->otherHelp);
|
||||
else
|
||||
fprintf(fp, " %s\n", POPT_("[OPTION...]"));
|
||||
|
||||
leftColWidth = maxArgWidth(con->options, NULL);
|
||||
singleTableHelp(con, fp, con->options, leftColWidth, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fp output file handle
|
||||
* @param cursor
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static int singleOptionUsage(FILE * fp, int cursor,
|
||||
const struct poptOption * opt,
|
||||
/*@null@*/ const char *translation_domain)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
int len = 4;
|
||||
char shortStr[2] = { '\0', '\0' };
|
||||
const char * item = shortStr;
|
||||
const char * argDescrip = getArgDescrip(opt, translation_domain);
|
||||
|
||||
if (opt->shortName != '\0' && opt->longName != NULL) {
|
||||
len += 2;
|
||||
if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH)) len++;
|
||||
len += strlen(opt->longName);
|
||||
} else if (opt->shortName != '\0') {
|
||||
len++;
|
||||
shortStr[0] = opt->shortName;
|
||||
shortStr[1] = '\0';
|
||||
} else if (opt->longName) {
|
||||
len += strlen(opt->longName);
|
||||
if (!(opt->argInfo & POPT_ARGFLAG_ONEDASH)) len++;
|
||||
item = opt->longName;
|
||||
}
|
||||
|
||||
if (len == 4) return cursor;
|
||||
|
||||
if (argDescrip)
|
||||
len += strlen(argDescrip) + 1;
|
||||
|
||||
if ((cursor + len) > 79) {
|
||||
fprintf(fp, "\n ");
|
||||
cursor = 7;
|
||||
}
|
||||
|
||||
if (opt->longName && opt->shortName) {
|
||||
fprintf(fp, " [-%c|-%s%s%s%s]",
|
||||
opt->shortName, ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "" : "-"),
|
||||
opt->longName,
|
||||
(argDescrip ? " " : ""),
|
||||
(argDescrip ? argDescrip : ""));
|
||||
} else {
|
||||
fprintf(fp, " [-%s%s%s%s]",
|
||||
((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"),
|
||||
item,
|
||||
(argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
|
||||
(argDescrip ? argDescrip : ""));
|
||||
}
|
||||
|
||||
return cursor + len + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display popt alias and exec usage.
|
||||
* @param fp output file handle
|
||||
* @param cursor
|
||||
* @param item alias/exec array
|
||||
* @param nitems no. of ara/exec entries
|
||||
* @param translation_domain translation domain
|
||||
*/
|
||||
static int itemUsage(FILE * fp, int cursor, poptItem item, int nitems,
|
||||
/*@null@*/ const char * translation_domain)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, fileSystem @*/
|
||||
{
|
||||
int i;
|
||||
|
||||
/*@-branchstate@*/ /* FIX: W2DO? */
|
||||
if (item != NULL)
|
||||
for (i = 0; i < nitems; i++, item++) {
|
||||
const struct poptOption * opt;
|
||||
opt = &item->option;
|
||||
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
|
||||
translation_domain = (const char *)opt->arg;
|
||||
} else if ((opt->longName || opt->shortName) &&
|
||||
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
|
||||
cursor = singleOptionUsage(fp, cursor, opt, translation_domain);
|
||||
}
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep track of option tables already processed.
|
||||
*/
|
||||
typedef struct poptDone_s {
|
||||
int nopts;
|
||||
int maxopts;
|
||||
const void ** opts;
|
||||
} * poptDone;
|
||||
|
||||
/**
|
||||
* Display usage text for a table of options.
|
||||
* @param con context
|
||||
* @param fp output file handle
|
||||
* @param cursor
|
||||
* @param opt option(s)
|
||||
* @param translation_domain translation domain
|
||||
* @param done tables already processed
|
||||
* @return
|
||||
*/
|
||||
static int singleTableUsage(poptContext con, FILE * fp, int cursor,
|
||||
/*@null@*/ const struct poptOption * opt,
|
||||
/*@null@*/ const char * translation_domain,
|
||||
/*@null@*/ poptDone done)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *fp, done, fileSystem @*/
|
||||
{
|
||||
/*@-branchstate@*/ /* FIX: W2DO? */
|
||||
if (opt != NULL)
|
||||
for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
|
||||
if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
|
||||
translation_domain = (const char *)opt->arg;
|
||||
} else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
|
||||
if (done) {
|
||||
int i = 0;
|
||||
for (i = 0; i < done->nopts; i++) {
|
||||
/*@-boundsread@*/
|
||||
const void * that = done->opts[i];
|
||||
/*@=boundsread@*/
|
||||
if (that == NULL || that != opt->arg)
|
||||
/*@innercontinue@*/ continue;
|
||||
/*@innerbreak@*/ break;
|
||||
}
|
||||
/* Skip if this table has already been processed. */
|
||||
if (opt->arg == NULL || i < done->nopts)
|
||||
continue;
|
||||
/*@-boundswrite@*/
|
||||
if (done->nopts < done->maxopts)
|
||||
done->opts[done->nopts++] = (const void *) opt->arg;
|
||||
/*@=boundswrite@*/
|
||||
}
|
||||
cursor = singleTableUsage(con, fp, cursor, opt->arg,
|
||||
translation_domain, done);
|
||||
} else if ((opt->longName || opt->shortName) &&
|
||||
!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
|
||||
cursor = singleOptionUsage(fp, cursor, opt, translation_domain);
|
||||
}
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return concatenated short options for display.
|
||||
* @todo Sub-tables should be recursed.
|
||||
* @param opt option(s)
|
||||
* @param fp output file handle
|
||||
* @retval str concatenation of short options
|
||||
* @return length of display string
|
||||
*/
|
||||
static int showShortOptions(const struct poptOption * opt, FILE * fp,
|
||||
/*@null@*/ char * str)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies *str, *fp, fileSystem @*/
|
||||
{
|
||||
char * s = alloca(300); /* larger than the ascii set */
|
||||
|
||||
s[0] = '\0';
|
||||
/*@-branchstate@*/ /* FIX: W2DO? */
|
||||
if (str == NULL) {
|
||||
memset(s, 0, sizeof(s));
|
||||
str = s;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
|
||||
/*@-boundswrite@*/
|
||||
if (opt != NULL)
|
||||
for (; (opt->longName || opt->shortName || opt->arg); opt++) {
|
||||
if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK))
|
||||
str[strlen(str)] = opt->shortName;
|
||||
else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
|
||||
if (opt->arg) /* XXX program error */
|
||||
(void) showShortOptions(opt->arg, fp, str);
|
||||
}
|
||||
/*@=boundswrite@*/
|
||||
|
||||
if (s != str || *s != '\0')
|
||||
return 0;
|
||||
|
||||
fprintf(fp, " [-%s]", s);
|
||||
return strlen(s) + 4;
|
||||
}
|
||||
|
||||
void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags)
|
||||
{
|
||||
poptDone done = memset(alloca(sizeof(*done)), 0, sizeof(*done));
|
||||
int cursor;
|
||||
|
||||
done->nopts = 0;
|
||||
done->maxopts = 64;
|
||||
cursor = done->maxopts * sizeof(*done->opts);
|
||||
/*@-boundswrite@*/
|
||||
done->opts = memset(alloca(cursor), 0, cursor);
|
||||
done->opts[done->nopts++] = (const void *) con->options;
|
||||
/*@=boundswrite@*/
|
||||
|
||||
cursor = showHelpIntro(con, fp);
|
||||
cursor += showShortOptions(con->options, fp, NULL);
|
||||
cursor = singleTableUsage(con, fp, cursor, con->options, NULL, done);
|
||||
cursor = itemUsage(fp, cursor, con->aliases, con->numAliases, NULL);
|
||||
cursor = itemUsage(fp, cursor, con->execs, con->numExecs, NULL);
|
||||
|
||||
if (con->otherHelp) {
|
||||
cursor += strlen(con->otherHelp) + 1;
|
||||
if (cursor > 79) fprintf(fp, "\n ");
|
||||
fprintf(fp, " %s", con->otherHelp);
|
||||
}
|
||||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
void poptSetOtherOptionHelp(poptContext con, const char * text)
|
||||
{
|
||||
con->otherHelp = _free(con->otherHelp);
|
||||
con->otherHelp = xstrdup(text);
|
||||
}
|
||||
/*@=type@*/
|
116
ctdb/lib/popt/poptint.h
Normal file
116
ctdb/lib/popt/poptint.h
Normal file
@ -0,0 +1,116 @@
|
||||
/** \ingroup popt
|
||||
* \file popt/poptint.h
|
||||
*/
|
||||
|
||||
/* (C) 1998-2000 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#ifndef H_POPTINT
|
||||
#define H_POPTINT
|
||||
|
||||
/**
|
||||
* Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
|
||||
* @param p memory to free
|
||||
* @retval NULL always
|
||||
*/
|
||||
/*@unused@*/ static inline /*@null@*/ void *
|
||||
_free(/*@only@*/ /*@null@*/ const void * p)
|
||||
/*@modifies p @*/
|
||||
{
|
||||
if (p != NULL) free((void *)p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Bit mask macros. */
|
||||
/*@-exporttype -redef @*/
|
||||
typedef unsigned int __pbm_bits;
|
||||
/*@=exporttype =redef @*/
|
||||
#define __PBM_NBITS (8 * sizeof (__pbm_bits))
|
||||
#define __PBM_IX(d) ((d) / __PBM_NBITS)
|
||||
#define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
|
||||
/*@-exporttype -redef @*/
|
||||
typedef struct {
|
||||
__pbm_bits bits[1];
|
||||
} pbm_set;
|
||||
/*@=exporttype =redef @*/
|
||||
#define __PBM_BITS(set) ((set)->bits)
|
||||
|
||||
#define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
|
||||
#define PBM_FREE(s) _free(s);
|
||||
#define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
|
||||
#define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
|
||||
#define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
|
||||
|
||||
struct optionStackEntry {
|
||||
int argc;
|
||||
/*@only@*/ /*@null@*/
|
||||
const char ** argv;
|
||||
/*@only@*/ /*@null@*/
|
||||
pbm_set * argb;
|
||||
int next;
|
||||
/*@only@*/ /*@null@*/
|
||||
const char * nextArg;
|
||||
/*@observer@*/ /*@null@*/
|
||||
const char * nextCharArg;
|
||||
/*@dependent@*/ /*@null@*/
|
||||
poptItem currAlias;
|
||||
int stuffed;
|
||||
};
|
||||
|
||||
struct poptContext_s {
|
||||
struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
|
||||
/*@dependent@*/
|
||||
struct optionStackEntry * os;
|
||||
/*@owned@*/ /*@null@*/
|
||||
const char ** leftovers;
|
||||
int numLeftovers;
|
||||
int nextLeftover;
|
||||
/*@keep@*/
|
||||
const struct poptOption * options;
|
||||
int restLeftover;
|
||||
/*@only@*/ /*@null@*/
|
||||
const char * appName;
|
||||
/*@only@*/ /*@null@*/
|
||||
poptItem aliases;
|
||||
int numAliases;
|
||||
int flags;
|
||||
/*@owned@*/ /*@null@*/
|
||||
poptItem execs;
|
||||
int numExecs;
|
||||
/*@only@*/ /*@null@*/
|
||||
const char ** finalArgv;
|
||||
int finalArgvCount;
|
||||
int finalArgvAlloced;
|
||||
/*@dependent@*/ /*@null@*/
|
||||
poptItem doExec;
|
||||
/*@only@*/
|
||||
const char * execPath;
|
||||
int execAbsolute;
|
||||
/*@only@*/
|
||||
const char * otherHelp;
|
||||
/*@null@*/
|
||||
pbm_set * arg_strip;
|
||||
};
|
||||
|
||||
#ifdef HAVE_LIBINTL_H
|
||||
#include <libintl.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
|
||||
#define _(foo) gettext(foo)
|
||||
#else
|
||||
#define _(foo) foo
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_DCGETTEXT) && !defined(__LCLINT__)
|
||||
#define D_(dom, str) dgettext(dom, str)
|
||||
#define POPT_(foo) D_("popt", foo)
|
||||
#else
|
||||
#define D_(dom, str) str
|
||||
#define POPT_(foo) foo
|
||||
#endif
|
||||
|
||||
#define N_(foo) foo
|
||||
|
||||
#endif
|
227
ctdb/lib/popt/poptparse.c
Normal file
227
ctdb/lib/popt/poptparse.c
Normal file
@ -0,0 +1,227 @@
|
||||
/** \ingroup popt
|
||||
* \file popt/poptparse.c
|
||||
*/
|
||||
|
||||
/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING
|
||||
file accompanying popt source distributions, available from
|
||||
ftp://ftp.rpm.org/pub/rpm/dist. */
|
||||
|
||||
#include "system.h"
|
||||
|
||||
#define POPT_ARGV_ARRAY_GROW_DELTA 5
|
||||
|
||||
/*@-boundswrite@*/
|
||||
int poptDupArgv(int argc, const char **argv,
|
||||
int * argcPtr, const char *** argvPtr)
|
||||
{
|
||||
size_t nb = (argc + 1) * sizeof(*argv);
|
||||
const char ** argv2;
|
||||
char * dst;
|
||||
int i;
|
||||
|
||||
if (argc <= 0 || argv == NULL) /* XXX can't happen */
|
||||
return POPT_ERROR_NOARG;
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (argv[i] == NULL)
|
||||
return POPT_ERROR_NOARG;
|
||||
nb += strlen(argv[i]) + 1;
|
||||
}
|
||||
|
||||
dst = malloc(nb);
|
||||
if (dst == NULL) /* XXX can't happen */
|
||||
return POPT_ERROR_MALLOC;
|
||||
argv2 = (void *) dst;
|
||||
dst += (argc + 1) * sizeof(*argv);
|
||||
|
||||
/*@-branchstate@*/
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv2[i] = dst;
|
||||
dst += strlen(strcpy(dst, argv[i])) + 1;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
argv2[argc] = NULL;
|
||||
|
||||
if (argvPtr) {
|
||||
*argvPtr = argv2;
|
||||
} else {
|
||||
free(argv2);
|
||||
argv2 = NULL;
|
||||
}
|
||||
if (argcPtr)
|
||||
*argcPtr = argc;
|
||||
return 0;
|
||||
}
|
||||
/*@=boundswrite@*/
|
||||
|
||||
/*@-bounds@*/
|
||||
int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr)
|
||||
{
|
||||
const char * src;
|
||||
char quote = '\0';
|
||||
int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
|
||||
const char ** argv = malloc(sizeof(*argv) * argvAlloced);
|
||||
int argc = 0;
|
||||
int buflen = strlen(s) + 1;
|
||||
char * buf = memset(alloca(buflen), 0, buflen);
|
||||
int rc = POPT_ERROR_MALLOC;
|
||||
|
||||
if (argv == NULL) return rc;
|
||||
argv[argc] = buf;
|
||||
|
||||
for (src = s; *src != '\0'; src++) {
|
||||
if (quote == *src) {
|
||||
quote = '\0';
|
||||
} else if (quote != '\0') {
|
||||
if (*src == '\\') {
|
||||
src++;
|
||||
if (!*src) {
|
||||
rc = POPT_ERROR_BADQUOTE;
|
||||
goto exit;
|
||||
}
|
||||
if (*src != quote) *buf++ = '\\';
|
||||
}
|
||||
*buf++ = *src;
|
||||
} else if (isspace(*src)) {
|
||||
if (*argv[argc] != '\0') {
|
||||
buf++, argc++;
|
||||
if (argc == argvAlloced) {
|
||||
argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
|
||||
argv = realloc(argv, sizeof(*argv) * argvAlloced);
|
||||
if (argv == NULL) goto exit;
|
||||
}
|
||||
argv[argc] = buf;
|
||||
}
|
||||
} else switch (*src) {
|
||||
case '"':
|
||||
case '\'':
|
||||
quote = *src;
|
||||
/*@switchbreak@*/ break;
|
||||
case '\\':
|
||||
src++;
|
||||
if (!*src) {
|
||||
rc = POPT_ERROR_BADQUOTE;
|
||||
goto exit;
|
||||
}
|
||||
/*@fallthrough@*/
|
||||
default:
|
||||
*buf++ = *src;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(argv[argc])) {
|
||||
argc++, buf++;
|
||||
}
|
||||
|
||||
rc = poptDupArgv(argc, argv, argcPtr, argvPtr);
|
||||
|
||||
exit:
|
||||
if (argv) free(argv);
|
||||
return rc;
|
||||
}
|
||||
/*@=bounds@*/
|
||||
|
||||
/* still in the dev stage.
|
||||
* return values, perhaps 1== file erro
|
||||
* 2== line to long
|
||||
* 3== umm.... more?
|
||||
*/
|
||||
int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ int flags)
|
||||
{
|
||||
char line[999];
|
||||
char * argstr;
|
||||
char * p;
|
||||
char * q;
|
||||
char * x;
|
||||
int t;
|
||||
int argvlen = 0;
|
||||
size_t maxlinelen = sizeof(line);
|
||||
size_t linelen;
|
||||
int maxargvlen = 480;
|
||||
int linenum = 0;
|
||||
|
||||
*argstrp = NULL;
|
||||
|
||||
/* | this_is = our_line
|
||||
* p q x
|
||||
*/
|
||||
|
||||
if (fp == NULL)
|
||||
return POPT_ERROR_NULLARG;
|
||||
|
||||
argstr = calloc(maxargvlen, sizeof(*argstr));
|
||||
if (argstr == NULL) return POPT_ERROR_MALLOC;
|
||||
|
||||
while (fgets(line, (int)maxlinelen, fp) != NULL) {
|
||||
linenum++;
|
||||
p = line;
|
||||
|
||||
/* loop until first non-space char or EOL */
|
||||
while( *p != '\0' && isspace(*p) )
|
||||
p++;
|
||||
|
||||
linelen = strlen(p);
|
||||
if (linelen >= maxlinelen-1)
|
||||
return POPT_ERROR_OVERFLOW; /* XXX line too long */
|
||||
|
||||
if (*p == '\0' || *p == '\n') continue; /* line is empty */
|
||||
if (*p == '#') continue; /* comment line */
|
||||
|
||||
q = p;
|
||||
|
||||
while (*q != '\0' && (!isspace(*q)) && *q != '=')
|
||||
q++;
|
||||
|
||||
if (isspace(*q)) {
|
||||
/* a space after the name, find next non space */
|
||||
*q++='\0';
|
||||
while( *q != '\0' && isspace((int)*q) ) q++;
|
||||
}
|
||||
if (*q == '\0') {
|
||||
/* single command line option (ie, no name=val, just name) */
|
||||
q[-1] = '\0'; /* kill off newline from fgets() call */
|
||||
argvlen += (t = q - p) + (sizeof(" --")-1);
|
||||
if (argvlen >= maxargvlen) {
|
||||
maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
|
||||
argstr = realloc(argstr, maxargvlen);
|
||||
if (argstr == NULL) return POPT_ERROR_MALLOC;
|
||||
}
|
||||
strcat(argstr, " --");
|
||||
strcat(argstr, p);
|
||||
continue;
|
||||
}
|
||||
if (*q != '=')
|
||||
continue; /* XXX for now, silently ignore bogus line */
|
||||
|
||||
/* *q is an equal sign. */
|
||||
*q++ = '\0';
|
||||
|
||||
/* find next non-space letter of value */
|
||||
while (*q != '\0' && isspace(*q))
|
||||
q++;
|
||||
if (*q == '\0')
|
||||
continue; /* XXX silently ignore missing value */
|
||||
|
||||
/* now, loop and strip all ending whitespace */
|
||||
x = p + linelen;
|
||||
while (isspace(*--x))
|
||||
*x = 0; /* null out last char if space (including fgets() NL) */
|
||||
|
||||
/* rest of line accept */
|
||||
t = x - p;
|
||||
argvlen += t + (sizeof("' --='")-1);
|
||||
if (argvlen >= maxargvlen) {
|
||||
maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
|
||||
argstr = realloc(argstr, maxargvlen);
|
||||
if (argstr == NULL) return POPT_ERROR_MALLOC;
|
||||
}
|
||||
strcat(argstr, " --");
|
||||
strcat(argstr, p);
|
||||
strcat(argstr, "=\"");
|
||||
strcat(argstr, q);
|
||||
strcat(argstr, "\"");
|
||||
}
|
||||
|
||||
*argstrp = argstr;
|
||||
return 0;
|
||||
}
|
10
ctdb/lib/popt/samba.m4
Normal file
10
ctdb/lib/popt/samba.m4
Normal file
@ -0,0 +1,10 @@
|
||||
m4_include(lib/popt/libpopt.m4)
|
||||
|
||||
if test x"$POPTOBJ" = "x"; then
|
||||
SMB_EXT_LIB(LIBPOPT, [${POPT_LIBS}])
|
||||
SMB_ENABLE(LIBPOPT,YES)
|
||||
else
|
||||
SMB_SUBSYSTEM(LIBPOPT,
|
||||
[lib/popt/findme.o lib/popt/popt.o lib/popt/poptconfig.o lib/popt/popthelp.o lib/popt/poptparse.o], [], [-Ilib/popt])
|
||||
fi
|
||||
|
74
ctdb/lib/popt/system.h
Normal file
74
ctdb/lib/popt/system.h
Normal file
@ -0,0 +1,74 @@
|
||||
#include "config.h"
|
||||
|
||||
#if defined (__GLIBC__) && defined(__LCLINT__)
|
||||
/*@-declundef@*/
|
||||
/*@unchecked@*/
|
||||
extern __const __int32_t *__ctype_tolower;
|
||||
/*@unchecked@*/
|
||||
extern __const __int32_t *__ctype_toupper;
|
||||
/*@=declundef@*/
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if HAVE_MCHECK_H
|
||||
#include <mcheck.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __NeXT
|
||||
/* access macros are not declared in non posix mode in unistd.h -
|
||||
don't try to use posix on NeXTstep 3.3 ! */
|
||||
#include <libc.h>
|
||||
#endif
|
||||
|
||||
#if defined(__LCLINT__)
|
||||
/*@-declundef -incondefs -redecl@*/ /* LCL: missing annotation */
|
||||
/*@only@*/ void * alloca (size_t __size)
|
||||
/*@ensures MaxSet(result) == (__size - 1) @*/
|
||||
/*@*/;
|
||||
/*@=declundef =incondefs =redecl@*/
|
||||
#endif
|
||||
|
||||
/* AIX requires this to be the first thing in the file. */
|
||||
#ifndef __GNUC__
|
||||
# if HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
# else
|
||||
# ifdef _AIX
|
||||
#pragma alloca
|
||||
# else
|
||||
# ifndef alloca /* predefined by HP cc +Olibcalls */
|
||||
char *alloca ();
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#elif defined(__GNUC__) && defined(__STRICT_ANSI__)
|
||||
#define alloca __builtin_alloca
|
||||
#endif
|
||||
|
||||
/*@-redecl -redef@*/
|
||||
/*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str)
|
||||
/*@*/;
|
||||
/*@=redecl =redef@*/
|
||||
|
||||
#if HAVE_MCHECK_H && defined(__GNUC__)
|
||||
#define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
|
||||
#define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
|
||||
#else
|
||||
#define xstrdup(_str) strdup(_str)
|
||||
#endif /* HAVE_MCHECK_H && defined(__GNUC__) */
|
||||
|
||||
|
||||
#include "popt.h"
|
4
ctdb/lib/replace/.checker_innocent
Normal file
4
ctdb/lib/replace/.checker_innocent
Normal file
@ -0,0 +1,4 @@
|
||||
>>>MISTAKE21_create_files_6a9e68ada99a97cb
|
||||
>>>MISTAKE21_os2_delete_9b2bfa7f38711d09
|
||||
>>>MISTAKE21_os2_delete_2fcc29aaa99a97cb
|
||||
>>>SECURITY2_os2_delete_9b2bfa7f1c9396ca
|
60
ctdb/lib/replace/Makefile.in
Normal file
60
ctdb/lib/replace/Makefile.in
Normal file
@ -0,0 +1,60 @@
|
||||
#!gmake
|
||||
#
|
||||
CC = @CC@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
VPATH = @libreplacedir@
|
||||
srcdir = @srcdir@
|
||||
builddir = @builddir@
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
.PHONY: test
|
||||
|
||||
CFLAGS=-I. -I@libreplacedir@ @CFLAGS@
|
||||
|
||||
OBJS = @LIBREPLACEOBJ@
|
||||
|
||||
all: showflags libreplace.a testsuite
|
||||
|
||||
showflags:
|
||||
@echo 'libreplace will be compiled with flags:'
|
||||
@echo ' CC = $(CC)'
|
||||
@echo ' CFLAGS = $(CFLAGS)'
|
||||
@echo ' LIBS = $(LIBS)'
|
||||
|
||||
install: all
|
||||
mkdir -p $(libdir)
|
||||
$(INSTALL) libreplace.a $(libdir)
|
||||
|
||||
libreplace.a: $(OBJS)
|
||||
ar -rcsv $@ $(OBJS)
|
||||
|
||||
test: all
|
||||
./testsuite
|
||||
|
||||
installcheck: install test
|
||||
|
||||
TEST_OBJS = test/testsuite.o test/os2_delete.o
|
||||
|
||||
testsuite: libreplace.a $(TEST_OBJS)
|
||||
$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace
|
||||
|
||||
.c.o:
|
||||
@echo Compiling $*.c
|
||||
@mkdir -p `dirname $@`
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o test/*.o *.a testsuite
|
||||
rm -f testfile.dat
|
||||
|
||||
distclean: clean
|
||||
rm -f *~ */*~
|
||||
rm -f config.log config.status config.h config.cache
|
||||
rm -f Makefile
|
||||
|
||||
realdistclean: distclean
|
||||
rm -f configure config.h.in
|
88
ctdb/lib/replace/README
Normal file
88
ctdb/lib/replace/README
Normal file
@ -0,0 +1,88 @@
|
||||
This subsystem ensures that we can always use a certain core set of
|
||||
functions and types, that are either provided by the OS or by replacement
|
||||
functions / definitions in this subsystem. The aim is to try to stick
|
||||
to POSIX functions in here as much as possible. Convenience functions
|
||||
that are available on no platform at all belong in other subsystems
|
||||
(such as LIBUTIL).
|
||||
|
||||
The following functions are guaranteed:
|
||||
|
||||
ftruncate
|
||||
strlcpy
|
||||
strlcat
|
||||
mktime
|
||||
rename
|
||||
innetgr
|
||||
initgroups
|
||||
memmove
|
||||
strdup
|
||||
inet_ntoa
|
||||
setlinebuf
|
||||
vsyslog
|
||||
timegm
|
||||
setenv
|
||||
strndup
|
||||
strnlen
|
||||
waitpid
|
||||
seteuid
|
||||
setegid
|
||||
asprintf
|
||||
snprintf
|
||||
vasprintf
|
||||
vsnprintf
|
||||
opendir
|
||||
readdir
|
||||
telldir
|
||||
seekdir
|
||||
closedir
|
||||
dlopen
|
||||
dlclose
|
||||
dlsym
|
||||
dlerror
|
||||
chroot
|
||||
bzero
|
||||
strerror
|
||||
errno
|
||||
mkdtemp
|
||||
mkstemp (a secure one!)
|
||||
pread
|
||||
pwrite
|
||||
getpass
|
||||
readline (the library)
|
||||
inet_ntoa
|
||||
strtoll
|
||||
strtoull
|
||||
socketpair
|
||||
|
||||
Types:
|
||||
bool
|
||||
socklen_t
|
||||
uint_t
|
||||
uint{8,16,32,64}_t
|
||||
int{8,16,32,64}_t
|
||||
intptr_t
|
||||
|
||||
Constants:
|
||||
PATH_NAME_MAX
|
||||
UINT{16,32,64}_MAX
|
||||
INT32_MAX
|
||||
RTLD_LAZY
|
||||
HOST_NAME_MAX
|
||||
UINT16_MAX
|
||||
UINT32_MAX
|
||||
UINT64_MAX
|
||||
CHAR_BIT
|
||||
|
||||
Macros:
|
||||
va_copy
|
||||
__FUNCTION__
|
||||
__STRING
|
||||
MIN
|
||||
MAX
|
||||
QSORT_CAST
|
||||
|
||||
Prerequisites:
|
||||
memset (for bzero)
|
||||
syslog (for vsyslog)
|
||||
setnetgrent, getnetgrent, endnetgrent (for innetgr)
|
||||
mktemp (for mkstemp and mkdtemp)
|
1
ctdb/lib/replace/aclocal.m4
vendored
Normal file
1
ctdb/lib/replace/aclocal.m4
vendored
Normal file
@ -0,0 +1 @@
|
||||
m4_include(libreplace.m4)
|
197
ctdb/lib/replace/autoconf-2.60.m4
Normal file
197
ctdb/lib/replace/autoconf-2.60.m4
Normal file
@ -0,0 +1,197 @@
|
||||
# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
|
||||
# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
|
||||
# --------------------------------------------------------------
|
||||
# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
|
||||
# by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails,
|
||||
# try again with each compiler option in the space-separated OPTION-LIST; if one
|
||||
# helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE,
|
||||
# else ACTION-IF-UNAVAILABLE.
|
||||
AC_DEFUN([_AC_C_STD_TRY],
|
||||
[AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C]))
|
||||
AC_CACHE_VAL(ac_cv_prog_cc_$1,
|
||||
[ac_cv_prog_cc_$1=no
|
||||
ac_save_CC=$CC
|
||||
AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
|
||||
for ac_arg in '' $4
|
||||
do
|
||||
CC="$ac_save_CC $ac_arg"
|
||||
_AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
|
||||
test "x$ac_cv_prog_cc_$1" != "xno" && break
|
||||
done
|
||||
rm -f conftest.$ac_ext
|
||||
CC=$ac_save_CC
|
||||
])# AC_CACHE_VAL
|
||||
case "x$ac_cv_prog_cc_$1" in
|
||||
x)
|
||||
AC_MSG_RESULT([none needed]) ;;
|
||||
xno)
|
||||
AC_MSG_RESULT([unsupported]) ;;
|
||||
*)
|
||||
CC="$CC $ac_cv_prog_cc_$1"
|
||||
AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
|
||||
esac
|
||||
AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
|
||||
])# _AC_C_STD_TRY
|
||||
|
||||
# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
|
||||
# ----------------------------------------------------------------
|
||||
# If the C compiler is not in ISO C99 mode by default, try to add an
|
||||
# option to output variable CC to make it so. This macro tries
|
||||
# various options that select ISO C99 on some system or another. It
|
||||
# considers the compiler to be in ISO C99 mode if it handles mixed
|
||||
# code and declarations, _Bool, inline and restrict.
|
||||
AC_DEFUN([_AC_PROG_CC_C99],
|
||||
[_AC_C_STD_TRY([c99],
|
||||
[[#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct incomplete_array
|
||||
{
|
||||
int datasize;
|
||||
double data[];
|
||||
};
|
||||
|
||||
struct named_init {
|
||||
int number;
|
||||
const wchar_t *name;
|
||||
double average;
|
||||
};
|
||||
|
||||
typedef const char *ccp;
|
||||
|
||||
static inline int
|
||||
test_restrict(ccp restrict text)
|
||||
{
|
||||
// See if C++-style comments work.
|
||||
// Iterate through items via the restricted pointer.
|
||||
// Also check for declarations in for loops.
|
||||
for (unsigned int i = 0; *(text+i) != '\0'; ++i)
|
||||
continue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check varargs and va_copy work.
|
||||
static void
|
||||
test_varargs(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
const char *str;
|
||||
int number;
|
||||
float fnumber;
|
||||
|
||||
while (*format)
|
||||
{
|
||||
switch (*format++)
|
||||
{
|
||||
case 's': // string
|
||||
str = va_arg(args_copy, const char *);
|
||||
break;
|
||||
case 'd': // int
|
||||
number = va_arg(args_copy, int);
|
||||
break;
|
||||
case 'f': // float
|
||||
fnumber = (float) va_arg(args_copy, double);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
va_end(args_copy);
|
||||
va_end(args);
|
||||
}
|
||||
]],
|
||||
[[
|
||||
// Check bool and long long datatypes.
|
||||
_Bool success = false;
|
||||
long long int bignum = -1234567890LL;
|
||||
unsigned long long int ubignum = 1234567890uLL;
|
||||
|
||||
// Check restrict.
|
||||
if (test_restrict("String literal") != 0)
|
||||
success = true;
|
||||
char *restrict newvar = "Another string";
|
||||
|
||||
// Check varargs.
|
||||
test_varargs("s, d' f .", "string", 65, 34.234);
|
||||
|
||||
// Check incomplete arrays work.
|
||||
struct incomplete_array *ia =
|
||||
malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10));
|
||||
ia->datasize = 10;
|
||||
for (int i = 0; i < ia->datasize; ++i)
|
||||
ia->data[i] = (double) i * 1.234;
|
||||
|
||||
// Check named initialisers.
|
||||
struct named_init ni = {
|
||||
.number = 34,
|
||||
.name = L"Test wide string",
|
||||
.average = 543.34343,
|
||||
};
|
||||
|
||||
ni.number = 58;
|
||||
|
||||
int dynamic_array[ni.number];
|
||||
dynamic_array[43] = 543;
|
||||
|
||||
// work around unused variable warnings
|
||||
return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x';
|
||||
]],
|
||||
dnl Try
|
||||
dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
|
||||
dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99)
|
||||
dnl Intel ICC -c99
|
||||
dnl IRIX -c99
|
||||
dnl Solaris (unused because it causes the compiler to assume C99 semantics for
|
||||
dnl library functions, and this is invalid before Solaris 10: -xc99)
|
||||
dnl Tru64 -c99
|
||||
dnl with extended modes being tried first.
|
||||
[[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl
|
||||
])# _AC_PROG_CC_C99
|
||||
|
||||
# AC_PROG_CC_C99
|
||||
# --------------
|
||||
AC_DEFUN([AC_PROG_CC_C99],
|
||||
[ AC_REQUIRE([AC_PROG_CC])dnl
|
||||
_AC_PROG_CC_C99
|
||||
])
|
||||
|
||||
# AC_USE_SYSTEM_EXTENSIONS
|
||||
# ------------------------
|
||||
# Enable extensions on systems that normally disable them,
|
||||
# typically due to standards-conformance issues.
|
||||
AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
|
||||
[
|
||||
AC_BEFORE([$0], [AC_COMPILE_IFELSE])
|
||||
AC_BEFORE([$0], [AC_RUN_IFELSE])
|
||||
|
||||
AC_REQUIRE([AC_GNU_SOURCE])
|
||||
AC_REQUIRE([AC_AIX])
|
||||
AC_REQUIRE([AC_MINIX])
|
||||
|
||||
AH_VERBATIM([__EXTENSIONS__],
|
||||
[/* Enable extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif])
|
||||
AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
|
||||
[ac_cv_safe_to_define___extensions__],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM([
|
||||
# define __EXTENSIONS__ 1
|
||||
AC_INCLUDES_DEFAULT])],
|
||||
[ac_cv_safe_to_define___extensions__=yes],
|
||||
[ac_cv_safe_to_define___extensions__=no])])
|
||||
test $ac_cv_safe_to_define___extensions__ = yes &&
|
||||
AC_DEFINE([__EXTENSIONS__])
|
||||
AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
|
||||
])
|
13
ctdb/lib/replace/autogen.sh
Executable file
13
ctdb/lib/replace/autogen.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf autom4te.cache
|
||||
rm -f configure config.h.in
|
||||
|
||||
autoheader || exit 1
|
||||
autoconf || exit 1
|
||||
|
||||
rm -rf autom4te.cache
|
||||
|
||||
echo "Now run ./configure and then make."
|
||||
exit 0
|
||||
|
1466
ctdb/lib/replace/config.guess
vendored
Executable file
1466
ctdb/lib/replace/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
690
ctdb/lib/replace/config.h.in
Normal file
690
ctdb/lib/replace/config.h.in
Normal file
@ -0,0 +1,690 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Whether strndup is broken */
|
||||
#undef BROKEN_STRNDUP
|
||||
|
||||
/* Whether strnlen is broken */
|
||||
#undef BROKEN_STRNLEN
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#undef HAVE_ARPA_INET_H
|
||||
|
||||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#undef HAVE_ASPRINTF
|
||||
|
||||
/* Whether the bool type is available */
|
||||
#undef HAVE_BOOL
|
||||
|
||||
/* Define to 1 if you have the `bzero' function. */
|
||||
#undef HAVE_BZERO
|
||||
|
||||
/* Whether there is a C99 compliant vsnprintf */
|
||||
#undef HAVE_C99_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `chroot' function. */
|
||||
#undef HAVE_CHROOT
|
||||
|
||||
/* Define to 1 if you have the `chsize' function. */
|
||||
#undef HAVE_CHSIZE
|
||||
|
||||
/* Whether or not we have comparison_fn_t */
|
||||
#undef HAVE_COMPARISON_FN_T
|
||||
|
||||
/* Define to 1 if you have the <compat.h> header file. */
|
||||
#undef HAVE_COMPAT_H
|
||||
|
||||
/* Define to 1 if you have the <ctype.h> header file. */
|
||||
#undef HAVE_CTYPE_H
|
||||
|
||||
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_ASPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_VASPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <direct.h> header file. */
|
||||
#undef HAVE_DIRECT_H
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
|
||||
/* Define to 1 if you have the `dlclose' function. */
|
||||
#undef HAVE_DLCLOSE
|
||||
|
||||
/* Define to 1 if you have the `dlerror' function. */
|
||||
#undef HAVE_DLERROR
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `dlopen' function. */
|
||||
#undef HAVE_DLOPEN
|
||||
|
||||
/* Define to 1 if you have the `dlsym' function. */
|
||||
#undef HAVE_DLSYM
|
||||
|
||||
/* Define to 1 if you have the `endnetgrent' function. */
|
||||
#undef HAVE_ENDNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `epoll_create' function. */
|
||||
#undef HAVE_EPOLL_CREATE
|
||||
|
||||
/* Whether errno() is available */
|
||||
#undef HAVE_ERRNO_DECL
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <fnmatch.h> header file. */
|
||||
#undef HAVE_FNMATCH_H
|
||||
|
||||
/* Define to 1 if you have the `ftruncate' function. */
|
||||
#undef HAVE_FTRUNCATE
|
||||
|
||||
/* Whether there is a __FUNCTION__ macro */
|
||||
#undef HAVE_FUNCTION_MACRO
|
||||
|
||||
/* Define to 1 if you have the `getdents' function. */
|
||||
#undef HAVE_GETDENTS
|
||||
|
||||
/* Define to 1 if you have the `getdirentries' function. */
|
||||
#undef HAVE_GETDIRENTRIES
|
||||
|
||||
/* Define to 1 if you have the `getnetgrent' function. */
|
||||
#undef HAVE_GETNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `getpgrp' function. */
|
||||
#undef HAVE_GETPGRP
|
||||
|
||||
/* Define to 1 if you have the <grp.h> header file. */
|
||||
#undef HAVE_GRP_H
|
||||
|
||||
/* Whether the compiler supports immediate structures */
|
||||
#undef HAVE_IMMEDIATE_STRUCTURES
|
||||
|
||||
/* Define to 1 if you have the `initgroups' function. */
|
||||
#undef HAVE_INITGROUPS
|
||||
|
||||
/* Define to 1 if you have the `innetgr' function. */
|
||||
#undef HAVE_INNETGR
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define to 1 if the system has the type `long long'. */
|
||||
#undef HAVE_LONG_LONG
|
||||
|
||||
/* Define to 1 if you have the `lstat' function. */
|
||||
#undef HAVE_LSTAT
|
||||
|
||||
/* Define to 1 if you have the `memcpy' function. */
|
||||
#undef HAVE_MEMCPY
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#undef HAVE_MEMMOVE
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define if target mkdir supports mode option */
|
||||
#undef HAVE_MKDIR_MODE
|
||||
|
||||
/* Define to 1 if you have the `mkdtemp' function. */
|
||||
#undef HAVE_MKDTEMP
|
||||
|
||||
/* Define to 1 if you have the `mktime' function. */
|
||||
#undef HAVE_MKTIME
|
||||
|
||||
/* Whether mmap works */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#undef HAVE_NETDB_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#undef HAVE_NETINET_IN_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in_ip.h> header file. */
|
||||
#undef HAVE_NETINET_IN_IP_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in_systm.h> header file. */
|
||||
#undef HAVE_NETINET_IN_SYSTM_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/ip.h> header file. */
|
||||
#undef HAVE_NETINET_IP_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/tcp.h> header file. */
|
||||
#undef HAVE_NETINET_TCP_H
|
||||
|
||||
/* usability of net/if.h */
|
||||
#undef HAVE_NET_IF_H
|
||||
|
||||
/* Whether the open(2) accepts O_DIRECT */
|
||||
#undef HAVE_OPEN_O_DIRECT
|
||||
|
||||
/* Define to 1 if you have the `pipe' function. */
|
||||
#undef HAVE_PIPE
|
||||
|
||||
/* Define to 1 if you have the `pread' function. */
|
||||
#undef HAVE_PREAD
|
||||
|
||||
/* Define to 1 if you have the `printf' function. */
|
||||
#undef HAVE_PRINTF
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#undef HAVE_PWD_H
|
||||
|
||||
/* Define to 1 if you have the `pwrite' function. */
|
||||
#undef HAVE_PWRITE
|
||||
|
||||
/* Define to 1 if you have the `rand' function. */
|
||||
#undef HAVE_RAND
|
||||
|
||||
/* Define to 1 if you have the `random' function. */
|
||||
#undef HAVE_RANDOM
|
||||
|
||||
/* Define to 1 if you have the `rename' function. */
|
||||
#undef HAVE_RENAME
|
||||
|
||||
/* Whether mkstemp is secure */
|
||||
#undef HAVE_SECURE_MKSTEMP
|
||||
|
||||
/* Define to 1 if you have the `setbuffer' function. */
|
||||
#undef HAVE_SETBUFFER
|
||||
|
||||
/* Define to 1 if you have the `setegid' function. */
|
||||
#undef HAVE_SETEGID
|
||||
|
||||
/* Define to 1 if you have the `setenv' function. */
|
||||
#undef HAVE_SETENV
|
||||
|
||||
/* Define to 1 if you have the `seteuid' function. */
|
||||
#undef HAVE_SETEUID
|
||||
|
||||
/* Define to 1 if you have the `setlinebuf' function. */
|
||||
#undef HAVE_SETLINEBUF
|
||||
|
||||
/* Define to 1 if you have the `setnetgrent' function. */
|
||||
#undef HAVE_SETNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `setresgid' function. */
|
||||
#undef HAVE_SETRESGID
|
||||
|
||||
/* Whether setresgid() is available */
|
||||
#undef HAVE_SETRESGID_DECL
|
||||
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
#undef HAVE_SETRESUID
|
||||
|
||||
/* Whether setresuid() is available */
|
||||
#undef HAVE_SETRESUID_DECL
|
||||
|
||||
/* Define to 1 if you have the <shadow.h> header file. */
|
||||
#undef HAVE_SHADOW_H
|
||||
|
||||
/* Whether we have the atomic_t variable type */
|
||||
#undef HAVE_SIG_ATOMIC_T_TYPE
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `srand' function. */
|
||||
#undef HAVE_SRAND
|
||||
|
||||
/* Define to 1 if you have the `srandom' function. */
|
||||
#undef HAVE_SRANDOM
|
||||
|
||||
/* Define to 1 if you have the <standards.h> header file. */
|
||||
#undef HAVE_STANDARDS_H
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#undef HAVE_STDARG_H
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#undef HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#undef HAVE_STDIO_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strcasestr' function. */
|
||||
#undef HAVE_STRCASESTR
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#undef HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the `strftime' function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcat' function. */
|
||||
#undef HAVE_STRLCAT
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#undef HAVE_STRNDUP
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#undef HAVE_STRNLEN
|
||||
|
||||
/* Define to 1 if you have the `strtok_r' function. */
|
||||
#undef HAVE_STRTOK_R
|
||||
|
||||
/* Define to 1 if you have the `strtoll' function. */
|
||||
#undef HAVE_STRTOLL
|
||||
|
||||
/* Define to 1 if you have the `strtoq' function. */
|
||||
#undef HAVE_STRTOQ
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
#undef HAVE_STRTOULL
|
||||
|
||||
/* Define to 1 if you have the `strtouq' function. */
|
||||
#undef HAVE_STRTOUQ
|
||||
|
||||
/* Define to 1 if `st_rdev' is member of `struct stat'. */
|
||||
#undef HAVE_STRUCT_STAT_ST_RDEV
|
||||
|
||||
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
|
||||
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
|
||||
#undef HAVE_ST_RDEV
|
||||
|
||||
/* Define to 1 if you have the `syslog' function. */
|
||||
#undef HAVE_SYSLOG
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#undef HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/acl.h> header file. */
|
||||
#undef HAVE_SYS_ACL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/capability.h> header file. */
|
||||
#undef HAVE_SYS_CAPABILITY_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/epoll.h> header file. */
|
||||
#undef HAVE_SYS_EPOLL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fcntl.h> header file. */
|
||||
#undef HAVE_SYS_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filio.h> header file. */
|
||||
#undef HAVE_SYS_FILIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filsys.h> header file. */
|
||||
#undef HAVE_SYS_FILSYS_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fs/s5param.h> header file. */
|
||||
#undef HAVE_SYS_FS_S5PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/id.h> header file. */
|
||||
#undef HAVE_SYS_ID_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ipc.h> header file. */
|
||||
#undef HAVE_SYS_IPC_H
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#undef HAVE_SYS_MMAN_H
|
||||
|
||||
/* Define to 1 if you have the <sys/mode.h> header file. */
|
||||
#undef HAVE_SYS_MODE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/priv.h> header file. */
|
||||
#undef HAVE_SYS_PRIV_H
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
#undef HAVE_SYS_RESOURCE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/security.h> header file. */
|
||||
#undef HAVE_SYS_SECURITY_H
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/shm.h> header file. */
|
||||
#undef HAVE_SYS_SHM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/sockio.h> header file. */
|
||||
#undef HAVE_SYS_SOCKIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/syslog.h> header file. */
|
||||
#undef HAVE_SYS_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/termio.h> header file. */
|
||||
#undef HAVE_SYS_TERMIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <sys/un.h> header file. */
|
||||
#undef HAVE_SYS_UN_H
|
||||
|
||||
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the <termios.h> header file. */
|
||||
#undef HAVE_TERMIOS_H
|
||||
|
||||
/* Define to 1 if you have the <termio.h> header file. */
|
||||
#undef HAVE_TERMIO_H
|
||||
|
||||
/* Define to 1 if you have the `timegm' function. */
|
||||
#undef HAVE_TIMEGM
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#undef HAVE_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
/* Define to 1 if you have the <vararg.h> header file. */
|
||||
#undef HAVE_VARARG_H
|
||||
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#undef HAVE_VASPRINTF
|
||||
|
||||
/* Whether va_copy() is available */
|
||||
#undef HAVE_VA_COPY
|
||||
|
||||
/* Whether the C compiler understands volatile */
|
||||
#undef HAVE_VOLATILE
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `vsyslog' function. */
|
||||
#undef HAVE_VSYSLOG
|
||||
|
||||
/* Define to 1 if you have the `waitpid' function. */
|
||||
#undef HAVE_WAITPID
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Define to 1 if you have the <winsock2.h> header file. */
|
||||
#undef HAVE_WINSOCK2_H
|
||||
|
||||
/* Define to 1 if you have the <ws2tcpip.h> header file. */
|
||||
#undef HAVE_WS2TCPIP_H
|
||||
|
||||
/* Whether the _Bool type is available */
|
||||
#undef HAVE__Bool
|
||||
|
||||
/* Whether the __VA_ARGS__ macro is available */
|
||||
#undef HAVE__VA_ARGS__MACRO
|
||||
|
||||
/* Define to 1 if you have the `__strtoll' function. */
|
||||
#undef HAVE___STRTOLL
|
||||
|
||||
/* Define to 1 if you have the `__strtoull' function. */
|
||||
#undef HAVE___STRTOULL
|
||||
|
||||
/* Whether __va_copy() is available */
|
||||
#undef HAVE___VA_COPY
|
||||
|
||||
/* Whether there is a __func__ macro */
|
||||
#undef HAVE_func_MACRO
|
||||
|
||||
/* Whether MMAP is broken */
|
||||
#undef MMAP_BLACKLIST
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Whether getpass should be replaced */
|
||||
#undef REPLACE_GETPASS
|
||||
|
||||
/* Whether inet_ntoa should be replaced */
|
||||
#undef REPLACE_INET_NTOA
|
||||
|
||||
/* replace readdir */
|
||||
#undef REPLACE_READDIR
|
||||
|
||||
/* replace readdir using getdents() */
|
||||
#undef REPLACE_READDIR_GETDENTS
|
||||
|
||||
/* replace readdir using getdirentries() */
|
||||
#undef REPLACE_READDIR_GETDIRENTRIES
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Whether seekdir returns an int */
|
||||
#undef SEEKDIR_RETURNS_INT
|
||||
|
||||
/* The size of `char', as computed by sizeof. */
|
||||
#undef SIZEOF_CHAR
|
||||
|
||||
/* The size of `int', as computed by sizeof. */
|
||||
#undef SIZEOF_INT
|
||||
|
||||
/* The size of `long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG
|
||||
|
||||
/* The size of `long long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG_LONG
|
||||
|
||||
/* The size of `off_t', as computed by sizeof. */
|
||||
#undef SIZEOF_OFF_T
|
||||
|
||||
/* The size of `short', as computed by sizeof. */
|
||||
#undef SIZEOF_SHORT
|
||||
|
||||
/* The size of `size_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SIZE_T
|
||||
|
||||
/* The size of `ssize_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SSIZE_T
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Whether telldir takes a const pointer */
|
||||
#undef TELLDIR_TAKES_CONST_DIR
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to 1 if on MINIX. */
|
||||
#undef _MINIX
|
||||
|
||||
#ifndef _OSF_SOURCE
|
||||
# define _OSF_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
||||
this defined. */
|
||||
#undef _POSIX_1_SOURCE
|
||||
|
||||
/* Whether to enable POSIX support */
|
||||
#undef _POSIX_C_SOURCE
|
||||
|
||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Whether to enable System V compatibility */
|
||||
#undef _SYSV
|
||||
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
# define _XOPEN_SOURCE_EXTENDED 1
|
||||
#endif
|
||||
|
||||
/* Enable extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef ino_t
|
||||
|
||||
/* Define to `short' if <sys/types.h> does not define. */
|
||||
#undef int16_t
|
||||
|
||||
/* Define to `long' if <sys/types.h> does not define. */
|
||||
#undef int32_t
|
||||
|
||||
/* Define to `long long' if <sys/types.h> does not define. */
|
||||
#undef int64_t
|
||||
|
||||
/* Define to `char' if <sys/types.h> does not define. */
|
||||
#undef int8_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef intptr_t
|
||||
|
||||
/* Define to `off_t' if <sys/types.h> does not define. */
|
||||
#undef loff_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `loff_t' if <sys/types.h> does not define. */
|
||||
#undef offset_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef ptrdiff_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Socket length type */
|
||||
#undef socklen_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Define to `unsigned short' if <sys/types.h> does not define. */
|
||||
#undef uint16_t
|
||||
|
||||
/* Define to `unsigned long' if <sys/types.h> does not define. */
|
||||
#undef uint32_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef uint64_t
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#undef uint8_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef uint_t
|
1579
ctdb/lib/replace/config.sub
vendored
Executable file
1579
ctdb/lib/replace/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
22
ctdb/lib/replace/configure.ac
Normal file
22
ctdb/lib/replace/configure.ac
Normal file
@ -0,0 +1,22 @@
|
||||
AC_PREREQ(2.50)
|
||||
AC_INIT(replace.c)
|
||||
AC_CONFIG_SRCDIR([replace.c])
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_LIBREPLACE_ALL_CHECKS
|
||||
|
||||
if test "$ac_cv_prog_gcc" = yes; then
|
||||
CFLAGS="$CFLAGS -Wall"
|
||||
CFLAGS="$CFLAGS -W"
|
||||
CFLAGS="$CFLAGS -Wshadow"
|
||||
CFLAGS="$CFLAGS -Wstrict-prototypes"
|
||||
CFLAGS="$CFLAGS -Wpointer-arith"
|
||||
CFLAGS="$CFLAGS -Wcast-qual"
|
||||
CFLAGS="$CFLAGS -Wcast-align"
|
||||
CFLAGS="$CFLAGS -Wwrite-strings"
|
||||
CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
|
||||
CFLAGS="$CFLAGS -Wformat=2"
|
||||
CFLAGS="$CFLAGS -Wno-format-y2k"
|
||||
fi
|
||||
|
||||
AC_OUTPUT(Makefile)
|
54
ctdb/lib/replace/dlfcn.c
Normal file
54
ctdb/lib/replace/dlfcn.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Samba system utilities
|
||||
Copyright (C) Andrew Tridgell 1992-1998
|
||||
Copyright (C) Jeremy Allison 1998-2002
|
||||
|
||||
** NOTE! The following LGPL license applies to the replace
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
|
||||
#ifndef HAVE_DLOPEN
|
||||
void *rep_dlopen(const char *name, int flags)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLSYM
|
||||
void *rep_dlsym(void *handle, const char *symbol)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLERROR
|
||||
char *rep_dlerror(void)
|
||||
{
|
||||
return "dynamic loading of objects not supported on this platform";
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLCLOSE
|
||||
int rep_dlclose(void *handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
20
ctdb/lib/replace/dlfcn.m4
Normal file
20
ctdb/lib/replace/dlfcn.m4
Normal file
@ -0,0 +1,20 @@
|
||||
dnl dummies provided by dlfcn.c if not available
|
||||
save_LIBS="$LIBS"
|
||||
LIBS=""
|
||||
|
||||
AC_SEARCH_LIBS(dlopen, dl)
|
||||
|
||||
if test "$ac_cv_search_dlopen" != no; then
|
||||
AC_CHECK_HEADERS(dlfcn.h)
|
||||
|
||||
libreplace_cv_dlfcn=no
|
||||
AC_CHECK_FUNCS([dlopen dlsym dlerror dlclose],[],[libreplace_cv_dlfcn=yes])
|
||||
|
||||
if test x"${libreplace_cv_dlfcn}" = x"yes";then
|
||||
LIBREPLACEOBJ="${LIBREPLACEOBJ} dlfcn.o"
|
||||
fi
|
||||
fi
|
||||
|
||||
LIBDL="$LIBS"
|
||||
AC_SUBST(LIBDL)
|
||||
LIBS="$save_LIBS"
|
212
ctdb/lib/replace/getpass.c
Normal file
212
ctdb/lib/replace/getpass.c
Normal file
@ -0,0 +1,212 @@
|
||||
/* Copyright (C) 1992-1998 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
/* Modified to use with samba by Jeremy Allison, 8th July 1995. */
|
||||
|
||||
#include "replace.h"
|
||||
|
||||
#if defined(HAVE_TERMIOS_H)
|
||||
/* POSIX terminal handling. */
|
||||
#include <termios.h>
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
/* Older SYSV terminal handling - don't use if we can avoid it. */
|
||||
#include <termio.h>
|
||||
#elif defined(HAVE_SYS_TERMIO_H)
|
||||
/* Older SYSV terminal handling - don't use if we can avoid it. */
|
||||
#include <sys/termio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define additional missing types
|
||||
*/
|
||||
#ifndef HAVE_SIG_ATOMIC_T_TYPE
|
||||
typedef int sig_atomic_t;
|
||||
#endif
|
||||
|
||||
#ifndef SIGCLD
|
||||
#define SIGCLD SIGCHLD
|
||||
#endif
|
||||
|
||||
#ifndef SIGNAL_CAST
|
||||
#define SIGNAL_CAST (RETSIGTYPE (*)(int))
|
||||
#endif
|
||||
|
||||
#ifdef REPLACE_GETPASS
|
||||
|
||||
#ifdef SYSV_TERMIO
|
||||
|
||||
/* SYSTEM V TERMIO HANDLING */
|
||||
|
||||
static struct termio t;
|
||||
|
||||
#define ECHO_IS_ON(t) ((t).c_lflag & ECHO)
|
||||
#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO)
|
||||
#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO)
|
||||
|
||||
#ifndef TCSAFLUSH
|
||||
#define TCSAFLUSH 1
|
||||
#endif
|
||||
|
||||
#ifndef TCSANOW
|
||||
#define TCSANOW 0
|
||||
#endif
|
||||
|
||||
static int tcgetattr(int fd, struct termio *_t)
|
||||
{
|
||||
return ioctl(fd, TCGETA, _t);
|
||||
}
|
||||
|
||||
static int tcsetattr(int fd, int flags, struct termio *_t)
|
||||
{
|
||||
if(flags & TCSAFLUSH)
|
||||
ioctl(fd, TCFLSH, TCIOFLUSH);
|
||||
return ioctl(fd, TCSETS, _t);
|
||||
}
|
||||
|
||||
#elif !defined(TCSAFLUSH)
|
||||
|
||||
/* BSD TERMIO HANDLING */
|
||||
|
||||
static struct sgttyb t;
|
||||
|
||||
#define ECHO_IS_ON(t) ((t).sg_flags & ECHO)
|
||||
#define TURN_ECHO_OFF(t) ((t).sg_flags &= ~ECHO)
|
||||
#define TURN_ECHO_ON(t) ((t).sg_flags |= ECHO)
|
||||
|
||||
#define TCSAFLUSH 1
|
||||
#define TCSANOW 0
|
||||
|
||||
static int tcgetattr(int fd, struct sgttyb *_t)
|
||||
{
|
||||
return ioctl(fd, TIOCGETP, (char *)_t);
|
||||
}
|
||||
|
||||
static int tcsetattr(int fd, int flags, struct sgttyb *_t)
|
||||
{
|
||||
return ioctl(fd, TIOCSETP, (char *)_t);
|
||||
}
|
||||
|
||||
#else /* POSIX TERMIO HANDLING */
|
||||
#define ECHO_IS_ON(t) ((t).c_lflag & ECHO)
|
||||
#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO)
|
||||
#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO)
|
||||
|
||||
static struct termios t;
|
||||
#endif /* SYSV_TERMIO */
|
||||
|
||||
static void catch_signal(int signum,void (*handler)(int ))
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction act;
|
||||
struct sigaction oldact;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
|
||||
act.sa_handler = handler;
|
||||
#ifdef SA_RESTART
|
||||
/*
|
||||
* We *want* SIGALRM to interrupt a system call.
|
||||
*/
|
||||
if(signum != SIGALRM)
|
||||
act.sa_flags = SA_RESTART;
|
||||
#endif
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaddset(&act.sa_mask,signum);
|
||||
sigaction(signum,&act,&oldact);
|
||||
return oldact.sa_handler;
|
||||
#else /* !HAVE_SIGACTION */
|
||||
/* FIXME: need to handle sigvec and systems with broken signal() */
|
||||
return signal(signum, handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *getsmbpass(const char *prompt)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int echo_off;
|
||||
static char buf[256];
|
||||
static size_t bufsize = sizeof(buf);
|
||||
size_t nread;
|
||||
|
||||
/* Catch problematic signals */
|
||||
catch_signal(SIGINT, SIGNAL_CAST SIG_IGN);
|
||||
|
||||
/* Try to write to and read from the terminal if we can.
|
||||
If we can't open the terminal, use stderr and stdin. */
|
||||
|
||||
in = fopen ("/dev/tty", "w+");
|
||||
if (in == NULL)
|
||||
{
|
||||
in = stdin;
|
||||
out = stderr;
|
||||
}
|
||||
else
|
||||
out = in;
|
||||
|
||||
setvbuf(in, NULL, _IONBF, 0);
|
||||
|
||||
/* Turn echoing off if it is on now. */
|
||||
|
||||
if (tcgetattr (fileno (in), &t) == 0)
|
||||
{
|
||||
if (ECHO_IS_ON(t))
|
||||
{
|
||||
TURN_ECHO_OFF(t);
|
||||
echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0;
|
||||
TURN_ECHO_ON(t);
|
||||
}
|
||||
else
|
||||
echo_off = 0;
|
||||
}
|
||||
else
|
||||
echo_off = 0;
|
||||
|
||||
/* Write the prompt. */
|
||||
fputs (prompt, out);
|
||||
fflush (out);
|
||||
|
||||
/* Read the password. */
|
||||
buf[0] = 0;
|
||||
fgets(buf, bufsize, in);
|
||||
nread = strlen(buf);
|
||||
if (buf[nread - 1] == '\n')
|
||||
buf[nread - 1] = '\0';
|
||||
|
||||
/* Restore echoing. */
|
||||
if (echo_off)
|
||||
(void) tcsetattr (fileno (in), TCSANOW, &t);
|
||||
|
||||
if (in != stdin)
|
||||
/* We opened the terminal; now close it. */
|
||||
fclose (in);
|
||||
|
||||
/* Catch problematic signals */
|
||||
catch_signal(SIGINT, SIGNAL_CAST SIG_DFL);
|
||||
|
||||
printf("\n");
|
||||
return buf;
|
||||
}
|
||||
|
||||
#else
|
||||
void getsmbpasswd_dummy(void);
|
||||
void getsmbpasswd_dummy(void) {;}
|
||||
#endif
|
17
ctdb/lib/replace/getpass.m4
Normal file
17
ctdb/lib/replace/getpass.m4
Normal file
@ -0,0 +1,17 @@
|
||||
AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[
|
||||
SAVE_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS -I$libreplacedir/"
|
||||
AC_TRY_COMPILE([
|
||||
#include "confdefs.h"
|
||||
#define _LIBREPLACE_REPLACE_H
|
||||
#define REPLACE_GETPASS 1
|
||||
#define main dont_declare_main
|
||||
#include "$libreplacedir/getpass.c"
|
||||
#undef main
|
||||
],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no)
|
||||
CPPFLAGS="$SAVE_CPPFLAGS"
|
||||
])
|
||||
if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then
|
||||
AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
|
||||
LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"
|
||||
fi
|
51
ctdb/lib/replace/havenone.h
Normal file
51
ctdb/lib/replace/havenone.h
Normal file
@ -0,0 +1,51 @@
|
||||
#undef HAVE_TIMEGM
|
||||
#undef HAVE_ASPRINTF
|
||||
#undef HAVE_BOOL
|
||||
#undef HAVE_BZERO
|
||||
#undef HAVE_C99_VSNPRINTF
|
||||
#undef HAVE_CHROOT
|
||||
#undef HAVE_CHSIZE
|
||||
#undef HAVE_COMPARISON_FN_T
|
||||
#undef HAVE_DECL_ASPRINTF
|
||||
#undef HAVE_DECL_SNPRINTF
|
||||
#undef HAVE_DECL_VASPRINTF
|
||||
#undef HAVE_DECL_VSNPRINTF
|
||||
#undef HAVE_DLCLOSE
|
||||
#undef HAVE_DLERROR
|
||||
#undef HAVE_DLOPEN
|
||||
#undef HAVE_DLSYM
|
||||
#undef HAVE_ENDNETGRENT
|
||||
#undef HAVE_GETNETGRENT
|
||||
#undef HAVE_INITGROUPS
|
||||
#undef HAVE_INNETGR
|
||||
#undef HAVE_MEMCPY
|
||||
#undef HAVE_MEMMOVE
|
||||
#undef HAVE_MEMSET
|
||||
#undef HAVE_MKDTEMP
|
||||
#undef HAVE_MKTIME
|
||||
#undef HAVE_PREAD
|
||||
#undef HAVE_PRINTF
|
||||
#undef HAVE_PWRITE
|
||||
#undef HAVE_RENAME
|
||||
#undef HAVE_SECURE_MKSTEMP
|
||||
#undef HAVE_SETENV
|
||||
#undef HAVE_SETLINEBUF
|
||||
#undef HAVE_SETNETGRENT
|
||||
#undef HAVE_SETRESGID
|
||||
#undef HAVE_SETRESUID
|
||||
#undef HAVE_SIG_ATOMIC_T_TYPE
|
||||
#undef HAVE_SNPRINTF
|
||||
#undef HAVE_STRCASESTR
|
||||
#undef HAVE_STRDUP
|
||||
#undef HAVE_STRLCAT
|
||||
#undef HAVE_STRLCPY
|
||||
#undef HAVE_STRNDUP
|
||||
#undef HAVE_STRNLEN
|
||||
#undef HAVE_STRTOK_R
|
||||
#undef HAVE_SYSLOG
|
||||
#undef HAVE_TIMEGM
|
||||
#undef HAVE_VASPRINTF
|
||||
#undef HAVE_VA_COPY
|
||||
#undef HAVE_VSNPRINTF
|
||||
#undef HAVE_VSYSLOG
|
||||
#undef HAVE_WAITPID
|
238
ctdb/lib/replace/install-sh
Executable file
238
ctdb/lib/replace/install-sh
Executable file
@ -0,0 +1,238 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
#
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
355
ctdb/lib/replace/libreplace.m4
Normal file
355
ctdb/lib/replace/libreplace.m4
Normal file
@ -0,0 +1,355 @@
|
||||
AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
|
||||
[
|
||||
echo "LIBREPLACE_LOCATION_CHECKS: START"
|
||||
|
||||
dnl find the libreplace sources. This is meant to work both for
|
||||
dnl libreplace standalone builds, and builds of packages using libreplace
|
||||
libreplacedir=""
|
||||
libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace"
|
||||
for d in $libreplacepaths; do
|
||||
if test -f "$d/replace.c"; then
|
||||
libreplacedir="$d"
|
||||
AC_SUBST(libreplacedir)
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if test x"$libreplacedir" = "x"; then
|
||||
AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
|
||||
fi
|
||||
LIBREPLACEOBJ="replace.o"
|
||||
AC_SUBST(LIBREPLACEOBJ)
|
||||
|
||||
AC_CANONICAL_BUILD
|
||||
AC_CANONICAL_HOST
|
||||
AC_CANONICAL_TARGET
|
||||
|
||||
echo "LIBREPLACE_LOCATION_CHECKS: END"
|
||||
]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
|
||||
|
||||
|
||||
AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
|
||||
[
|
||||
echo "LIBREPLACE_BROKEN_CHECKS: START"
|
||||
|
||||
dnl find the libreplace sources. This is meant to work both for
|
||||
dnl libreplace standalone builds, and builds of packages using libreplace
|
||||
libreplacedir=""
|
||||
for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
|
||||
if test -f "$d/replace.c"; then
|
||||
libreplacedir="$d"
|
||||
AC_SUBST(libreplacedir)
|
||||
break;
|
||||
fi
|
||||
done
|
||||
LIBREPLACEOBJ="replace.o"
|
||||
AC_SUBST(LIBREPLACEOBJ)
|
||||
|
||||
LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
|
||||
|
||||
AC_TYPE_SIGNAL
|
||||
AC_TYPE_UID_T
|
||||
AC_TYPE_MODE_T
|
||||
AC_TYPE_OFF_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_PID_T
|
||||
AC_STRUCT_ST_RDEV
|
||||
AC_CHECK_TYPE(ino_t,unsigned)
|
||||
AC_CHECK_TYPE(loff_t,off_t)
|
||||
AC_CHECK_TYPE(offset_t,loff_t)
|
||||
|
||||
AC_FUNC_MEMCMP
|
||||
|
||||
AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
|
||||
|
||||
AC_CHECK_HEADERS(stdbool.h sys/select.h)
|
||||
AC_CHECK_HEADERS(setjmp.h)
|
||||
|
||||
AC_CHECK_TYPE(bool,
|
||||
[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
|
||||
[
|
||||
AC_INCLUDES_DEFAULT
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif]
|
||||
)
|
||||
|
||||
AC_CHECK_TYPE(_Bool,
|
||||
[AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
|
||||
[
|
||||
AC_INCLUDES_DEFAULT
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif]
|
||||
)
|
||||
|
||||
AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
|
||||
AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
|
||||
samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
|
||||
if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
|
||||
AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
|
||||
fi
|
||||
|
||||
|
||||
AC_CHECK_HEADERS(sys/syslog.h syslog.h)
|
||||
AC_CHECK_HEADERS(sys/time.h time.h)
|
||||
AC_CHECK_HEADERS(stdarg.h vararg.h)
|
||||
AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
|
||||
AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
|
||||
AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
|
||||
|
||||
|
||||
dnl we need to check that net/if.h really can be used, to cope with hpux
|
||||
dnl where including it always fails
|
||||
AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
AC_INCLUDES_DEFAULT
|
||||
#if HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
#include <net/if.h>
|
||||
int main(void) {return 0;}])],
|
||||
[libreplace_cv_USABLE_NET_IF_H=yes],
|
||||
[libreplace_cv_USABLE_NET_IF_H=no]
|
||||
)
|
||||
])
|
||||
if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
|
||||
AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
main() { struct in_addr ip; ip.s_addr = 0x12345678;
|
||||
if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
|
||||
strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
|
||||
exit(1);}],
|
||||
samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
|
||||
if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
|
||||
AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
|
||||
fi
|
||||
|
||||
dnl Provided by replace.c:
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#if STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#include <sys/socket.h>],
|
||||
[socklen_t foo;],,
|
||||
[AC_DEFINE(socklen_t, int,[Socket length type])])
|
||||
|
||||
AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
|
||||
AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
|
||||
AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
|
||||
AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
|
||||
AC_HAVE_DECL(setresuid, [#include <unistd.h>])
|
||||
AC_HAVE_DECL(setresgid, [#include <unistd.h>])
|
||||
AC_HAVE_DECL(errno, [#include <errno.h>])
|
||||
|
||||
AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
|
||||
AC_TRY_RUN([#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
main() {
|
||||
struct stat st;
|
||||
char tpl[20]="/tmp/test.XXXXXX";
|
||||
int fd = mkstemp(tpl);
|
||||
if (fd == -1) exit(1);
|
||||
unlink(tpl);
|
||||
if (fstat(fd, &st) != 0) exit(1);
|
||||
if ((st.st_mode & 0777) != 0600) exit(1);
|
||||
exit(0);
|
||||
}],
|
||||
samba_cv_HAVE_SECURE_MKSTEMP=yes,
|
||||
samba_cv_HAVE_SECURE_MKSTEMP=no,
|
||||
samba_cv_HAVE_SECURE_MKSTEMP=cross)])
|
||||
if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
|
||||
AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
|
||||
fi
|
||||
|
||||
dnl Provided by snprintf.c:
|
||||
AC_CHECK_HEADERS(stdio.h strings.h)
|
||||
AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
|
||||
AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
|
||||
|
||||
AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
void foo(const char *format, ...) {
|
||||
va_list ap;
|
||||
int len;
|
||||
char buf[20];
|
||||
long long l = 1234567890;
|
||||
l *= 100;
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(buf, 0, format, ap);
|
||||
va_end(ap);
|
||||
if (len != 5) exit(1);
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(0, 0, format, ap);
|
||||
va_end(ap);
|
||||
if (len != 5) exit(2);
|
||||
|
||||
if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
|
||||
|
||||
if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
|
||||
if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
|
||||
if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
|
||||
if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
main() { foo("hello"); }
|
||||
],
|
||||
samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
|
||||
if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
|
||||
AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
|
||||
fi
|
||||
|
||||
|
||||
dnl VA_COPY
|
||||
AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
|
||||
AC_TRY_LINK([#include <stdarg.h>
|
||||
va_list ap1,ap2;], [va_copy(ap1,ap2);],
|
||||
samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
|
||||
if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
|
||||
AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
|
||||
fi
|
||||
|
||||
if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
|
||||
AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
|
||||
AC_TRY_LINK([#include <stdarg.h>
|
||||
va_list ap1,ap2;], [__va_copy(ap1,ap2);],
|
||||
samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
|
||||
if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
|
||||
AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl __FUNCTION__ macro
|
||||
AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
|
||||
AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
|
||||
samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
|
||||
if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
|
||||
AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
|
||||
else
|
||||
dnl __func__ macro
|
||||
AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
|
||||
AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
|
||||
samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
|
||||
if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
|
||||
AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS([sys/param.h limits.h])
|
||||
|
||||
AC_CHECK_TYPE(comparison_fn_t,
|
||||
[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
|
||||
|
||||
AC_CHECK_FUNCS(strnlen setenv)
|
||||
AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
|
||||
|
||||
# this test disabled as we don't actually need __VA_ARGS__ yet
|
||||
AC_TRY_CPP([
|
||||
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
|
||||
eprintf("bla", "bar");
|
||||
], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
|
||||
|
||||
# Check prerequisites
|
||||
AC_CHECK_FUNCS([memset printf syslog], [],
|
||||
[ AC_MSG_ERROR([Required function not found])])
|
||||
|
||||
AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#if STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#include <signal.h>],[sig_atomic_t i = 0],
|
||||
samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
|
||||
if test x"$samba_cv_sig_atomic_t" = x"yes"; then
|
||||
AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
|
||||
fi
|
||||
|
||||
|
||||
AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
|
||||
AC_TRY_COMPILE([
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif],
|
||||
[int fd = open("/dev/null", O_DIRECT);],
|
||||
samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
|
||||
if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
|
||||
AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
|
||||
fi
|
||||
|
||||
|
||||
AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
|
||||
dnl Check whether the compiler can generate precompiled headers
|
||||
touch conftest.h
|
||||
if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
|
||||
precompiled_headers=yes
|
||||
else
|
||||
precompiled_headers=no
|
||||
fi])
|
||||
AC_SUBST(precompiled_headers)
|
||||
|
||||
|
||||
dnl Check if the C compiler understands volatile (it should, being ANSI).
|
||||
AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
|
||||
AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
|
||||
samba_cv_volatile=yes,samba_cv_volatile=no)])
|
||||
if test x"$samba_cv_volatile" = x"yes"; then
|
||||
AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
|
||||
fi
|
||||
|
||||
m4_include(system/config.m4)
|
||||
|
||||
m4_include(dlfcn.m4)
|
||||
m4_include(getpass.m4)
|
||||
m4_include(win32.m4)
|
||||
m4_include(timegm.m4)
|
||||
m4_include(repdir.m4)
|
||||
|
||||
AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
|
||||
[AC_MSG_ERROR([Required function not found])])
|
||||
|
||||
echo "LIBREPLACE_BROKEN_CHECKS: END"
|
||||
]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
|
||||
|
||||
AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
|
||||
[
|
||||
#LIBREPLACE_ALL_CHECKS: START"
|
||||
])
|
||||
AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
|
||||
[
|
||||
#LIBREPLACE_ALL_CHECKS: END"
|
||||
])
|
||||
m4_define(AC_LIBREPLACE_ALL_CHECKS,
|
||||
[
|
||||
AC__LIBREPLACE_ALL_CHECKS_START
|
||||
AC_LIBREPLACE_LOCATION_CHECKS
|
||||
AC_LIBREPLACE_CC_CHECKS
|
||||
AC_LIBREPLACE_BROKEN_CHECKS
|
||||
AC__LIBREPLACE_ALL_CHECKS_END
|
||||
])
|
||||
|
||||
m4_include(libreplace_cc.m4)
|
||||
m4_include(libreplace_macros.m4)
|
||||
m4_include(autoconf-2.60.m4)
|
167
ctdb/lib/replace/libreplace_cc.m4
Normal file
167
ctdb/lib/replace/libreplace_cc.m4
Normal file
@ -0,0 +1,167 @@
|
||||
|
||||
AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_START,
|
||||
[
|
||||
echo "LIBREPLACE_CC_CHECKS: START"
|
||||
])
|
||||
|
||||
AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_END,
|
||||
[
|
||||
echo "LIBREPLACE_CC_CHECKS: END"
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl
|
||||
dnl AC_LIBREPLACE_CC_CHECKS
|
||||
dnl
|
||||
dnl Note: we need to use m4_define instead of AC_DEFUN because
|
||||
dnl of the ordering of tests
|
||||
dnl
|
||||
dnl
|
||||
m4_define(AC_LIBREPLACE_CC_CHECKS,
|
||||
[
|
||||
AC__LIBREPLACE_ONLY_CC_CHECKS_START
|
||||
|
||||
dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it
|
||||
dnl which conflicts with C99 on HPUX
|
||||
ac_cv_prog_cc_Ae=no
|
||||
|
||||
savedCFLAGS=$CFLAGS
|
||||
AC_PROG_CC
|
||||
CFLAGS=$savedCFLAGS
|
||||
|
||||
dnl don't try for C99 if we are using gcc, as otherwise we
|
||||
dnl lose immediate structure constants
|
||||
if test x"$GCC" != x"yes" ; then
|
||||
AC_PROG_CC_C99
|
||||
fi
|
||||
|
||||
if test x"$GCC" = x"yes" ; then
|
||||
AC_MSG_CHECKING([for version of gcc])
|
||||
GCC_VERSION=`$CC -dumpversion`
|
||||
AC_MSG_RESULT(${GCC_VERSION})
|
||||
fi
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_C_BIGENDIAN
|
||||
AC_C_INLINE
|
||||
LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_WARN([c99 structure initializer are not supported])])
|
||||
|
||||
AC_PROG_INSTALL
|
||||
|
||||
AC_ISC_POSIX
|
||||
AC_EXTENSION_FLAG(_XOPEN_SOURCE_EXTENDED)
|
||||
AC_EXTENSION_FLAG(_OSF_SOURCE)
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
dnl Add #include for broken IRIX header files
|
||||
case "$host_os" in
|
||||
*irix6*) AC_ADD_INCLUDE(<standards.h>)
|
||||
;;
|
||||
*hpux*)
|
||||
# mmap on HPUX is completely broken...
|
||||
AC_DEFINE(MMAP_BLACKLIST, 1, [Whether MMAP is broken])
|
||||
if test "`uname -r`" = "B.11.11"; then
|
||||
AC_MSG_WARN([Enabling HPUX 11.11 header bug workaround])
|
||||
CFLAGS="$CFLAGS -D_LARGEFILE64_SUPPORT -D__LP64__ -DO_LARGEFILE=04000"
|
||||
fi
|
||||
if test "`uname -r`" = "B.11.23"; then
|
||||
AC_MSG_WARN([Enabling HPUX 11.23 machine/sys/getppdp.h bug workaround])
|
||||
CFLAGS="$CFLAGS -D_MACHINE_SYS_GETPPDP_INCLUDED"
|
||||
fi
|
||||
;;
|
||||
*aix*)
|
||||
AC_DEFINE(BROKEN_STRNDUP, 1, [Whether strndup is broken])
|
||||
AC_DEFINE(BROKEN_STRNLEN, 1, [Whether strnlen is broken])
|
||||
if test "${GCC}" != "yes"; then
|
||||
## for funky AIX compiler using strncpy()
|
||||
CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
|
||||
fi
|
||||
;;
|
||||
#
|
||||
# VOS may need to have POSIX support and System V compatibility enabled.
|
||||
#
|
||||
*vos*)
|
||||
case "$CFLAGS" in
|
||||
*-D_POSIX_C_SOURCE*);;
|
||||
*)
|
||||
CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L"
|
||||
AC_DEFINE(_POSIX_C_SOURCE, 200112L, [Whether to enable POSIX support])
|
||||
;;
|
||||
esac
|
||||
case "$CFLAGS" in
|
||||
*-D_SYSV*|*-D_SVID_SOURCE*);;
|
||||
*)
|
||||
CFLAGS="$CFLAGS -D_SYSV"
|
||||
AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility])
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
AC_CHECK_HEADERS([standards.h])
|
||||
|
||||
# Solaris needs HAVE_LONG_LONG defined
|
||||
AC_CHECK_TYPES(long long)
|
||||
|
||||
AC_CHECK_TYPE(uint_t, unsigned int)
|
||||
AC_CHECK_TYPE(int8_t, char)
|
||||
AC_CHECK_TYPE(uint8_t, unsigned char)
|
||||
AC_CHECK_TYPE(int16_t, short)
|
||||
AC_CHECK_TYPE(uint16_t, unsigned short)
|
||||
AC_CHECK_TYPE(int32_t, long)
|
||||
AC_CHECK_TYPE(uint32_t, unsigned long)
|
||||
AC_CHECK_TYPE(int64_t, long long)
|
||||
AC_CHECK_TYPE(uint64_t, unsigned long long)
|
||||
|
||||
AC_CHECK_TYPE(size_t, unsigned int)
|
||||
AC_CHECK_TYPE(ssize_t, int)
|
||||
|
||||
AC_CHECK_SIZEOF(int)
|
||||
AC_CHECK_SIZEOF(char)
|
||||
AC_CHECK_SIZEOF(short)
|
||||
AC_CHECK_SIZEOF(long)
|
||||
AC_CHECK_SIZEOF(long long)
|
||||
|
||||
AC_CHECK_SIZEOF(off_t)
|
||||
AC_CHECK_SIZEOF(size_t)
|
||||
AC_CHECK_SIZEOF(ssize_t)
|
||||
|
||||
AC_CHECK_TYPE(intptr_t, unsigned long long)
|
||||
AC_CHECK_TYPE(ptrdiff_t, unsigned long long)
|
||||
|
||||
if test x"$ac_cv_type_long_long" != x"yes";then
|
||||
AC_MSG_ERROR([LIBREPLACE needs type 'long long'])
|
||||
fi
|
||||
if test $ac_cv_sizeof_long_long -lt 8;then
|
||||
AC_MSG_ERROR([LIBREPLACE needs sizeof(long long) >= 8])
|
||||
fi
|
||||
|
||||
############################################
|
||||
# check if the compiler can do immediate structures
|
||||
AC_SUBST(libreplace_cv_immediate_structures)
|
||||
AC_CACHE_CHECK([for immediate structures],libreplace_cv_immediate_structures,[
|
||||
AC_TRY_COMPILE([
|
||||
#include <stdio.h>
|
||||
],[
|
||||
typedef struct {unsigned x;} FOOBAR;
|
||||
#define X_FOOBAR(x) ((FOOBAR) { x })
|
||||
#define FOO_ONE X_FOOBAR(1)
|
||||
FOOBAR f = FOO_ONE;
|
||||
static const struct {
|
||||
FOOBAR y;
|
||||
} f2[] = {
|
||||
{FOO_ONE}
|
||||
};
|
||||
],
|
||||
libreplace_cv_immediate_structures=yes,
|
||||
libreplace_cv_immediate_structures=no,
|
||||
libreplace_cv_immediate_structures=cross)
|
||||
])
|
||||
if test x"$libreplace_cv_immediate_structures" = x"yes"; then
|
||||
AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
|
||||
fi
|
||||
|
||||
AC__LIBREPLACE_ONLY_CC_CHECKS_END
|
||||
]) dnl end AC_LIBREPLACE_CC_CHECKS
|
308
ctdb/lib/replace/libreplace_macros.m4
Normal file
308
ctdb/lib/replace/libreplace_macros.m4
Normal file
@ -0,0 +1,308 @@
|
||||
#
|
||||
# This is a collection of useful autoconf macros
|
||||
#
|
||||
|
||||
############################################
|
||||
# Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags
|
||||
# Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action)
|
||||
# changes CFLAGS to add -AC99 or -c99 if needed
|
||||
AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
|
||||
[
|
||||
saved_CFLAGS="$CFLAGS";
|
||||
c99_init=no
|
||||
if test x"$c99_init" = x"no"; then
|
||||
AC_MSG_CHECKING(for C99 designated initializers)
|
||||
CFLAGS="$saved_CFLAGS";
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[ struct foo {int x;char y;};
|
||||
struct foo bar = { .y = 'X', .x = 1 };
|
||||
],
|
||||
[AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
||||
fi
|
||||
if test x"$c99_init" = x"no"; then
|
||||
AC_MSG_CHECKING(for C99 designated initializers with -AC99)
|
||||
CFLAGS="$saved_CFLAGS -AC99";
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[ struct foo {int x;char y;};
|
||||
struct foo bar = { .y = 'X', .x = 1 };
|
||||
],
|
||||
[AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
||||
fi
|
||||
if test x"$c99_init" = x"no"; then
|
||||
AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=extc99)
|
||||
CFLAGS="$saved_CFLAGS -qlanglvl=extc99";
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[ struct foo {int x;char y;};
|
||||
struct foo bar = { .y = 'X', .x = 1 };
|
||||
],
|
||||
[AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
||||
fi
|
||||
if test x"$c99_init" = x"no"; then
|
||||
AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=stdc99)
|
||||
CFLAGS="$saved_CFLAGS -qlanglvl=stdc99";
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[ struct foo {int x;char y;};
|
||||
struct foo bar = { .y = 'X', .x = 1 };
|
||||
],
|
||||
[AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
||||
fi
|
||||
if test x"$c99_init" = x"no"; then
|
||||
AC_MSG_CHECKING(for C99 designated initializers with -c99)
|
||||
CFLAGS="$saved_CFLAGS -c99"
|
||||
AC_TRY_COMPILE([#include <stdio.h>],
|
||||
[ struct foo {int x;char y;};
|
||||
struct foo bar = { .y = 'X', .x = 1 };
|
||||
],
|
||||
[AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
||||
fi
|
||||
|
||||
if test "`uname`" = "HP-UX"; then
|
||||
if test "$ac_cv_c_compiler_gnu" = no; then
|
||||
# special override for broken HP-UX compiler - I can't find a way to test
|
||||
# this properly (its a compiler bug)
|
||||
CFLAGS="$CFLAGS -AC99";
|
||||
c99_init=yes;
|
||||
fi
|
||||
fi
|
||||
|
||||
if test x"$c99_init" = x"yes"; then
|
||||
saved_CFLAGS=""
|
||||
$1
|
||||
else
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
saved_CFLAGS=""
|
||||
$2
|
||||
fi
|
||||
])
|
||||
|
||||
dnl AC_PROG_CC_FLAG(flag)
|
||||
AC_DEFUN(AC_PROG_CC_FLAG,
|
||||
[AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1,
|
||||
[echo 'void f(){}' > conftest.c
|
||||
if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then
|
||||
ac_cv_prog_cc_$1=yes
|
||||
else
|
||||
ac_cv_prog_cc_$1=no
|
||||
fi
|
||||
rm -f conftest*
|
||||
])])
|
||||
|
||||
AC_DEFUN([AC_EXTENSION_FLAG],
|
||||
[
|
||||
cat >>confdefs.h <<\EOF
|
||||
#ifndef $1
|
||||
# define $1 1
|
||||
#endif
|
||||
EOF
|
||||
AH_VERBATIM([$1], [#ifndef $1
|
||||
# define $1 1
|
||||
#endif])
|
||||
])
|
||||
|
||||
|
||||
dnl see if a declaration exists for a function or variable
|
||||
dnl defines HAVE_function_DECL if it exists
|
||||
dnl AC_HAVE_DECL(var, includes)
|
||||
AC_DEFUN(AC_HAVE_DECL,
|
||||
[
|
||||
AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
|
||||
AC_TRY_COMPILE([$2],[int i = (int)$1],
|
||||
ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
|
||||
if test x"$ac_cv_have_$1_decl" = x"yes"; then
|
||||
AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
|
||||
fi
|
||||
])
|
||||
|
||||
|
||||
# AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
|
||||
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
|
||||
# [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
|
||||
# ------------------------------------------------------
|
||||
#
|
||||
# Use a cache variable name containing both the library and function name,
|
||||
# because the test really is for library $1 defining function $3, not
|
||||
# just for library $1. Separate tests with the same $1 and different $3s
|
||||
# may have different results.
|
||||
#
|
||||
# Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
|
||||
# is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
|
||||
# ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence
|
||||
# the AS_LITERAL_IF indirection.
|
||||
#
|
||||
# FIXME: This macro is extremely suspicious. It DEFINEs unconditionally,
|
||||
# whatever the FUNCTION, in addition to not being a *S macro. Note
|
||||
# that the cache does depend upon the function we are looking for.
|
||||
#
|
||||
# It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
|
||||
# `ac_save_LIBS': there are many macros which don't want to see `LIBS'
|
||||
# changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
|
||||
# And ``ac_save_LIBS' is too tempting a name, so let's leave them some
|
||||
# freedom.
|
||||
AC_DEFUN([AC_CHECK_LIB_EXT],
|
||||
[
|
||||
AH_CHECK_LIB_EXT([$1])
|
||||
ac_check_lib_ext_save_LIBS=$LIBS
|
||||
LIBS="-l$1 $$2 $7 $LIBS"
|
||||
AS_LITERAL_IF([$1],
|
||||
[AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
|
||||
[AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
|
||||
|
||||
m4_ifval([$3],
|
||||
[
|
||||
AH_CHECK_FUNC_EXT([$3])
|
||||
AS_LITERAL_IF([$1],
|
||||
[AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
|
||||
[AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
|
||||
AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
|
||||
[AC_TRY_LINK_FUNC($3,
|
||||
[AS_VAR_SET(ac_Lib_func, yes);
|
||||
AS_VAR_SET(ac_Lib_ext, yes)],
|
||||
[AS_VAR_SET(ac_Lib_func, no);
|
||||
AS_VAR_SET(ac_Lib_ext, no)])
|
||||
])
|
||||
AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
|
||||
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
|
||||
AS_VAR_POPDEF([ac_Lib_func])dnl
|
||||
],[
|
||||
AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
|
||||
[AC_TRY_LINK_FUNC([main],
|
||||
[AS_VAR_SET(ac_Lib_ext, yes)],
|
||||
[AS_VAR_SET(ac_Lib_ext, no)])
|
||||
])
|
||||
])
|
||||
LIBS=$ac_check_lib_ext_save_LIBS
|
||||
|
||||
AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
|
||||
[m4_default([$4],
|
||||
[AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
|
||||
case "$$2" in
|
||||
*-l$1*)
|
||||
;;
|
||||
*)
|
||||
$2="-l$1 $$2"
|
||||
;;
|
||||
esac])
|
||||
[$6]
|
||||
],
|
||||
[$5])dnl
|
||||
AS_VAR_POPDEF([ac_Lib_ext])dnl
|
||||
])# AC_CHECK_LIB_EXT
|
||||
|
||||
# AH_CHECK_LIB_EXT(LIBNAME)
|
||||
# ---------------------
|
||||
m4_define([AH_CHECK_LIB_EXT],
|
||||
[AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
|
||||
[Define to 1 if you have the `]$1[' library (-l]$1[).])])
|
||||
|
||||
dnl AC_SEARCH_LIBS_EXT(FUNCTION, SEARCH-LIBS, EXT_LIBS,
|
||||
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
|
||||
dnl [OTHER-LIBRARIES])
|
||||
dnl --------------------------------------------------------
|
||||
dnl Search for a library defining FUNC, if it's not already available.
|
||||
AC_DEFUN([AC_SEARCH_LIBS_EXT],
|
||||
[AC_CACHE_CHECK([for library containing $1], [ac_cv_search_ext_$1],
|
||||
[
|
||||
ac_func_search_ext_save_LIBS=$LIBS
|
||||
ac_cv_search_ext_$1=no
|
||||
AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
|
||||
[ac_cv_search_ext_$1="none required"])
|
||||
if test "$ac_cv_search_ext_$1" = no; then
|
||||
for ac_lib in $2; do
|
||||
LIBS="-l$ac_lib $$3 $6 $ac_func_search_save_ext_LIBS"
|
||||
AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
|
||||
[ac_cv_search_ext_$1="-l$ac_lib"
|
||||
break])
|
||||
done
|
||||
fi
|
||||
LIBS=$ac_func_search_ext_save_LIBS])
|
||||
AS_IF([test "$ac_cv_search_ext_$1" != no],
|
||||
[test "$ac_cv_search_ext_$1" = "none required" || $3="$ac_cv_search_ext_$1 $$3"
|
||||
$4],
|
||||
[$5])dnl
|
||||
])
|
||||
|
||||
dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
|
||||
dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
|
||||
AC_DEFUN([AC_CHECK_FUNC_EXT],
|
||||
[
|
||||
AH_CHECK_FUNC_EXT($1)
|
||||
ac_check_func_ext_save_LIBS=$LIBS
|
||||
LIBS="$2 $LIBS"
|
||||
AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
|
||||
AC_CACHE_CHECK([for $1], ac_var,
|
||||
[AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
|
||||
[AS_VAR_SET(ac_var, yes)],
|
||||
[AS_VAR_SET(ac_var, no)])])
|
||||
LIBS=$ac_check_func_ext_save_LIBS
|
||||
AS_IF([test AS_VAR_GET(ac_var) = yes],
|
||||
[AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3],
|
||||
[$4])dnl
|
||||
AS_VAR_POPDEF([ac_var])dnl
|
||||
])# AC_CHECK_FUNC
|
||||
|
||||
# AH_CHECK_FUNC_EXT(FUNCNAME)
|
||||
# ---------------------
|
||||
m4_define([AH_CHECK_FUNC_EXT],
|
||||
[AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
|
||||
[Define to 1 if you have the `]$1[' function.])])
|
||||
|
||||
dnl Define an AC_DEFINE with ifndef guard.
|
||||
dnl AC_N_DEFINE(VARIABLE [, VALUE])
|
||||
define(AC_N_DEFINE,
|
||||
[cat >> confdefs.h <<\EOF
|
||||
[#ifndef] $1
|
||||
[#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
|
||||
[#endif]
|
||||
EOF
|
||||
])
|
||||
|
||||
dnl Add an #include
|
||||
dnl AC_ADD_INCLUDE(VARIABLE)
|
||||
define(AC_ADD_INCLUDE,
|
||||
[cat >> confdefs.h <<\EOF
|
||||
[#include] $1
|
||||
EOF
|
||||
])
|
||||
|
||||
dnl remove an #include
|
||||
dnl AC_REMOVE_INCLUDE(VARIABLE)
|
||||
define(AC_REMOVE_INCLUDE,
|
||||
[
|
||||
grep -v '[#include] $1' confdefs.h >confdefs.h.tmp
|
||||
cat confdefs.h.tmp > confdefs.h
|
||||
rm confdefs.h.tmp
|
||||
])
|
||||
|
||||
dnl remove an #define
|
||||
dnl AC_REMOVE_DEFINE(VARIABLE)
|
||||
define(AC_REMOVE_DEFINE,
|
||||
[
|
||||
grep -v '[#define] $1 ' confdefs.h |grep -v '[#define] $1[$]'>confdefs.h.tmp
|
||||
cat confdefs.h.tmp > confdefs.h
|
||||
rm confdefs.h.tmp
|
||||
])
|
||||
|
||||
dnl AS_HELP_STRING is not available in autoconf 2.57, and AC_HELP_STRING is deprecated
|
||||
dnl in autoconf 2.59, so define AS_HELP_STRING to be AC_HELP_STRING unless it is already
|
||||
dnl defined.
|
||||
m4_ifdef([AS_HELP_STRING], , [m4_define([AS_HELP_STRING], m4_defn([AC_HELP_STRING]))])
|
||||
|
||||
dnl check if the prototype in the header matches the given one
|
||||
dnl AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders])
|
||||
AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
|
||||
[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_INCLUDES_DEFAULT
|
||||
$5
|
||||
$1
|
||||
{
|
||||
$2
|
||||
}
|
||||
],[
|
||||
AS_TR_SH([ac_cv_c_prototype_$1])=yes
|
||||
],[
|
||||
AS_TR_SH([ac_cv_c_prototype_$1])=no
|
||||
])
|
||||
)
|
||||
AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
|
||||
])
|
78
ctdb/lib/replace/repdir.m4
Normal file
78
ctdb/lib/replace/repdir.m4
Normal file
@ -0,0 +1,78 @@
|
||||
AC_CACHE_CHECK([for broken readdir],libreplace_cv_READDIR_NEEDED,[
|
||||
AC_TRY_RUN([
|
||||
#define test_readdir_os2_delete main
|
||||
#include "$libreplacedir/test/os2_delete.c"],
|
||||
[libreplace_cv_READDIR_NEEDED=no],
|
||||
[libreplace_cv_READDIR_NEEDED=yes],
|
||||
[libreplace_cv_READDIR_NEEDED="assuming not"])
|
||||
])
|
||||
|
||||
#
|
||||
# try to replace with getdirentries() if needed
|
||||
#
|
||||
if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
|
||||
AC_CHECK_FUNCS(getdirentries)
|
||||
AC_VERIFY_C_PROTOTYPE([long telldir(const DIR *dir)],
|
||||
[
|
||||
return 0;
|
||||
],[
|
||||
AC_DEFINE(TELLDIR_TAKES_CONST_DIR, 1, [Whether telldir takes a const pointer])
|
||||
],[],[
|
||||
#include <dirent.h>
|
||||
])
|
||||
|
||||
AC_VERIFY_C_PROTOTYPE([int seekdir(DIR *dir, long ofs)],
|
||||
[
|
||||
return 0;
|
||||
],[
|
||||
AC_DEFINE(SEEKDIR_RETURNS_INT, 1, [Whether seekdir returns an int])
|
||||
],[],[
|
||||
#include <dirent.h>
|
||||
])
|
||||
AC_CACHE_CHECK([for replacing readdir using getdirentries()],libreplace_cv_READDIR_GETDIRENTRIES,[
|
||||
AC_TRY_RUN([
|
||||
#define _LIBREPLACE_REPLACE_H
|
||||
#include "$libreplacedir/repdir_getdirentries.c"
|
||||
#define test_readdir_os2_delete main
|
||||
#include "$libreplacedir/test/os2_delete.c"],
|
||||
[libreplace_cv_READDIR_GETDIRENTRIES=yes],
|
||||
[libreplace_cv_READDIR_GETDIRENTRIES=no])
|
||||
])
|
||||
fi
|
||||
if test x"$libreplace_cv_READDIR_GETDIRENTRIES" = x"yes"; then
|
||||
AC_DEFINE(REPLACE_READDIR,1,[replace readdir])
|
||||
AC_DEFINE(REPLACE_READDIR_GETDIRENTRIES,1,[replace readdir using getdirentries()])
|
||||
LIBREPLACEOBJ="${LIBREPLACEOBJ} repdir_getdirentries.o"
|
||||
libreplace_cv_READDIR_NEEDED=no
|
||||
fi
|
||||
|
||||
#
|
||||
# try to replace with getdents() if needed
|
||||
#
|
||||
if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
|
||||
AC_CHECK_FUNCS(getdents)
|
||||
AC_CACHE_CHECK([for replacing readdir using getdents()],libreplace_cv_READDIR_GETDENTS,[
|
||||
AC_TRY_RUN([
|
||||
#define _LIBREPLACE_REPLACE_H
|
||||
#error _donot_use_getdents_replacement_anymore
|
||||
#include "$libreplacedir/repdir_getdents.c"
|
||||
#define test_readdir_os2_delete main
|
||||
#include "$libreplacedir/test/os2_delete.c"],
|
||||
[libreplace_cv_READDIR_GETDENTS=yes],
|
||||
[libreplace_cv_READDIR_GETDENTS=no])
|
||||
])
|
||||
fi
|
||||
if test x"$libreplace_cv_READDIR_GETDENTS" = x"yes"; then
|
||||
AC_DEFINE(REPLACE_READDIR,1,[replace readdir])
|
||||
AC_DEFINE(REPLACE_READDIR_GETDENTS,1,[replace readdir using getdents()])
|
||||
LIBREPLACEOBJ="${LIBREPLACEOBJ} repdir_getdents.o"
|
||||
libreplace_cv_READDIR_NEEDED=no
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([a usable readdir()])
|
||||
if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_WARN([the provided readdir() is broken])
|
||||
else
|
||||
AC_MSG_RESULT(yes)
|
||||
fi
|
167
ctdb/lib/replace/repdir_getdents.c
Normal file
167
ctdb/lib/replace/repdir_getdents.c
Normal file
@ -0,0 +1,167 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
** NOTE! The following LGPL license applies to the replace
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/*
|
||||
a replacement for opendir/readdir/telldir/seekdir/closedir for BSD systems
|
||||
|
||||
This is needed because the existing directory handling in FreeBSD
|
||||
and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink()
|
||||
on files in a directory where telldir() has been used. On a block
|
||||
boundary it will occasionally miss a file when seekdir() is used to
|
||||
return to a position previously recorded with telldir().
|
||||
|
||||
This also fixes a severe performance and memory usage problem with
|
||||
telldir() on BSD systems. Each call to telldir() in BSD adds an
|
||||
entry to a linked list, and those entries are cleaned up on
|
||||
closedir(). This means with a large directory closedir() can take an
|
||||
arbitrary amount of time, causing network timeouts as millions of
|
||||
telldir() entries are freed
|
||||
|
||||
Note! This replacement code is not portable. It relies on getdents()
|
||||
always leaving the file descriptor at a seek offset that is a
|
||||
multiple of DIR_BUF_SIZE. If the code detects that this doesn't
|
||||
happen then it will abort(). It also does not handle directories
|
||||
with offsets larger than can be stored in a long,
|
||||
|
||||
This code is available under other free software licenses as
|
||||
well. Contact the author.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define DIR_BUF_BITS 9
|
||||
#define DIR_BUF_SIZE (1<<DIR_BUF_BITS)
|
||||
|
||||
struct dir_buf {
|
||||
int fd;
|
||||
int nbytes, ofs;
|
||||
off_t seekpos;
|
||||
char buf[DIR_BUF_SIZE];
|
||||
};
|
||||
|
||||
DIR *opendir(const char *dname)
|
||||
{
|
||||
struct dir_buf *d;
|
||||
struct stat sb;
|
||||
d = malloc(sizeof(*d));
|
||||
if (d == NULL) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
d->fd = open(dname, O_RDONLY);
|
||||
if (d->fd == -1) {
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (fstat(d->fd, &sb) < 0) {
|
||||
close(d->fd);
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
close(d->fd);
|
||||
free(d);
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
d->ofs = 0;
|
||||
d->seekpos = 0;
|
||||
d->nbytes = 0;
|
||||
return (DIR *)d;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
struct dirent *de;
|
||||
|
||||
if (d->ofs >= d->nbytes) {
|
||||
d->seekpos = lseek(d->fd, 0, SEEK_CUR);
|
||||
d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
|
||||
d->ofs = 0;
|
||||
}
|
||||
if (d->ofs >= d->nbytes) {
|
||||
return NULL;
|
||||
}
|
||||
de = (struct dirent *)&d->buf[d->ofs];
|
||||
d->ofs += de->d_reclen;
|
||||
return de;
|
||||
}
|
||||
|
||||
long telldir(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
if (d->ofs >= d->nbytes) {
|
||||
d->seekpos = lseek(d->fd, 0, SEEK_CUR);
|
||||
d->ofs = 0;
|
||||
d->nbytes = 0;
|
||||
}
|
||||
/* this relies on seekpos always being a multiple of
|
||||
DIR_BUF_SIZE. Is that always true on BSD systems? */
|
||||
if (d->seekpos & (DIR_BUF_SIZE-1)) {
|
||||
abort();
|
||||
}
|
||||
return d->seekpos + d->ofs;
|
||||
}
|
||||
|
||||
void seekdir(DIR *dir, long ofs)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
|
||||
d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
|
||||
d->ofs = 0;
|
||||
while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
|
||||
if (readdir(dir) == NULL) break;
|
||||
}
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dir)
|
||||
{
|
||||
seekdir(dir, 0);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
int r = close(d->fd);
|
||||
if (r != 0) {
|
||||
return r;
|
||||
}
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef dirfd
|
||||
/* darn, this is a macro on some systems. */
|
||||
int dirfd(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
return d->fd;
|
||||
}
|
||||
#endif
|
184
ctdb/lib/replace/repdir_getdirentries.c
Normal file
184
ctdb/lib/replace/repdir_getdirentries.c
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
|
||||
** NOTE! The following LGPL license applies to the replace
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/*
|
||||
a replacement for opendir/readdir/telldir/seekdir/closedir for BSD
|
||||
systems using getdirentries
|
||||
|
||||
This is needed because the existing directory handling in FreeBSD
|
||||
and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink()
|
||||
on files in a directory where telldir() has been used. On a block
|
||||
boundary it will occasionally miss a file when seekdir() is used to
|
||||
return to a position previously recorded with telldir().
|
||||
|
||||
This also fixes a severe performance and memory usage problem with
|
||||
telldir() on BSD systems. Each call to telldir() in BSD adds an
|
||||
entry to a linked list, and those entries are cleaned up on
|
||||
closedir(). This means with a large directory closedir() can take an
|
||||
arbitrary amount of time, causing network timeouts as millions of
|
||||
telldir() entries are freed
|
||||
|
||||
Note! This replacement code is not portable. It relies on
|
||||
getdirentries() always leaving the file descriptor at a seek offset
|
||||
that is a multiple of DIR_BUF_SIZE. If the code detects that this
|
||||
doesn't happen then it will abort(). It also does not handle
|
||||
directories with offsets larger than can be stored in a long,
|
||||
|
||||
This code is available under other free software licenses as
|
||||
well. Contact the author.
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define DIR_BUF_BITS 9
|
||||
#define DIR_BUF_SIZE (1<<DIR_BUF_BITS)
|
||||
|
||||
struct dir_buf {
|
||||
int fd;
|
||||
int nbytes, ofs;
|
||||
off_t seekpos;
|
||||
char buf[DIR_BUF_SIZE];
|
||||
};
|
||||
|
||||
DIR *opendir(const char *dname)
|
||||
{
|
||||
struct dir_buf *d;
|
||||
struct stat sb;
|
||||
d = malloc(sizeof(*d));
|
||||
if (d == NULL) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
d->fd = open(dname, O_RDONLY);
|
||||
if (d->fd == -1) {
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (fstat(d->fd, &sb) < 0) {
|
||||
close(d->fd);
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
close(d->fd);
|
||||
free(d);
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
d->ofs = 0;
|
||||
d->seekpos = 0;
|
||||
d->nbytes = 0;
|
||||
return (DIR *)d;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
struct dirent *de;
|
||||
|
||||
if (d->ofs >= d->nbytes) {
|
||||
long pos;
|
||||
d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos);
|
||||
d->seekpos = pos;
|
||||
d->ofs = 0;
|
||||
}
|
||||
if (d->ofs >= d->nbytes) {
|
||||
return NULL;
|
||||
}
|
||||
de = (struct dirent *)&d->buf[d->ofs];
|
||||
d->ofs += de->d_reclen;
|
||||
return de;
|
||||
}
|
||||
|
||||
#ifdef TELLDIR_TAKES_CONST_DIR
|
||||
long telldir(const DIR *dir)
|
||||
#else
|
||||
long telldir(DIR *dir)
|
||||
#endif
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
if (d->ofs >= d->nbytes) {
|
||||
d->seekpos = lseek(d->fd, 0, SEEK_CUR);
|
||||
d->ofs = 0;
|
||||
d->nbytes = 0;
|
||||
}
|
||||
/* this relies on seekpos always being a multiple of
|
||||
DIR_BUF_SIZE. Is that always true on BSD systems? */
|
||||
if (d->seekpos & (DIR_BUF_SIZE-1)) {
|
||||
abort();
|
||||
}
|
||||
return d->seekpos + d->ofs;
|
||||
}
|
||||
|
||||
#ifdef SEEKDIR_RETURNS_INT
|
||||
int seekdir(DIR *dir, long ofs)
|
||||
#else
|
||||
void seekdir(DIR *dir, long ofs)
|
||||
#endif
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
long pos;
|
||||
d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
|
||||
d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos);
|
||||
d->ofs = 0;
|
||||
while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
|
||||
if (readdir(dir) == NULL) break;
|
||||
}
|
||||
#ifdef SEEKDIR_RETURNS_INT
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dir)
|
||||
{
|
||||
seekdir(dir, 0);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
int r = close(d->fd);
|
||||
if (r != 0) {
|
||||
return r;
|
||||
}
|
||||
free(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef dirfd
|
||||
/* darn, this is a macro on some systems. */
|
||||
int dirfd(DIR *dir)
|
||||
{
|
||||
struct dir_buf *d = (struct dir_buf *)dir;
|
||||
return d->fd;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
613
ctdb/lib/replace/replace.c
Normal file
613
ctdb/lib/replace/replace.c
Normal file
@ -0,0 +1,613 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
replacement routines for broken systems
|
||||
Copyright (C) Andrew Tridgell 1992-1998
|
||||
|
||||
** NOTE! The following LGPL license applies to the replace
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
|
||||
#include "system/filesys.h"
|
||||
#include "system/time.h"
|
||||
#include "system/passwd.h"
|
||||
#include "system/syslog.h"
|
||||
#include "system/network.h"
|
||||
#include "system/locale.h"
|
||||
#include "system/wait.h"
|
||||
|
||||
void replace_dummy(void);
|
||||
void replace_dummy(void) {}
|
||||
|
||||
#ifndef HAVE_FTRUNCATE
|
||||
/*******************************************************************
|
||||
ftruncate for operating systems that don't have it
|
||||
********************************************************************/
|
||||
int rep_ftruncate(int f, off_t l)
|
||||
{
|
||||
#ifdef HAVE_CHSIZE
|
||||
return chsize(f,l);
|
||||
#elif defined(F_FREESP)
|
||||
struct flock fl;
|
||||
|
||||
fl.l_whence = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_start = l;
|
||||
fl.l_type = F_WRLCK;
|
||||
return fcntl(f, F_FREESP, &fl);
|
||||
#else
|
||||
#error "you must have a ftruncate function"
|
||||
#endif
|
||||
}
|
||||
#endif /* HAVE_FTRUNCATE */
|
||||
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
/* like strncpy but does not 0 fill the buffer and always null
|
||||
terminates. bufsize is the size of the destination buffer */
|
||||
size_t rep_strlcpy(char *d, const char *s, size_t bufsize)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
size_t ret = len;
|
||||
if (bufsize <= 0) return 0;
|
||||
if (len >= bufsize) len = bufsize-1;
|
||||
memcpy(d, s, len);
|
||||
d[len] = 0;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/* like strncat but does not 0 fill the buffer and always null
|
||||
terminates. bufsize is the length of the buffer, which should
|
||||
be one more than the maximum resulting string length */
|
||||
size_t rep_strlcat(char *d, const char *s, size_t bufsize)
|
||||
{
|
||||
size_t len1 = strlen(d);
|
||||
size_t len2 = strlen(s);
|
||||
size_t ret = len1 + len2;
|
||||
|
||||
if (len1+len2 >= bufsize) {
|
||||
len2 = bufsize - (len1+1);
|
||||
}
|
||||
if (len2 > 0) {
|
||||
memcpy(d+len1, s, len2);
|
||||
d[len1+len2] = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKTIME
|
||||
/*******************************************************************
|
||||
a mktime() replacement for those who don't have it - contributed by
|
||||
C.A. Lademann <cal@zls.com>
|
||||
Corrections by richard.kettlewell@kewill.com
|
||||
********************************************************************/
|
||||
|
||||
#define MINUTE 60
|
||||
#define HOUR 60*MINUTE
|
||||
#define DAY 24*HOUR
|
||||
#define YEAR 365*DAY
|
||||
time_t rep_mktime(struct tm *t)
|
||||
{
|
||||
struct tm *u;
|
||||
time_t epoch = 0;
|
||||
int n;
|
||||
int mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
y, m, i;
|
||||
|
||||
if(t->tm_year < 70)
|
||||
return((time_t)-1);
|
||||
|
||||
n = t->tm_year + 1900 - 1;
|
||||
epoch = (t->tm_year - 70) * YEAR +
|
||||
((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY;
|
||||
|
||||
y = t->tm_year + 1900;
|
||||
m = 0;
|
||||
|
||||
for(i = 0; i < t->tm_mon; i++) {
|
||||
epoch += mon [m] * DAY;
|
||||
if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
|
||||
epoch += DAY;
|
||||
|
||||
if(++m > 11) {
|
||||
m = 0;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
epoch += (t->tm_mday - 1) * DAY;
|
||||
epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec;
|
||||
|
||||
if((u = localtime(&epoch)) != NULL) {
|
||||
t->tm_sec = u->tm_sec;
|
||||
t->tm_min = u->tm_min;
|
||||
t->tm_hour = u->tm_hour;
|
||||
t->tm_mday = u->tm_mday;
|
||||
t->tm_mon = u->tm_mon;
|
||||
t->tm_year = u->tm_year;
|
||||
t->tm_wday = u->tm_wday;
|
||||
t->tm_yday = u->tm_yday;
|
||||
t->tm_isdst = u->tm_isdst;
|
||||
}
|
||||
|
||||
return(epoch);
|
||||
}
|
||||
#endif /* !HAVE_MKTIME */
|
||||
|
||||
|
||||
#ifndef HAVE_INNETGR
|
||||
#if defined(HAVE_SETNETGRENT) && defined(HAVE_GETNETGRENT) && defined(HAVE_ENDNETGRENT)
|
||||
/*
|
||||
* Search for a match in a netgroup. This replaces it on broken systems.
|
||||
*/
|
||||
int rep_innetgr(const char *group, const char *host, const char *user,
|
||||
const char *dom)
|
||||
{
|
||||
char *hst, *usr, *dm;
|
||||
|
||||
setnetgrent(group);
|
||||
while (getnetgrent(&hst, &usr, &dm)) {
|
||||
if (((host == 0) || (hst == 0) || !strcmp(host, hst)) &&
|
||||
((user == 0) || (usr == 0) || !strcmp(user, usr)) &&
|
||||
((dom == 0) || (dm == 0) || !strcmp(dom, dm))) {
|
||||
endnetgrent();
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
endnetgrent();
|
||||
return (0);
|
||||
}
|
||||
#endif /* HAVE_SETNETGRENT HAVE_GETNETGRENT HAVE_ENDNETGRENT */
|
||||
#endif /* HAVE_INNETGR */
|
||||
|
||||
|
||||
|
||||
#ifndef HAVE_INITGROUPS
|
||||
/****************************************************************************
|
||||
some systems don't have an initgroups call
|
||||
****************************************************************************/
|
||||
int rep_initgroups(char *name, gid_t id)
|
||||
{
|
||||
#ifndef HAVE_SETGROUPS
|
||||
/* yikes! no SETGROUPS or INITGROUPS? how can this work? */
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#else /* HAVE_SETGROUPS */
|
||||
|
||||
#include <grp.h>
|
||||
|
||||
gid_t *grouplst = NULL;
|
||||
int max_gr = 32;
|
||||
int ret;
|
||||
int i,j;
|
||||
struct group *g;
|
||||
char *gr;
|
||||
|
||||
if((grouplst = malloc(sizeof(gid_t) * max_gr)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
grouplst[0] = id;
|
||||
i = 1;
|
||||
while (i < max_gr && ((g = (struct group *)getgrent()) != (struct group *)NULL)) {
|
||||
if (g->gr_gid == id)
|
||||
continue;
|
||||
j = 0;
|
||||
gr = g->gr_mem[0];
|
||||
while (gr && (*gr != (char)NULL)) {
|
||||
if (strcmp(name,gr) == 0) {
|
||||
grouplst[i] = g->gr_gid;
|
||||
i++;
|
||||
gr = (char *)NULL;
|
||||
break;
|
||||
}
|
||||
gr = g->gr_mem[++j];
|
||||
}
|
||||
}
|
||||
endgrent();
|
||||
ret = setgroups(i, grouplst);
|
||||
free(grouplst);
|
||||
return ret;
|
||||
#endif /* HAVE_SETGROUPS */
|
||||
}
|
||||
#endif /* HAVE_INITGROUPS */
|
||||
|
||||
|
||||
#if (defined(SecureWare) && defined(SCO))
|
||||
/* This is needed due to needing the nap() function but we don't want
|
||||
to include the Xenix libraries since that will break other things...
|
||||
BTW: system call # 0x0c28 is the same as calling nap() */
|
||||
long nap(long milliseconds) {
|
||||
return syscall(0x0c28, milliseconds);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_MEMMOVE
|
||||
/*******************************************************************
|
||||
safely copies memory, ensuring no overlap problems.
|
||||
this is only used if the machine does not have it's own memmove().
|
||||
this is not the fastest algorithm in town, but it will do for our
|
||||
needs.
|
||||
********************************************************************/
|
||||
void *rep_memmove(void *dest,const void *src,int size)
|
||||
{
|
||||
unsigned long d,s;
|
||||
int i;
|
||||
if (dest==src || !size) return(dest);
|
||||
|
||||
d = (unsigned long)dest;
|
||||
s = (unsigned long)src;
|
||||
|
||||
if ((d >= (s+size)) || (s >= (d+size))) {
|
||||
/* no overlap */
|
||||
memcpy(dest,src,size);
|
||||
return(dest);
|
||||
}
|
||||
|
||||
if (d < s) {
|
||||
/* we can forward copy */
|
||||
if (s-d >= sizeof(int) &&
|
||||
!(s%sizeof(int)) &&
|
||||
!(d%sizeof(int)) &&
|
||||
!(size%sizeof(int))) {
|
||||
/* do it all as words */
|
||||
int *idest = (int *)dest;
|
||||
int *isrc = (int *)src;
|
||||
size /= sizeof(int);
|
||||
for (i=0;i<size;i++) idest[i] = isrc[i];
|
||||
} else {
|
||||
/* simplest */
|
||||
char *cdest = (char *)dest;
|
||||
char *csrc = (char *)src;
|
||||
for (i=0;i<size;i++) cdest[i] = csrc[i];
|
||||
}
|
||||
} else {
|
||||
/* must backward copy */
|
||||
if (d-s >= sizeof(int) &&
|
||||
!(s%sizeof(int)) &&
|
||||
!(d%sizeof(int)) &&
|
||||
!(size%sizeof(int))) {
|
||||
/* do it all as words */
|
||||
int *idest = (int *)dest;
|
||||
int *isrc = (int *)src;
|
||||
size /= sizeof(int);
|
||||
for (i=size-1;i>=0;i--) idest[i] = isrc[i];
|
||||
} else {
|
||||
/* simplest */
|
||||
char *cdest = (char *)dest;
|
||||
char *csrc = (char *)src;
|
||||
for (i=size-1;i>=0;i--) cdest[i] = csrc[i];
|
||||
}
|
||||
}
|
||||
return(dest);
|
||||
}
|
||||
#endif /* HAVE_MEMMOVE */
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
/****************************************************************************
|
||||
duplicate a string
|
||||
****************************************************************************/
|
||||
char *rep_strdup(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
char *ret;
|
||||
|
||||
if (!s) return(NULL);
|
||||
|
||||
len = strlen(s)+1;
|
||||
ret = (char *)malloc(len);
|
||||
if (!ret) return(NULL);
|
||||
memcpy(ret,s,len);
|
||||
return(ret);
|
||||
}
|
||||
#endif /* HAVE_STRDUP */
|
||||
|
||||
#ifndef WITH_PTHREADS
|
||||
/* REWRITE: not thread safe */
|
||||
#ifdef REPLACE_INET_NTOA
|
||||
char *rep_inet_ntoa(struct in_addr ip)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)&ip.s_addr;
|
||||
static char buf[18];
|
||||
slprintf(buf, 17, "%d.%d.%d.%d",
|
||||
(int)p[0], (int)p[1], (int)p[2], (int)p[3]);
|
||||
return buf;
|
||||
}
|
||||
#endif /* REPLACE_INET_NTOA */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETLINEBUF
|
||||
void rep_setlinebuf(FILE *stream)
|
||||
{
|
||||
setvbuf(stream, (char *)NULL, _IOLBF, 0);
|
||||
}
|
||||
#endif /* HAVE_SETLINEBUF */
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
#ifdef HAVE_SYSLOG
|
||||
void rep_vsyslog (int facility_priority, const char *format, va_list arglist)
|
||||
{
|
||||
char *msg = NULL;
|
||||
vasprintf(&msg, format, arglist);
|
||||
if (!msg)
|
||||
return;
|
||||
syslog(facility_priority, "%s", msg);
|
||||
free(msg);
|
||||
}
|
||||
#endif /* HAVE_SYSLOG */
|
||||
#endif /* HAVE_VSYSLOG */
|
||||
|
||||
#ifndef HAVE_STRNLEN
|
||||
/**
|
||||
Some platforms don't have strnlen
|
||||
**/
|
||||
size_t rep_strnlen(const char *s, size_t max)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; len < max; len++) {
|
||||
if (s[len] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNDUP
|
||||
/**
|
||||
Some platforms don't have strndup.
|
||||
**/
|
||||
char *rep_strndup(const char *s, size_t n)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
n = strnlen(s, n);
|
||||
ret = malloc(n+1);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memcpy(ret, s, n);
|
||||
ret[n] = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WAITPID
|
||||
int rep_waitpid(pid_t pid,int *status,int options)
|
||||
{
|
||||
return wait4(pid, status, options, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETEUID
|
||||
int rep_seteuid(uid_t euid)
|
||||
{
|
||||
#ifdef HAVE_SETRESUID
|
||||
return setresuid(-1, euid, -1);
|
||||
#else
|
||||
# error "You need a seteuid function"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETEGID
|
||||
int rep_setegid(gid_t egid)
|
||||
{
|
||||
#ifdef HAVE_SETRESGID
|
||||
return setresgid(-1, egid, -1);
|
||||
#else
|
||||
# error "You need a setegid function"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************
|
||||
os/2 also doesn't have chroot
|
||||
********************************************************************/
|
||||
#ifndef HAVE_CHROOT
|
||||
int rep_chroot(const char *dname)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************
|
||||
Possibly replace mkstemp if it is broken.
|
||||
*****************************************************************/
|
||||
|
||||
#ifndef HAVE_SECURE_MKSTEMP
|
||||
int rep_mkstemp(char *template)
|
||||
{
|
||||
/* have a reasonable go at emulating it. Hope that
|
||||
the system mktemp() isn't completly hopeless */
|
||||
char *p = mktemp(template);
|
||||
if (!p)
|
||||
return -1;
|
||||
return open(p, O_CREAT|O_EXCL|O_RDWR, 0600);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKDTEMP
|
||||
char *rep_mkdtemp(char *template)
|
||||
{
|
||||
char *dname;
|
||||
|
||||
if ((dname = mktemp(template))) {
|
||||
if (mkdir(dname, 0700) >= 0) {
|
||||
return dname;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PREAD
|
||||
ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
|
||||
{
|
||||
if (lseek(__fd, __offset, SEEK_SET) != __offset) {
|
||||
return -1;
|
||||
}
|
||||
return read(__fd, __buf, __nbytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PWRITE
|
||||
ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
|
||||
{
|
||||
if (lseek(__fd, __offset, SEEK_SET) != __offset) {
|
||||
return -1;
|
||||
}
|
||||
return write(__fd, __buf, __nbytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASESTR
|
||||
char *rep_strcasestr(const char *haystack, const char *needle)
|
||||
{
|
||||
const char *s;
|
||||
size_t nlen = strlen(needle);
|
||||
for (s=haystack;*s;s++) {
|
||||
if (toupper(*needle) == toupper(*s) &&
|
||||
strncasecmp(s, needle, nlen) == 0) {
|
||||
return (char *)((intptr_t)s);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOK_R
|
||||
/* based on GLIBC version, copyright Free Software Foundation */
|
||||
char *rep_strtok_r(char *s, const char *delim, char **save_ptr)
|
||||
{
|
||||
char *token;
|
||||
|
||||
if (s == NULL) s = *save_ptr;
|
||||
|
||||
s += strspn(s, delim);
|
||||
if (*s == '\0') {
|
||||
*save_ptr = s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
token = s;
|
||||
s = strpbrk(token, delim);
|
||||
if (s == NULL) {
|
||||
*save_ptr = token + strlen(token);
|
||||
} else {
|
||||
*s = '\0';
|
||||
*save_ptr = s + 1;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOLL
|
||||
long long int rep_strtoll(const char *str, char **endptr, int base)
|
||||
{
|
||||
#ifdef HAVE_STRTOQ
|
||||
return strtoq(str, endptr, base);
|
||||
#elif defined(HAVE___STRTOLL)
|
||||
return __strtoll(str, endptr, base);
|
||||
#elif SIZEOF_LONG == SIZEOF_LONG_LONG
|
||||
return (long long int) strtol(str, endptr, base);
|
||||
#else
|
||||
# error "You need a strtoll function"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_STRTOULL
|
||||
unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
|
||||
{
|
||||
#ifdef HAVE_STRTOUQ
|
||||
return strtouq(str, endptr, base);
|
||||
#elif defined(HAVE___STRTOULL)
|
||||
return __strtoull(str, endptr, base);
|
||||
#elif SIZEOF_LONG == SIZEOF_LONG_LONG
|
||||
return (unsigned long long int) strtoul(str, endptr, base);
|
||||
#else
|
||||
# error "You need a strtoull function"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETENV
|
||||
int rep_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
char *p;
|
||||
size_t l1, l2;
|
||||
int ret;
|
||||
|
||||
if (!overwrite && getenv(name)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
l1 = strlen(name);
|
||||
l2 = strlen(value);
|
||||
|
||||
p = malloc(l1+l2+2);
|
||||
if (p == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(p, name, l1);
|
||||
p[l1] = '=';
|
||||
memcpy(p+l1+1, value, l2);
|
||||
p[l1+l2+1] = 0;
|
||||
|
||||
ret = putenv(p);
|
||||
if (ret != 0) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SOCKETPAIR
|
||||
int rep_socketpair(int d, int type, int protocol, int sv[2])
|
||||
{
|
||||
if (d != AF_UNIX) {
|
||||
errno = EAFNOSUPPORT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (protocol != 0) {
|
||||
errno = EPROTONOSUPPORT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type != SOCK_STREAM) {
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pipe(sv);
|
||||
}
|
||||
#endif
|
408
ctdb/lib/replace/replace.h
Normal file
408
ctdb/lib/replace/replace.h
Normal file
@ -0,0 +1,408 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
macros to go along with the lib/replace/ portability layer code
|
||||
|
||||
Copyright (C) Andrew Tridgell 2005
|
||||
Copyright (C) Jelmer Vernooij 2006
|
||||
|
||||
** NOTE! The following LGPL license applies to the replace
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LIBREPLACE_REPLACE_H
|
||||
#define _LIBREPLACE_REPLACE_H
|
||||
|
||||
#ifndef NO_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STANDARDS_H
|
||||
#include <standards.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#include "win32_replace.h"
|
||||
#endif
|
||||
|
||||
#ifdef __COMPAR_FN_T
|
||||
#define QSORT_CAST (__compar_fn_t)
|
||||
#endif
|
||||
|
||||
#ifndef QSORT_CAST
|
||||
#define QSORT_CAST (int (*)(const void *, const void *))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
/* force off HAVE_INTTYPES_H so that roken doesn't try to include both,
|
||||
which causes a warning storm on irix */
|
||||
#undef HAVE_INTTYPES_H
|
||||
#elif HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
extern char *sys_errlist[];
|
||||
#define strerror(i) sys_errlist[i]
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ERRNO_DECL
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
#define strdup rep_strdup
|
||||
char *rep_strdup(const char *s);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMMOVE
|
||||
#define memmove rep_memmove
|
||||
void *rep_memmove(void *dest,const void *src,int size);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_MKTIME) || !defined(HAVE_TIMEGM)
|
||||
#include "system/time.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKTIME
|
||||
#define mktime rep_mktime
|
||||
time_t rep_mktime(struct tm *t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_TIMEGM
|
||||
struct tm;
|
||||
#define timegm rep_timegm
|
||||
time_t rep_timegm(struct tm *tm);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
#define strlcpy rep_strlcpy
|
||||
size_t rep_strlcpy(char *d, const char *s, size_t bufsize);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#define strlcat rep_strlcat
|
||||
size_t rep_strlcat(char *d, const char *s, size_t bufsize);
|
||||
#endif
|
||||
|
||||
#if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP))
|
||||
#undef HAVE_STRNDUP
|
||||
#define strndup rep_strndup
|
||||
char *rep_strndup(const char *s, size_t n);
|
||||
#endif
|
||||
|
||||
#if (defined(BROKEN_STRNLEN) || !defined(HAVE_STRNLEN))
|
||||
#undef HAVE_STRNLEN
|
||||
#define strnlen rep_strnlen
|
||||
size_t rep_strnlen(const char *s, size_t n);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETENV
|
||||
#define setenv rep_setenv
|
||||
int rep_setenv(const char *name, const char *value, int overwrite);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETEUID
|
||||
#define seteuid rep_seteuid
|
||||
int rep_seteuid(uid_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETEGID
|
||||
#define setegid rep_setegid
|
||||
int rep_setegid(gid_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETLINEBUF
|
||||
#define setlinebuf rep_setlinebuf
|
||||
void rep_setlinebuf(FILE *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCASESTR
|
||||
#define strcasestr rep_strcasestr
|
||||
char *rep_strcasestr(const char *haystack, const char *needle);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOK_R
|
||||
#define strtok_r rep_strtok_r
|
||||
char *rep_strtok_r(char *s, const char *delim, char **save_ptr);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOLL
|
||||
#define strtoll rep_strtoll
|
||||
long long int rep_strtoll(const char *str, char **endptr, int base);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOULL
|
||||
#define strtoull rep_strtoull
|
||||
unsigned long long int rep_strtoull(const char *str, char **endptr, int base);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FTRUNCATE
|
||||
#define ftruncate rep_ftruncate
|
||||
int rep_ftruncate(int,off_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INITGROUPS
|
||||
#define initgroups rep_initgroups
|
||||
int rep_initgroups(char *name, gid_t id);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
|
||||
#define bzero(a,b) memset((a),'\0',(b))
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLERROR
|
||||
#define dlerror rep_dlerror
|
||||
char *rep_dlerror(void);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLOPEN
|
||||
#define dlopen rep_dlopen
|
||||
void *rep_dlopen(const char *name, int flags);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLSYM
|
||||
#define dlsym rep_dlsym
|
||||
void *rep_dlsym(void *handle, const char *symbol);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DLCLOSE
|
||||
#define dlclose rep_dlclose
|
||||
int rep_dlclose(void *handle);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SOCKETPAIR
|
||||
#define socketpair rep_socketpair
|
||||
int rep_socketpair(int d, int type, int protocol, int sv[2]);
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_ATTRIBUTE
|
||||
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
|
||||
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
|
||||
* the parameter containing the format, and a2 the index of the first
|
||||
* argument. Note that some gcc 2.x versions don't handle this
|
||||
* properly **/
|
||||
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
|
||||
#else
|
||||
#define PRINTF_ATTRIBUTE(a1, a2)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
#define vasprintf rep_vasprintf
|
||||
int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
|
||||
#define snprintf rep_snprintf
|
||||
int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
|
||||
#define vsnprintf rep_vsnprintf
|
||||
int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
#define asprintf rep_asprintf
|
||||
int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
#ifdef HAVE_SYSLOG
|
||||
#define vsyslog rep_vsyslog
|
||||
void rep_vsyslog (int facility_priority, const char *format, va_list arglist) PRINTF_ATTRIBUTE(2,0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* we used to use these fns, but now we have good replacements
|
||||
for snprintf and vsnprintf */
|
||||
#define slprintf snprintf
|
||||
|
||||
|
||||
#ifndef HAVE_VA_COPY
|
||||
#undef va_copy
|
||||
#ifdef HAVE___VA_COPY
|
||||
#define va_copy(dest, src) __va_copy(dest, src)
|
||||
#else
|
||||
#define va_copy(dest, src) (dest) = (src)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VOLATILE
|
||||
#define volatile
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_COMPARISON_FN_T
|
||||
typedef int (*comparison_fn_t)(const void *, const void *);
|
||||
#endif
|
||||
|
||||
/* Load header file for dynamic linking stuff */
|
||||
#ifdef HAVE_DLFCN_H
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#ifndef RTLD_LAZY
|
||||
#define RTLD_LAZY 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SECURE_MKSTEMP
|
||||
#define mkstemp(path) rep_mkstemp(path)
|
||||
int rep_mkstemp(char *temp);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKDTEMP
|
||||
#define mkdtemp rep_mkdtemp
|
||||
char *rep_mkdtemp(char *template);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
/* The extra casts work around common compiler bugs. */
|
||||
#define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
|
||||
It is necessary at least when t == time_t. */
|
||||
#define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \
|
||||
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
|
||||
#define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t)))
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 64
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX 65535
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX (4294967295U)
|
||||
#endif
|
||||
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX ((uint64_t)-1)
|
||||
#endif
|
||||
|
||||
#ifndef CHAR_BIT
|
||||
#define CHAR_BIT 8
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX _TYPE_MAXIMUM(int32_t)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_BOOL)
|
||||
#ifdef HAVE__Bool
|
||||
#define bool _Bool
|
||||
#else
|
||||
typedef int bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* to prevent <rpcsvc/yp_prot.h> from doing a redefine of 'bool'
|
||||
*
|
||||
* IRIX, HPUX, MacOS 10 and Solaris need BOOL_DEFINED
|
||||
* Tru64 needs _BOOL_EXISTS
|
||||
* AIX needs _BOOL,_TRUE,_FALSE
|
||||
*/
|
||||
#ifndef BOOL_DEFINED
|
||||
#define BOOL_DEFINED
|
||||
#endif
|
||||
#ifndef _BOOL_EXISTS
|
||||
#define _BOOL_EXISTS
|
||||
#endif
|
||||
#ifndef _BOOL
|
||||
#define _BOOL
|
||||
#endif
|
||||
|
||||
#ifndef __bool_true_false_are_defined
|
||||
#define __bool_true_false_are_defined
|
||||
#endif
|
||||
|
||||
#ifndef true
|
||||
#define true (1)
|
||||
#endif
|
||||
#ifndef false
|
||||
#define false (0)
|
||||
#endif
|
||||
|
||||
#ifndef _TRUE
|
||||
#define _TRUE true
|
||||
#endif
|
||||
#ifndef _FALSE
|
||||
#define _FALSE false
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FUNCTION_MACRO
|
||||
#ifdef HAVE_func_MACRO
|
||||
#define __FUNCTION__ __func__
|
||||
#else
|
||||
#define __FUNCTION__ ("")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef __STRING
|
||||
#define __STRING(x) #x
|
||||
#endif
|
||||
|
||||
#if MMAP_BLACKLIST
|
||||
#undef HAVE_MMAP
|
||||
#endif
|
||||
|
||||
#endif /* _LIBREPLACE_REPLACE_H */
|
BIN
ctdb/lib/replace/replace.ho
Normal file
BIN
ctdb/lib/replace/replace.ho
Normal file
Binary file not shown.
23
ctdb/lib/replace/samba.m4
Normal file
23
ctdb/lib/replace/samba.m4
Normal file
@ -0,0 +1,23 @@
|
||||
AC_LIBREPLACE_BROKEN_CHECKS
|
||||
|
||||
SMB_EXT_LIB(LIBREPLACE_EXT, [${LIBDL}])
|
||||
SMB_ENABLE(LIBREPLACE_EXT)
|
||||
|
||||
LIBREPLACE_DIR=`echo ${libreplacedir} |sed -e 's/^\.\///g'`
|
||||
|
||||
LIBREPLACE_OBJS=""
|
||||
for obj in ${LIBREPLACEOBJ}; do
|
||||
LIBREPLACE_OBJS="${LIBREPLACE_OBJS} ${LIBREPLACE_DIR}/${obj}"
|
||||
done
|
||||
|
||||
SMB_SUBSYSTEM(LIBREPLACE,
|
||||
[${LIBREPLACE_OBJS}],
|
||||
[LIBREPLACE_EXT],
|
||||
[-Ilib/replace])
|
||||
|
||||
LIBREPLACE_HOSTCC_OBJS=`echo ${LIBREPLACE_OBJS} |sed -e 's/\.o/\.ho/g'`
|
||||
|
||||
SMB_SUBSYSTEM(LIBREPLACE_HOSTCC,
|
||||
[${LIBREPLACE_HOSTCC_OBJS}],
|
||||
[],
|
||||
[-Ilib/replace])
|
1528
ctdb/lib/replace/snprintf.c
Normal file
1528
ctdb/lib/replace/snprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
ctdb/lib/replace/snprintf.ho
Normal file
BIN
ctdb/lib/replace/snprintf.ho
Normal file
Binary file not shown.
4
ctdb/lib/replace/system/README
Normal file
4
ctdb/lib/replace/system/README
Normal file
@ -0,0 +1,4 @@
|
||||
This directory contains wrappers around logical groups of system
|
||||
include files. The idea is to avoid #ifdef blocks in the main code,
|
||||
and instead put all the necessary conditional includes in subsystem
|
||||
specific header files in this directory.
|
29
ctdb/lib/replace/system/aio.h
Normal file
29
ctdb/lib/replace/system/aio.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef _system_aio_h
|
||||
#define _system_aio_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
AIO system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2006
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBAIO_H
|
||||
#include <libaio.h>
|
||||
#endif
|
||||
|
||||
#endif
|
41
ctdb/lib/replace/system/capability.h
Normal file
41
ctdb/lib/replace/system/capability.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef _system_capability_h
|
||||
#define _system_capability_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
capability system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_CAPABILITY_H
|
||||
|
||||
#if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H)
|
||||
#define _I386_STATFS_H
|
||||
#define BROKEN_REDHAT_7_STATFS_WORKAROUND
|
||||
#endif
|
||||
|
||||
#include <sys/capability.h>
|
||||
|
||||
#ifdef BROKEN_REDHAT_7_STATFS_WORKAROUND
|
||||
#undef _I386_STATFS_H
|
||||
#undef BROKEN_REDHAT_7_STATFS_WORKAROUND
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
31
ctdb/lib/replace/system/config.m4
Normal file
31
ctdb/lib/replace/system/config.m4
Normal file
@ -0,0 +1,31 @@
|
||||
# filesys
|
||||
AC_HEADER_DIRENT
|
||||
AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/acl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h )
|
||||
|
||||
# select
|
||||
AC_CHECK_HEADERS(sys/select.h)
|
||||
|
||||
# time
|
||||
AC_CHECK_HEADERS(sys/time.h utime.h)
|
||||
AC_HEADER_TIME
|
||||
|
||||
# wait
|
||||
AC_HEADER_SYS_WAIT
|
||||
|
||||
# capability
|
||||
AC_CHECK_HEADERS(sys/capability.h)
|
||||
|
||||
# passwd
|
||||
AC_CHECK_HEADERS(grp.h sys/id.h compat.h shadow.h sys/priv.h pwd.h sys/security.h)
|
||||
|
||||
# locale
|
||||
AC_CHECK_HEADERS(ctype.h locale.h)
|
||||
|
||||
# glob
|
||||
AC_CHECK_HEADERS(fnmatch.h)
|
||||
|
||||
# shmem
|
||||
AC_CHECK_HEADERS(sys/ipc.h sys/mman.h sys/shm.h )
|
||||
|
||||
# terminal
|
||||
AC_CHECK_HEADERS(termios.h termio.h sys/termio.h )
|
64
ctdb/lib/replace/system/dir.h
Normal file
64
ctdb/lib/replace/system/dir.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef _system_dir_h
|
||||
#define _system_dir_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
directory system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKDIR_MODE
|
||||
#define mkdir(dir, mode) mkdir(dir)
|
||||
#endif
|
||||
|
||||
/* Test whether a file name is the "." or ".." directory entries.
|
||||
* These really should be inline functions.
|
||||
*/
|
||||
#ifndef ISDOT
|
||||
#define ISDOT(path) ( \
|
||||
*((const char *)(path)) == '.' && \
|
||||
*(((const char *)(path)) + 1) == '\0' \
|
||||
)
|
||||
#endif
|
||||
|
||||
#ifndef ISDOTDOT
|
||||
#define ISDOTDOT(path) ( \
|
||||
*((const char *)(path)) == '.' && \
|
||||
*(((const char *)(path)) + 1) == '.' && \
|
||||
*(((const char *)(path)) + 2) == '\0' \
|
||||
)
|
||||
#endif
|
||||
|
||||
#endif
|
170
ctdb/lib/replace/system/filesys.h
Normal file
170
ctdb/lib/replace/system/filesys.h
Normal file
@ -0,0 +1,170 @@
|
||||
#ifndef _system_filesys_h
|
||||
#define _system_filesys_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
filesystem system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_MOUNT_H
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_VFS_H
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_ACL_H
|
||||
#include <sys/acl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_FS_S5PARAM_H
|
||||
#include <sys/fs/s5param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
|
||||
#include <sys/filsys.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STATFS_H
|
||||
# include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DUSTAT_H
|
||||
#include <sys/dustat.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STATVFS_H
|
||||
#include <sys/statvfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#include <sys/file.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_FCNTL_H
|
||||
#include <sys/fcntl.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_MODE_H
|
||||
/* apparently AIX needs this for S_ISLNK */
|
||||
#ifndef S_ISLNK
|
||||
#include <sys/mode.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Veritas File System. Often in addition to native.
|
||||
* Quotas different.
|
||||
*/
|
||||
#if defined(HAVE_SYS_FS_VX_QUOTA_H)
|
||||
#define VXFS_QUOTA
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_ATTRIBUTES_H
|
||||
#include <sys/attributes.h>
|
||||
#endif
|
||||
|
||||
/* mutually exclusive (SuSE 8.2) */
|
||||
#if HAVE_ATTR_XATTR_H
|
||||
#include <attr/xattr.h>
|
||||
#elif HAVE_SYS_XATTR_H
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_RESOURCE_H
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
/* Some POSIX definitions for those without */
|
||||
|
||||
#ifndef S_IFDIR
|
||||
#define S_IFDIR 0x4000
|
||||
#endif
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
|
||||
#endif
|
||||
#ifndef S_IRWXU
|
||||
#define S_IRWXU 00700 /* read, write, execute: owner */
|
||||
#endif
|
||||
#ifndef S_IRUSR
|
||||
#define S_IRUSR 00400 /* read permission: owner */
|
||||
#endif
|
||||
#ifndef S_IWUSR
|
||||
#define S_IWUSR 00200 /* write permission: owner */
|
||||
#endif
|
||||
#ifndef S_IXUSR
|
||||
#define S_IXUSR 00100 /* execute permission: owner */
|
||||
#endif
|
||||
#ifndef S_IRWXG
|
||||
#define S_IRWXG 00070 /* read, write, execute: group */
|
||||
#endif
|
||||
#ifndef S_IRGRP
|
||||
#define S_IRGRP 00040 /* read permission: group */
|
||||
#endif
|
||||
#ifndef S_IWGRP
|
||||
#define S_IWGRP 00020 /* write permission: group */
|
||||
#endif
|
||||
#ifndef S_IXGRP
|
||||
#define S_IXGRP 00010 /* execute permission: group */
|
||||
#endif
|
||||
#ifndef S_IRWXO
|
||||
#define S_IRWXO 00007 /* read, write, execute: other */
|
||||
#endif
|
||||
#ifndef S_IROTH
|
||||
#define S_IROTH 00004 /* read permission: other */
|
||||
#endif
|
||||
#ifndef S_IWOTH
|
||||
#define S_IWOTH 00002 /* write permission: other */
|
||||
#endif
|
||||
#ifndef S_IXOTH
|
||||
#define S_IXOTH 00001 /* execute permission: other */
|
||||
#endif
|
||||
|
||||
#ifndef O_ACCMODE
|
||||
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#define MAXPATHLEN 256
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
#endif
|
33
ctdb/lib/replace/system/glob.h
Normal file
33
ctdb/lib/replace/system/glob.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef _system_glob_h
|
||||
#define _system_glob_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
glob system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_GLOB_H
|
||||
#include <glob.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FNMATCH_H
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
#endif
|
53
ctdb/lib/replace/system/iconv.h
Normal file
53
ctdb/lib/replace/system/iconv.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef _system_iconv_h
|
||||
#define _system_iconv_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
iconv memory system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#if !defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
|
||||
#define HAVE_ICONV
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_GICONV) && defined(HAVE_GICONV_H)
|
||||
#define HAVE_GICONV
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_BICONV) && defined(HAVE_BICONV_H)
|
||||
#define HAVE_BICONV
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NATIVE_ICONV
|
||||
#if defined(HAVE_ICONV)
|
||||
#include <iconv.h>
|
||||
#elif defined(HAVE_GICONV)
|
||||
#include <giconv.h>
|
||||
#elif defined(HAVE_BICONV)
|
||||
#include <biconv.h>
|
||||
#endif
|
||||
#endif /* HAVE_NATIVE_ICONV */
|
||||
|
||||
/* needed for some systems without iconv. Doesn't really matter
|
||||
what error code we use */
|
||||
#ifndef EILSEQ
|
||||
#define EILSEQ EIO
|
||||
#endif
|
||||
|
||||
#endif
|
132
ctdb/lib/replace/system/kerberos.h
Normal file
132
ctdb/lib/replace/system/kerberos.h
Normal file
@ -0,0 +1,132 @@
|
||||
#ifndef _system_kerberos_h
|
||||
#define _system_kerberos_h
|
||||
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
kerberos system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_KRB5
|
||||
/* Whether the krb5_address struct has a addrtype property */
|
||||
/* #undef HAVE_ADDRTYPE_IN_KRB5_ADDRESS */
|
||||
/* Whether the krb5_address struct has a addr_type property */
|
||||
#define HAVE_ADDR_TYPE_IN_KRB5_ADDRESS 1
|
||||
/* Define to 1 if you have the `gsskrb5_extract_authz_data_from_sec_context' */
|
||||
#define HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT 1
|
||||
/* Define to 1 if you have the `gsskrb5_get_initiator_subkey' function. */
|
||||
#define HAVE_GSSKRB5_GET_INITIATOR_SUBKEY 1
|
||||
/* Define to 1 if you have the `gsskrb5_register_acceptor_identity' function. */
|
||||
#define HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY 1
|
||||
/* Define to 1 if you have the `gss_krb5_ccache_name' function. */
|
||||
#define HAVE_GSS_KRB5_CCACHE_NAME 1
|
||||
/* Define to 1 if you have the `krb5_addlog_func' function. */
|
||||
#define HAVE_KRB5_ADDLOG_FUNC 1
|
||||
/* Define to 1 if you have the `krb5_auth_con_setkey' function. */
|
||||
#define HAVE_KRB5_AUTH_CON_SETKEY 1
|
||||
/* Define to 1 if you have the `krb5_auth_con_setuseruserkey' function. */
|
||||
/* #undef HAVE_KRB5_AUTH_CON_SETUSERUSERKEY */
|
||||
/* Define to 1 if you have the `krb5_c_enctype_compare' function. */
|
||||
#define HAVE_KRB5_C_ENCTYPE_COMPARE 1
|
||||
/* Define to 1 if you have the `krb5_c_verify_checksum' function. */
|
||||
#define HAVE_KRB5_C_VERIFY_CHECKSUM 1
|
||||
/* Whether the type krb5_encrypt_block exists */
|
||||
/* #undef HAVE_KRB5_ENCRYPT_BLOCK */
|
||||
/* Define to 1 if you have the `krb5_encrypt_data' function. */
|
||||
/* #undef HAVE_KRB5_ENCRYPT_DATA */
|
||||
/* Define to 1 if you have the `krb5_enctypes_compatible_keys' function. */
|
||||
#define HAVE_KRB5_ENCTYPES_COMPATIBLE_KEYS 1
|
||||
/* Define to 1 if you have the `krb5_free_data_contents' function. */
|
||||
#define HAVE_KRB5_FREE_DATA_CONTENTS 1
|
||||
/* Define to 1 if you have the `krb5_free_error_string' function. */
|
||||
#define HAVE_KRB5_FREE_ERROR_STRING 1
|
||||
/* Define to 1 if you have the `krb5_free_keytab_entry_contents' function. */
|
||||
/* #undef HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS */
|
||||
/* Define to 1 if you have the `krb5_free_ktypes' function. */
|
||||
/* #undef HAVE_KRB5_FREE_KTYPES */
|
||||
/* Define to 1 if you have the `krb5_free_unparsed_name' function. */
|
||||
/* #undef HAVE_KRB5_FREE_UNPARSED_NAME */
|
||||
/* Define to 1 if you have the `krb5_get_default_in_tkt_etypes' function. */
|
||||
#define HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES 1
|
||||
/* Define to 1 if you have the `krb5_get_error_string' function. */
|
||||
#define HAVE_KRB5_GET_ERROR_STRING 1
|
||||
/* Define to 1 if you have the `krb5_get_permitted_enctypes' function. */
|
||||
/* #undef HAVE_KRB5_GET_PERMITTED_ENCTYPES */
|
||||
/* Define to 1 if you have the `krb5_get_pw_salt' function. */
|
||||
#define HAVE_KRB5_GET_PW_SALT 1
|
||||
/* Define to 1 if you have the <krb5.h> header file. */
|
||||
#define HAVE_KRB5_H 1
|
||||
/* Define to 1 if you have the `krb5_initlog' function. */
|
||||
#define HAVE_KRB5_INITLOG 1
|
||||
/* Define to 1 if you have the `krb5_kdc_default_config' function. */
|
||||
#define HAVE_KRB5_KDC_DEFAULT_CONFIG 1
|
||||
/* Whether the krb5_creds struct has a keyblock property */
|
||||
/* #undef HAVE_KRB5_KEYBLOCK_IN_CREDS */
|
||||
/* Whether the krb5_keyblock struct has a keyvalue property */
|
||||
#define HAVE_KRB5_KEYBLOCK_KEYVALUE 1
|
||||
/* Whether krb5_keytab_entry has key member */
|
||||
/* #undef HAVE_KRB5_KEYTAB_ENTRY_KEY */
|
||||
/* Whether krb5_keytab_entry has keyblock member */
|
||||
#define HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK 1
|
||||
/* Define to 1 if you have the `krb5_krbhst_get_addrinfo' function. */
|
||||
#define HAVE_KRB5_KRBHST_GET_ADDRINFO 1
|
||||
/* Define to 1 if you have the `krb5_kt_compare' function. */
|
||||
#define HAVE_KRB5_KT_COMPARE 1
|
||||
/* Define to 1 if you have the `krb5_kt_free_entry' function. */
|
||||
#define HAVE_KRB5_KT_FREE_ENTRY 1
|
||||
/* Whether the type krb5_log_facility exists */
|
||||
#define HAVE_KRB5_LOG_FACILITY 1
|
||||
/* Define to 1 if you have the `krb5_mk_req_extended' function. */
|
||||
#define HAVE_KRB5_MK_REQ_EXTENDED 1
|
||||
/* Define to 1 if you have the `krb5_principal2salt' function. */
|
||||
/* #undef HAVE_KRB5_PRINCIPAL2SALT */
|
||||
/* Define to 1 if you have the `krb5_principal_get_comp_string' function. */
|
||||
#define HAVE_KRB5_PRINCIPAL_GET_COMP_STRING 1
|
||||
/* Whether krb5_princ_component is available */
|
||||
/* #undef HAVE_KRB5_PRINC_COMPONENT */
|
||||
/* Whether the krb5_creds struct has a session property */
|
||||
#define HAVE_KRB5_SESSION_IN_CREDS 1
|
||||
/* Define to 1 if you have the `krb5_set_default_in_tkt_etypes' function. */
|
||||
#define HAVE_KRB5_SET_DEFAULT_IN_TKT_ETYPES 1
|
||||
/* Define to 1 if you have the `krb5_set_default_tgs_ktypes' function. */
|
||||
/* #undef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES */
|
||||
/* Define to 1 if you have the `krb5_set_real_time' function. */
|
||||
#define HAVE_KRB5_SET_REAL_TIME 1
|
||||
/* Define to 1 if you have the `krb5_set_warn_dest' function. */
|
||||
#define HAVE_KRB5_SET_WARN_DEST 1
|
||||
/* Define to 1 if you have the `krb5_string_to_key' function. */
|
||||
#define HAVE_KRB5_STRING_TO_KEY 1
|
||||
/* Define to 1 if you have the `krb5_string_to_key_salt' function. */
|
||||
#define HAVE_KRB5_STRING_TO_KEY_SALT 1
|
||||
/* Define to 1 if you have the `krb5_ticket_get_authorization_data_type' */
|
||||
#define HAVE_KRB5_TICKET_GET_AUTHORIZATION_DATA_TYPE 1
|
||||
/* Whether the krb5_ticket struct has a enc_part2 property */
|
||||
/* #undef HAVE_KRB5_TKT_ENC_PART2 */
|
||||
/* Define to 1 if you have the `krb5_use_enctype' function. */
|
||||
/* #undef HAVE_KRB5_USE_ENCTYPE */
|
||||
/* Define to 1 if you have the `krb5_verify_checksum' function. */
|
||||
#define HAVE_KRB5_VERIFY_CHECKSUM 1
|
||||
/* Whether krb5_princ_realm returns krb5_realm or krb5_data */
|
||||
#define KRB5_PRINC_REALM_RETURNS_REALM 1
|
||||
|
||||
#include "heimdal/lib/krb5/krb5.h"
|
||||
#include "heimdal/lib/com_err/com_err.h"
|
||||
#endif
|
||||
|
||||
#endif
|
34
ctdb/lib/replace/system/locale.h
Normal file
34
ctdb/lib/replace/system/locale.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef _system_locale_h
|
||||
#define _system_locale_h
|
||||
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
locale include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CTYPE_H
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#endif
|
113
ctdb/lib/replace/system/network.h
Normal file
113
ctdb/lib/replace/system/network.h
Normal file
@ -0,0 +1,113 @@
|
||||
#ifndef _system_network_h
|
||||
#define _system_network_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
networking system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNIXSOCKET
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The next three defines are needed to access the IPTOS_* options
|
||||
* on some systems.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_IP_H
|
||||
#include <netinet/in_ip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef SOCKET_WRAPPER
|
||||
#ifndef SOCKET_WRAPPER_NOT_REPLACE
|
||||
#define SOCKET_WRAPPER_REPLACE
|
||||
#endif
|
||||
#include "lib/socket_wrapper/socket_wrapper.h"
|
||||
#endif
|
||||
|
||||
#ifdef REPLACE_INET_NTOA
|
||||
char *rep_inet_ntoa(struct in_addr ip);
|
||||
#define inet_ntoa rep_inet_ntoa
|
||||
#endif
|
||||
|
||||
/*
|
||||
* glibc on linux doesn't seem to have MSG_WAITALL
|
||||
* defined. I think the kernel has it though..
|
||||
*/
|
||||
#ifndef MSG_WAITALL
|
||||
#define MSG_WAITALL 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some older systems seem not to have MAXHOSTNAMELEN
|
||||
* defined.
|
||||
*/
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 254
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_LOOPBACK
|
||||
#define INADDR_LOOPBACK 0x7f000001
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
#endif
|
91
ctdb/lib/replace/system/passwd.h
Normal file
91
ctdb/lib/replace/system/passwd.h
Normal file
@ -0,0 +1,91 @@
|
||||
#ifndef _system_passwd_h
|
||||
#define _system_passwd_h
|
||||
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
passwd system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#ifdef HAVE_GRP_H
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PRIV_H
|
||||
#include <sys/priv.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_ID_H
|
||||
#include <sys/id.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CRYPT_H
|
||||
#include <crypt.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SHADOW_H
|
||||
#include <shadow.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SECURITY_H
|
||||
#include <sys/security.h>
|
||||
#include <prot.h>
|
||||
#define PASSWORD_LENGTH 16
|
||||
#endif /* HAVE_SYS_SECURITY_H */
|
||||
|
||||
#ifdef HAVE_GETPWANAM
|
||||
#include <sys/label.h>
|
||||
#include <sys/audit.h>
|
||||
#include <pwdadj.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COMPAT_H
|
||||
#include <compat.h>
|
||||
#endif
|
||||
|
||||
#ifdef REPLACE_GETPASS
|
||||
#define getpass(prompt) getsmbpass((prompt))
|
||||
#endif
|
||||
|
||||
#ifndef NGROUPS_MAX
|
||||
#define NGROUPS_MAX 32 /* Guess... */
|
||||
#endif
|
||||
|
||||
/* what is the longest significant password available on your system?
|
||||
Knowing this speeds up password searches a lot */
|
||||
#ifndef PASSWORD_LENGTH
|
||||
#define PASSWORD_LENGTH 8
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
|
||||
#define OSF1_ENH_SEC 1
|
||||
#endif
|
||||
|
||||
#ifndef ALLOW_CHANGE_PASSWORD
|
||||
#if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
|
||||
#define ALLOW_CHANGE_PASSWORD 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
|
||||
#define ULTRIX_AUTH 1
|
||||
#endif
|
||||
|
||||
#endif
|
46
ctdb/lib/replace/system/printing.h
Normal file
46
ctdb/lib/replace/system/printing.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef _system_printing_h
|
||||
#define _system_printing_h
|
||||
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
printing system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef AIX
|
||||
#define DEFAULT_PRINTING PRINT_AIX
|
||||
#define PRINTCAP_NAME "/etc/qconfig"
|
||||
#endif
|
||||
|
||||
#ifdef HPUX
|
||||
#define DEFAULT_PRINTING PRINT_HPUX
|
||||
#endif
|
||||
|
||||
#ifdef QNX
|
||||
#define DEFAULT_PRINTING PRINT_QNX
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_PRINTING
|
||||
#define DEFAULT_PRINTING PRINT_BSD
|
||||
#endif
|
||||
#ifndef PRINTCAP_NAME
|
||||
#define PRINTCAP_NAME "/etc/printcap"
|
||||
#endif
|
||||
|
||||
#endif
|
48
ctdb/lib/replace/system/readline.h
Normal file
48
ctdb/lib/replace/system/readline.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef _system_readline_h
|
||||
#define _system_readline_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
readline wrappers
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
# ifdef HAVE_READLINE_READLINE_H
|
||||
# include <readline/readline.h>
|
||||
# ifdef HAVE_READLINE_HISTORY_H
|
||||
# include <readline/history.h>
|
||||
# endif
|
||||
# else
|
||||
# ifdef HAVE_READLINE_H
|
||||
# include <readline.h>
|
||||
# ifdef HAVE_HISTORY_H
|
||||
# include <history.h>
|
||||
# endif
|
||||
# else
|
||||
# undef HAVE_LIBREADLINE
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NEW_LIBREADLINE
|
||||
# define RL_COMPLETION_CAST (rl_completion_func_t *)
|
||||
#else
|
||||
/* This type is missing from libreadline<4.0 (approximately) */
|
||||
# define RL_COMPLETION_CAST
|
||||
#endif /* HAVE_NEW_LIBREADLINE */
|
||||
|
||||
#endif
|
33
ctdb/lib/replace/system/select.h
Normal file
33
ctdb/lib/replace/system/select.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef _system_select_h
|
||||
#define _system_select_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
select system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#ifndef SELECT_CAST
|
||||
#define SELECT_CAST
|
||||
#endif
|
||||
|
||||
#endif
|
55
ctdb/lib/replace/system/shmem.h
Normal file
55
ctdb/lib/replace/system/shmem.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef _system_shmem_h
|
||||
#define _system_shmem_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
shared memory system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_SYS_IPC_H)
|
||||
#include <sys/ipc.h>
|
||||
#endif /* HAVE_SYS_IPC_H */
|
||||
|
||||
#if defined(HAVE_SYS_SHM_H)
|
||||
#include <sys/shm.h>
|
||||
#endif /* HAVE_SYS_SHM_H */
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/* NetBSD doesn't have these */
|
||||
#ifndef SHM_R
|
||||
#define SHM_R 0400
|
||||
#endif
|
||||
|
||||
#ifndef SHM_W
|
||||
#define SHM_W 0200
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MAP_FILE
|
||||
#define MAP_FILE 0
|
||||
#endif
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((void *)-1)
|
||||
#endif
|
||||
|
||||
#endif
|
66
ctdb/lib/replace/system/syslog.h
Normal file
66
ctdb/lib/replace/system/syslog.h
Normal file
@ -0,0 +1,66 @@
|
||||
#ifndef _system_syslog_h
|
||||
#define _system_syslog_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
syslog system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_SYSLOG_H
|
||||
#include <sys/syslog.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For sys_adminlog(). */
|
||||
#ifndef LOG_EMERG
|
||||
#define LOG_EMERG 0 /* system is unusable */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_ALERT
|
||||
#define LOG_ALERT 1 /* action must be taken immediately */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_CRIT
|
||||
#define LOG_CRIT 2 /* critical conditions */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_ERR
|
||||
#define LOG_ERR 3 /* error conditions */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_WARNING
|
||||
#define LOG_WARNING 4 /* warning conditions */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_NOTICE
|
||||
#define LOG_NOTICE 5 /* normal but significant condition */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_INFO
|
||||
#define LOG_INFO 6 /* informational */
|
||||
#endif
|
||||
|
||||
#ifndef LOG_DEBUG
|
||||
#define LOG_DEBUG 7 /* debug-level messages */
|
||||
#endif
|
||||
|
||||
#endif
|
42
ctdb/lib/replace/system/terminal.h
Normal file
42
ctdb/lib/replace/system/terminal.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef _system_terminal_h
|
||||
#define _system_terminal_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
terminal system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef SUNOS4
|
||||
/* on SUNOS4 termios.h conflicts with sys/ioctl.h */
|
||||
#undef HAVE_TERMIOS_H
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_TERMIOS_H)
|
||||
/* POSIX terminal handling. */
|
||||
#include <termios.h>
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
/* Older SYSV terminal handling - don't use if we can avoid it. */
|
||||
#include <termio.h>
|
||||
#elif defined(HAVE_SYS_TERMIO_H)
|
||||
/* Older SYSV terminal handling - don't use if we can avoid it. */
|
||||
#include <sys/termio.h>
|
||||
#endif
|
||||
|
||||
#endif
|
40
ctdb/lib/replace/system/time.h
Normal file
40
ctdb/lib/replace/system/time.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef _system_time_h
|
||||
#define _system_time_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
time system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTIME_H
|
||||
#include <utime.h>
|
||||
#endif
|
||||
|
||||
#endif
|
47
ctdb/lib/replace/system/wait.h
Normal file
47
ctdb/lib/replace/system/wait.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef _system_wait_h
|
||||
#define _system_wait_h
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
waitpid system include wrappers
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef SIGCLD
|
||||
#define SIGCLD SIGCHLD
|
||||
#endif
|
||||
|
||||
#ifndef SIGNAL_CAST
|
||||
#define SIGNAL_CAST (RETSIGTYPE (*)(int))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETJMP_H
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
#ifndef SA_RESETHAND
|
||||
#define SA_RESETHAND SA_ONESHOT
|
||||
#endif
|
||||
|
||||
#endif
|
115
ctdb/lib/replace/test/os2_delete.c
Normal file
115
ctdb/lib/replace/test/os2_delete.c
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
test readdir/unlink pattern that OS/2 uses
|
||||
tridge@samba.org July 2005
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define NUM_FILES 700
|
||||
#define READDIR_SIZE 100
|
||||
#define DELETE_SIZE 4
|
||||
|
||||
#define TESTDIR "test.dir"
|
||||
|
||||
static int test_readdir_os2_delete_ret;
|
||||
|
||||
#define FAILED(d) (printf("failure: readdir [\nFailed for %s - %d = %s\n]\n", d, errno, strerror(errno)), test_readdir_os2_delete_ret = 1, 1)
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
/* I'm a lazy bastard */
|
||||
system("rm -rf " TESTDIR);
|
||||
mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir");
|
||||
}
|
||||
|
||||
static void create_files(void)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<NUM_FILES;i++) {
|
||||
char fname[40];
|
||||
sprintf(fname, TESTDIR "/test%u.txt", i);
|
||||
close(open(fname, O_CREAT|O_RDWR, 0600)) == 0 || FAILED("close");
|
||||
}
|
||||
}
|
||||
|
||||
static int os2_delete(DIR *d)
|
||||
{
|
||||
off_t offsets[READDIR_SIZE];
|
||||
int i, j;
|
||||
struct dirent *de;
|
||||
char names[READDIR_SIZE][30];
|
||||
|
||||
/* scan, remembering offsets */
|
||||
for (i=0, de=readdir(d);
|
||||
de && i < READDIR_SIZE;
|
||||
de=readdir(d), i++) {
|
||||
offsets[i] = telldir(d);
|
||||
strcpy(names[i], de->d_name);
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* delete the first few */
|
||||
for (j=0; j<MIN(i, DELETE_SIZE); j++) {
|
||||
char fname[40];
|
||||
sprintf(fname, TESTDIR "/%s", names[j]);
|
||||
unlink(fname) == 0 || FAILED("unlink");
|
||||
}
|
||||
|
||||
/* seek to just after the deletion */
|
||||
seekdir(d, offsets[j-1]);
|
||||
|
||||
/* return number deleted */
|
||||
return j;
|
||||
}
|
||||
|
||||
int test_readdir_os2_delete(void)
|
||||
{
|
||||
int total_deleted = 0;
|
||||
DIR *d;
|
||||
struct dirent *de;
|
||||
|
||||
test_readdir_os2_delete_ret = 0;
|
||||
|
||||
cleanup();
|
||||
create_files();
|
||||
|
||||
d = opendir(TESTDIR "/test0.txt");
|
||||
if (d != NULL) FAILED("opendir() on file succeed");
|
||||
if (errno != ENOTDIR) FAILED("opendir() on file didn't give ENOTDIR");
|
||||
|
||||
d = opendir(TESTDIR);
|
||||
|
||||
/* skip past . and .. */
|
||||
de = readdir(d);
|
||||
strcmp(de->d_name, ".") == 0 || FAILED("match .");
|
||||
de = readdir(d);
|
||||
strcmp(de->d_name, "..") == 0 || FAILED("match ..");
|
||||
|
||||
while (1) {
|
||||
int n = os2_delete(d);
|
||||
if (n == 0) break;
|
||||
total_deleted += n;
|
||||
}
|
||||
closedir(d);
|
||||
|
||||
fprintf(stderr, "Deleted %d files of %d\n", total_deleted, NUM_FILES);
|
||||
|
||||
rmdir(TESTDIR) == 0 || FAILED("rmdir");
|
||||
|
||||
return test_readdir_os2_delete_ret;
|
||||
}
|
68
ctdb/lib/replace/test/shared_mmap.c
Normal file
68
ctdb/lib/replace/test/shared_mmap.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* this tests whether we can use a shared writeable mmap on a file -
|
||||
as needed for the mmap variant of FAST_SHARE_MODES */
|
||||
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define DATA "conftest.mmap"
|
||||
|
||||
#ifndef MAP_FILE
|
||||
#define MAP_FILE 0
|
||||
#endif
|
||||
|
||||
main()
|
||||
{
|
||||
int *buf;
|
||||
int i;
|
||||
int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666);
|
||||
int count=7;
|
||||
|
||||
if (fd == -1) exit(1);
|
||||
|
||||
for (i=0;i<10000;i++) {
|
||||
write(fd,&i,sizeof(i));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
if (fork() == 0) {
|
||||
fd = open(DATA,O_RDWR);
|
||||
if (fd == -1) exit(1);
|
||||
|
||||
buf = (int *)mmap(NULL, 10000*sizeof(int),
|
||||
(PROT_READ | PROT_WRITE),
|
||||
MAP_FILE | MAP_SHARED,
|
||||
fd, 0);
|
||||
|
||||
while (count-- && buf[9124] != 55732) sleep(1);
|
||||
|
||||
if (count <= 0) exit(1);
|
||||
|
||||
buf[1763] = 7268;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fd = open(DATA,O_RDWR);
|
||||
if (fd == -1) exit(1);
|
||||
|
||||
buf = (int *)mmap(NULL, 10000*sizeof(int),
|
||||
(PROT_READ | PROT_WRITE),
|
||||
MAP_FILE | MAP_SHARED,
|
||||
fd, 0);
|
||||
|
||||
if (buf == (int *)-1) exit(1);
|
||||
|
||||
buf[9124] = 55732;
|
||||
|
||||
while (count-- && buf[1763] != 7268) sleep(1);
|
||||
|
||||
unlink(DATA);
|
||||
|
||||
if (count > 0) exit(0);
|
||||
exit(1);
|
||||
}
|
481
ctdb/lib/replace/test/testsuite.c
Normal file
481
ctdb/lib/replace/test/testsuite.c
Normal file
@ -0,0 +1,481 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
libreplace tests
|
||||
|
||||
Copyright (C) Jelmer Vernooij 2006
|
||||
|
||||
** NOTE! The following LGPL license applies to the talloc
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
|
||||
/*
|
||||
we include all the system/ include files here so that libreplace tests
|
||||
them in the build farm
|
||||
*/
|
||||
#include "system/capability.h"
|
||||
#include "system/dir.h"
|
||||
#include "system/filesys.h"
|
||||
#include "system/glob.h"
|
||||
#include "system/iconv.h"
|
||||
#include "system/locale.h"
|
||||
#include "system/network.h"
|
||||
#include "system/passwd.h"
|
||||
#include "system/printing.h"
|
||||
#include "system/readline.h"
|
||||
#include "system/select.h"
|
||||
#include "system/shmem.h"
|
||||
#include "system/syslog.h"
|
||||
#include "system/terminal.h"
|
||||
#include "system/time.h"
|
||||
#include "system/wait.h"
|
||||
#include "system/aio.h"
|
||||
|
||||
#define TESTFILE "testfile.dat"
|
||||
|
||||
/*
|
||||
test ftruncate() function
|
||||
*/
|
||||
static int test_ftruncate(void)
|
||||
{
|
||||
struct stat st;
|
||||
int fd;
|
||||
const int size = 1234;
|
||||
printf("test: ftruncate\n");
|
||||
unlink(TESTFILE);
|
||||
fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
|
||||
if (fd == -1) {
|
||||
printf("failure: ftruncate [\n"
|
||||
"creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (ftruncate(fd, size) != 0) {
|
||||
printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (fstat(fd, &st) != 0) {
|
||||
printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (st.st_size != size) {
|
||||
printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
|
||||
(int)st.st_size, size);
|
||||
return false;
|
||||
}
|
||||
unlink(TESTFILE);
|
||||
printf("success: ftruncate\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
test strlcpy() function.
|
||||
see http://www.gratisoft.us/todd/papers/strlcpy.html
|
||||
*/
|
||||
static int test_strlcpy(void)
|
||||
{
|
||||
char buf[4];
|
||||
const struct {
|
||||
const char *src;
|
||||
size_t result;
|
||||
} tests[] = {
|
||||
{ "abc", 3 },
|
||||
{ "abcdef", 6 },
|
||||
{ "abcd", 4 },
|
||||
{ "", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
int i;
|
||||
printf("test: strlcpy\n");
|
||||
for (i=0;tests[i].src;i++) {
|
||||
if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
|
||||
printf("failure: strlcpy [\ntest %d failed\n]\n", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
printf("success: strlcpy\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strlcat(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_mktime(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_innetgr(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_initgroups(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_memmove(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strdup(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_setlinebuf(void)
|
||||
{
|
||||
printf("test: setlinebuf\n");
|
||||
setlinebuf(stdout);
|
||||
printf("success: setlinebuf\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_vsyslog(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_timegm(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_setenv(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strndup(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strnlen(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_waitpid(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_seteuid(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_setegid(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_asprintf(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_snprintf(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_vasprintf(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_vsnprintf(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_opendir(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
extern int test_readdir_os2_delete(void);
|
||||
|
||||
static int test_readdir(void)
|
||||
{
|
||||
printf("test: readdir\n");
|
||||
if (test_readdir_os2_delete() != 0) {
|
||||
return false;
|
||||
}
|
||||
printf("success: readdir\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_telldir(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_seekdir(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_dlopen(void)
|
||||
{
|
||||
/* FIXME: test dlopen, dlsym, dlclose, dlerror */
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int test_chroot(void)
|
||||
{
|
||||
/* FIXME: chroot() */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_bzero(void)
|
||||
{
|
||||
/* FIXME: bzero */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strerror(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_errno(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_mkdtemp(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_mkstemp(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_pread(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_pwrite(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_getpass(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_inet_ntoa(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strtoll(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_strtoull(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
FIXME:
|
||||
Types:
|
||||
bool
|
||||
socklen_t
|
||||
uint_t
|
||||
uint{8,16,32,64}_t
|
||||
int{8,16,32,64}_t
|
||||
intptr_t
|
||||
|
||||
Constants:
|
||||
PATH_NAME_MAX
|
||||
UINT{16,32,64}_MAX
|
||||
INT32_MAX
|
||||
*/
|
||||
|
||||
static int test_va_copy(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_FUNCTION(void)
|
||||
{
|
||||
/* FIXME: test __FUNCTION__ macro */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_MIN(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_MAX(void)
|
||||
{
|
||||
/* FIXME */
|
||||
return true;
|
||||
}
|
||||
|
||||
static int test_socketpair(void)
|
||||
{
|
||||
int sock[2];
|
||||
char buf[20];
|
||||
|
||||
printf("test: socketpair\n");
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
|
||||
printf("failure: socketpair [\n"
|
||||
"socketpair() failed\n"
|
||||
"]\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (write(sock[1], "automatisch", 12) == -1) {
|
||||
printf("failure: socketpair [\n"
|
||||
"write() failed: %s\n"
|
||||
"]\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read(sock[0], buf, 12) == -1) {
|
||||
printf("failure: socketpair [\n"
|
||||
"read() failed: %s\n"
|
||||
"]\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(buf, "automatisch") != 0) {
|
||||
printf("failure: socketpair [\n"
|
||||
"expected: automatisch, got: %s\n"
|
||||
"]\n", buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("success: socketpair\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct torture_context;
|
||||
bool torture_local_replace(struct torture_context *ctx)
|
||||
{
|
||||
bool ret = true;
|
||||
ret &= test_ftruncate();
|
||||
ret &= test_strlcpy();
|
||||
ret &= test_strlcat();
|
||||
ret &= test_mktime();
|
||||
ret &= test_innetgr();
|
||||
ret &= test_initgroups();
|
||||
ret &= test_memmove();
|
||||
ret &= test_strdup();
|
||||
ret &= test_setlinebuf();
|
||||
ret &= test_vsyslog();
|
||||
ret &= test_timegm();
|
||||
ret &= test_setenv();
|
||||
ret &= test_strndup();
|
||||
ret &= test_strnlen();
|
||||
ret &= test_waitpid();
|
||||
ret &= test_seteuid();
|
||||
ret &= test_setegid();
|
||||
ret &= test_asprintf();
|
||||
ret &= test_snprintf();
|
||||
ret &= test_vasprintf();
|
||||
ret &= test_vsnprintf();
|
||||
ret &= test_opendir();
|
||||
ret &= test_readdir();
|
||||
ret &= test_telldir();
|
||||
ret &= test_seekdir();
|
||||
ret &= test_dlopen();
|
||||
ret &= test_chroot();
|
||||
ret &= test_bzero();
|
||||
ret &= test_strerror();
|
||||
ret &= test_errno();
|
||||
ret &= test_mkdtemp();
|
||||
ret &= test_mkstemp();
|
||||
ret &= test_pread();
|
||||
ret &= test_pwrite();
|
||||
ret &= test_getpass();
|
||||
ret &= test_inet_ntoa();
|
||||
ret &= test_strtoll();
|
||||
ret &= test_strtoll();
|
||||
ret &= test_strtoull();
|
||||
ret &= test_va_copy();
|
||||
ret &= test_FUNCTION();
|
||||
ret &= test_MIN();
|
||||
ret &= test_MAX();
|
||||
ret &= test_socketpair();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if _SAMBA_BUILD_<4
|
||||
int main(void)
|
||||
{
|
||||
bool ret = torture_local_replace(NULL);
|
||||
if (ret)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
78
ctdb/lib/replace/timegm.c
Normal file
78
ctdb/lib/replace/timegm.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 1997 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
adapted for Samba4 by Andrew Tridgell
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
#include "system/time.h"
|
||||
|
||||
static int is_leap(unsigned y)
|
||||
{
|
||||
y += 1900;
|
||||
return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0);
|
||||
}
|
||||
|
||||
time_t rep_timegm(struct tm *tm)
|
||||
{
|
||||
static const unsigned ndays[2][12] ={
|
||||
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
|
||||
time_t res = 0;
|
||||
unsigned i;
|
||||
|
||||
if (tm->tm_mon > 12 ||
|
||||
tm->tm_mon < 0 ||
|
||||
tm->tm_mday > 31 ||
|
||||
tm->tm_min > 60 ||
|
||||
tm->tm_sec > 60 ||
|
||||
tm->tm_hour > 24) {
|
||||
/* invalid tm structure */
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 70; i < tm->tm_year; ++i)
|
||||
res += is_leap(i) ? 366 : 365;
|
||||
|
||||
for (i = 0; i < tm->tm_mon; ++i)
|
||||
res += ndays[is_leap(tm->tm_year)][i];
|
||||
res += tm->tm_mday - 1;
|
||||
res *= 24;
|
||||
res += tm->tm_hour;
|
||||
res *= 60;
|
||||
res += tm->tm_min;
|
||||
res *= 60;
|
||||
res += tm->tm_sec;
|
||||
return res;
|
||||
}
|
1
ctdb/lib/replace/timegm.m4
Normal file
1
ctdb/lib/replace/timegm.m4
Normal file
@ -0,0 +1 @@
|
||||
AC_CHECK_FUNCS(timegm,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} timegm.o"])
|
20
ctdb/lib/replace/win32.m4
Normal file
20
ctdb/lib/replace/win32.m4
Normal file
@ -0,0 +1,20 @@
|
||||
AC_CHECK_HEADERS(direct.h windows.h winsock2.h ws2tcpip.h)
|
||||
|
||||
#######################################
|
||||
# Check for mkdir mode
|
||||
AC_CACHE_CHECK( [whether mkdir supports mode], ac_mkdir_has_mode,
|
||||
AC_TRY_COMPILE([
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_DIRECT_H
|
||||
#include <direct.h>
|
||||
#endif],[
|
||||
mkdir("foo",0777);
|
||||
return 0;
|
||||
],
|
||||
ac_mkdir_has_mode="yes",
|
||||
ac_mkdir_has_mode="no") )
|
||||
|
||||
if test "$ac_mkdir_has_mode" = "yes"
|
||||
then
|
||||
AC_DEFINE(HAVE_MKDIR_MODE, 1, [Define if target mkdir supports mode option])
|
||||
fi
|
159
ctdb/lib/replace/win32_replace.h
Normal file
159
ctdb/lib/replace/win32_replace.h
Normal file
@ -0,0 +1,159 @@
|
||||
#ifndef _WIN32_REPLACE_H
|
||||
#define _WIN32_REPLACE_H
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WS2TCPIP_H
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* Map BSD Socket errorcodes to the WSA errorcodes (if possible) */
|
||||
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
#define ENOTCONN WSAENOTCONN
|
||||
#define ENOTSUP 134
|
||||
|
||||
/* We undefine the following constants due to conflicts with the w32api headers
|
||||
* and the Windows Platform SDK/DDK.
|
||||
*/
|
||||
|
||||
#undef interface
|
||||
|
||||
#undef ERROR_INVALID_PARAMETER
|
||||
#undef ERROR_INSUFFICIENT_BUFFER
|
||||
#undef ERROR_INVALID_DATATYPE
|
||||
|
||||
#undef FILE_GENERIC_READ
|
||||
#undef FILE_GENERIC_WRITE
|
||||
#undef FILE_GENERIC_EXECUTE
|
||||
#undef FILE_ATTRIBUTE_READONLY
|
||||
#undef FILE_ATTRIBUTE_HIDDEN
|
||||
#undef FILE_ATTRIBUTE_SYSTEM
|
||||
#undef FILE_ATTRIBUTE_DIRECTORY
|
||||
#undef FILE_ATTRIBUTE_ARCHIVE
|
||||
#undef FILE_ATTRIBUTE_DEVICE
|
||||
#undef FILE_ATTRIBUTE_NORMAL
|
||||
#undef FILE_ATTRIBUTE_TEMPORARY
|
||||
#undef FILE_ATTRIBUTE_REPARSE_POINT
|
||||
#undef FILE_ATTRIBUTE_COMPRESSED
|
||||
#undef FILE_ATTRIBUTE_OFFLINE
|
||||
#undef FILE_ATTRIBUTE_ENCRYPTED
|
||||
#undef FILE_FLAG_WRITE_THROUGH
|
||||
#undef FILE_FLAG_NO_BUFFERING
|
||||
#undef FILE_FLAG_RANDOM_ACCESS
|
||||
#undef FILE_FLAG_SEQUENTIAL_SCAN
|
||||
#undef FILE_FLAG_DELETE_ON_CLOSE
|
||||
#undef FILE_FLAG_BACKUP_SEMANTICS
|
||||
#undef FILE_FLAG_POSIX_SEMANTICS
|
||||
#undef FILE_TYPE_DISK
|
||||
#undef FILE_TYPE_UNKNOWN
|
||||
#undef FILE_CASE_SENSITIVE_SEARCH
|
||||
#undef FILE_CASE_PRESERVED_NAMES
|
||||
#undef FILE_UNICODE_ON_DISK
|
||||
#undef FILE_PERSISTENT_ACLS
|
||||
#undef FILE_FILE_COMPRESSION
|
||||
#undef FILE_VOLUME_QUOTAS
|
||||
#undef FILE_VOLUME_IS_COMPRESSED
|
||||
#undef FILE_NOTIFY_CHANGE_FILE_NAME
|
||||
#undef FILE_NOTIFY_CHANGE_DIR_NAME
|
||||
#undef FILE_NOTIFY_CHANGE_ATTRIBUTES
|
||||
#undef FILE_NOTIFY_CHANGE_SIZE
|
||||
#undef FILE_NOTIFY_CHANGE_LAST_WRITE
|
||||
#undef FILE_NOTIFY_CHANGE_LAST_ACCESS
|
||||
#undef FILE_NOTIFY_CHANGE_CREATION
|
||||
#undef FILE_NOTIFY_CHANGE_EA
|
||||
#undef FILE_NOTIFY_CHANGE_SECURITY
|
||||
#undef FILE_NOTIFY_CHANGE_STREAM_NAME
|
||||
#undef FILE_NOTIFY_CHANGE_STREAM_SIZE
|
||||
#undef FILE_NOTIFY_CHANGE_STREAM_WRITE
|
||||
#undef FILE_NOTIFY_CHANGE_NAME
|
||||
|
||||
#undef PRINTER_ATTRIBUTE_QUEUED
|
||||
#undef PRINTER_ATTRIBUTE_DIRECT
|
||||
#undef PRINTER_ATTRIBUTE_DEFAULT
|
||||
#undef PRINTER_ATTRIBUTE_SHARED
|
||||
#undef PRINTER_ATTRIBUTE_NETWORK
|
||||
#undef PRINTER_ATTRIBUTE_HIDDEN
|
||||
#undef PRINTER_ATTRIBUTE_LOCAL
|
||||
#undef PRINTER_ATTRIBUTE_ENABLE_DEVQ
|
||||
#undef PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
|
||||
#undef PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST
|
||||
#undef PRINTER_ATTRIBUTE_WORK_OFFLINE
|
||||
#undef PRINTER_ATTRIBUTE_ENABLE_BIDI
|
||||
#undef PRINTER_ATTRIBUTE_RAW_ONLY
|
||||
#undef PRINTER_ATTRIBUTE_PUBLISHED
|
||||
#undef PRINTER_ENUM_DEFAULT
|
||||
#undef PRINTER_ENUM_LOCAL
|
||||
#undef PRINTER_ENUM_CONNECTIONS
|
||||
#undef PRINTER_ENUM_FAVORITE
|
||||
#undef PRINTER_ENUM_NAME
|
||||
#undef PRINTER_ENUM_REMOTE
|
||||
#undef PRINTER_ENUM_SHARED
|
||||
#undef PRINTER_ENUM_NETWORK
|
||||
#undef PRINTER_ENUM_EXPAND
|
||||
#undef PRINTER_ENUM_CONTAINER
|
||||
#undef PRINTER_ENUM_ICON1
|
||||
#undef PRINTER_ENUM_ICON2
|
||||
#undef PRINTER_ENUM_ICON3
|
||||
#undef PRINTER_ENUM_ICON4
|
||||
#undef PRINTER_ENUM_ICON5
|
||||
#undef PRINTER_ENUM_ICON6
|
||||
#undef PRINTER_ENUM_ICON7
|
||||
#undef PRINTER_ENUM_ICON8
|
||||
#undef PRINTER_STATUS_PAUSED
|
||||
#undef PRINTER_STATUS_ERROR
|
||||
#undef PRINTER_STATUS_PENDING_DELETION
|
||||
#undef PRINTER_STATUS_PAPER_JAM
|
||||
#undef PRINTER_STATUS_PAPER_OUT
|
||||
#undef PRINTER_STATUS_MANUAL_FEED
|
||||
#undef PRINTER_STATUS_PAPER_PROBLEM
|
||||
#undef PRINTER_STATUS_OFFLINE
|
||||
#undef PRINTER_STATUS_IO_ACTIVE
|
||||
#undef PRINTER_STATUS_BUSY
|
||||
#undef PRINTER_STATUS_PRINTING
|
||||
#undef PRINTER_STATUS_OUTPUT_BIN_FULL
|
||||
#undef PRINTER_STATUS_NOT_AVAILABLE
|
||||
#undef PRINTER_STATUS_WAITING
|
||||
#undef PRINTER_STATUS_PROCESSING
|
||||
#undef PRINTER_STATUS_INITIALIZING
|
||||
#undef PRINTER_STATUS_WARMING_UP
|
||||
#undef PRINTER_STATUS_TONER_LOW
|
||||
#undef PRINTER_STATUS_NO_TONER
|
||||
#undef PRINTER_STATUS_PAGE_PUNT
|
||||
#undef PRINTER_STATUS_USER_INTERVENTION
|
||||
#undef PRINTER_STATUS_OUT_OF_MEMORY
|
||||
#undef PRINTER_STATUS_DOOR_OPEN
|
||||
#undef PRINTER_STATUS_SERVER_UNKNOWN
|
||||
#undef PRINTER_STATUS_POWER_SAVE
|
||||
|
||||
#undef DWORD
|
||||
#undef HKEY_CLASSES_ROOT
|
||||
#undef HKEY_CURRENT_USER
|
||||
#undef HKEY_LOCAL_MACHINE
|
||||
#undef HKEY_USERS
|
||||
#undef HKEY_PERFORMANCE_DATA
|
||||
#undef HKEY_CURRENT_CONFIG
|
||||
#undef HKEY_DYN_DATA
|
||||
#undef REG_DWORD
|
||||
#undef REG_QWORD
|
||||
|
||||
#undef SERVICE_STATE_ALL
|
||||
|
||||
#undef SE_GROUP_MANDATORY
|
||||
#undef SE_GROUP_ENABLED_BY_DEFAULT
|
||||
#undef SE_GROUP_ENABLED
|
||||
|
||||
#endif /* _WIN32_REPLACE_H */
|
71
ctdb/lib/talloc/Makefile.in
Normal file
71
ctdb/lib/talloc/Makefile.in
Normal file
@ -0,0 +1,71 @@
|
||||
#!gmake
|
||||
#
|
||||
prefix = @prefix@
|
||||
datarootdir = @datarootdir@
|
||||
exec_prefix = @exec_prefix@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
mandir = @mandir@
|
||||
VPATH = @srcdir@:@libreplacedir@
|
||||
srcdir = @srcdir@
|
||||
builddir = @builddir@
|
||||
XSLTPROC = @XSLTPROC@
|
||||
INSTALLCMD = @INSTALL@
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@ -DHAVE_CONFIG_H= -I. -I@srcdir@ -I@libreplacedir@
|
||||
EXTRA_TARGETS = @DOC_TARGET@
|
||||
|
||||
.SUFFIXES: .c .o .3 .3.xml .xml .html
|
||||
|
||||
LIBOBJ = @TALLOCOBJ@ @LIBREPLACEOBJ@
|
||||
|
||||
all: showflags libtalloc.a testsuite $(EXTRA_TARGETS)
|
||||
|
||||
showflags:
|
||||
@echo 'talloc will be compiled with flags:'
|
||||
@echo ' CFLAGS = $(CFLAGS)'
|
||||
@echo ' LIBS = $(LIBS)'
|
||||
|
||||
testsuite: $(LIBOBJ) testsuite.o
|
||||
$(CC) $(CFLAGS) -o testsuite testsuite.o $(LIBOBJ) $(LIBS)
|
||||
|
||||
libtalloc.a: $(LIBOBJ)
|
||||
ar -rv $@ $(LIBOBJ)
|
||||
@-ranlib $@
|
||||
|
||||
install: all
|
||||
${INSTALLCMD} -d ${libdir}
|
||||
${INSTALLCMD} -m 755 libtalloc.a $(libdir)
|
||||
${INSTALLCMD} -d ${includedir}
|
||||
${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(includedir)
|
||||
${INSTALLCMD} -m 644 talloc.pc $(libdir)/pkgconfig
|
||||
if [ -f talloc.3 ];then ${INSTALLCMD} -d ${mandir}/man3; fi
|
||||
if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(mandir)/man3; fi
|
||||
|
||||
doc: talloc.3 talloc.3.html
|
||||
|
||||
.3.xml.3:
|
||||
-test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
|
||||
|
||||
.xml.html:
|
||||
-test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl $<
|
||||
|
||||
clean:
|
||||
rm -f *~ $(LIBOBJ) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html
|
||||
|
||||
test: testsuite
|
||||
./testsuite
|
||||
|
||||
gcov:
|
||||
gcov talloc.c
|
||||
|
||||
installcheck:
|
||||
$(MAKE) test
|
||||
|
||||
distclean: clean
|
||||
rm -f *~ */*~
|
||||
rm -f Makefile
|
||||
rm -f config.log config.status config.h config.cache
|
||||
|
||||
realdistclean: distclean
|
||||
rm -f configure config.h.in
|
1
ctdb/lib/talloc/aclocal.m4
vendored
Normal file
1
ctdb/lib/talloc/aclocal.m4
vendored
Normal file
@ -0,0 +1 @@
|
||||
m4_include(libreplace.m4)
|
14
ctdb/lib/talloc/autogen.sh
Executable file
14
ctdb/lib/talloc/autogen.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf autom4te.cache
|
||||
rm -f configure config.h.in
|
||||
|
||||
IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace"
|
||||
autoconf $IPATHS || exit 1
|
||||
autoheader $IPATHS || exit 1
|
||||
|
||||
rm -rf autom4te.cache
|
||||
|
||||
echo "Now run ./configure and then make."
|
||||
exit 0
|
||||
|
1466
ctdb/lib/talloc/config.guess
vendored
Executable file
1466
ctdb/lib/talloc/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
696
ctdb/lib/talloc/config.h.in
Normal file
696
ctdb/lib/talloc/config.h.in
Normal file
@ -0,0 +1,696 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Whether strndup is broken */
|
||||
#undef BROKEN_STRNDUP
|
||||
|
||||
/* Whether strnlen is broken */
|
||||
#undef BROKEN_STRNLEN
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#undef HAVE_ARPA_INET_H
|
||||
|
||||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#undef HAVE_ASPRINTF
|
||||
|
||||
/* Whether the bool type is available */
|
||||
#undef HAVE_BOOL
|
||||
|
||||
/* Define to 1 if you have the `bzero' function. */
|
||||
#undef HAVE_BZERO
|
||||
|
||||
/* Whether there is a C99 compliant vsnprintf */
|
||||
#undef HAVE_C99_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `chroot' function. */
|
||||
#undef HAVE_CHROOT
|
||||
|
||||
/* Define to 1 if you have the `chsize' function. */
|
||||
#undef HAVE_CHSIZE
|
||||
|
||||
/* Whether or not we have comparison_fn_t */
|
||||
#undef HAVE_COMPARISON_FN_T
|
||||
|
||||
/* Define to 1 if you have the <compat.h> header file. */
|
||||
#undef HAVE_COMPAT_H
|
||||
|
||||
/* Define to 1 if you have the <ctype.h> header file. */
|
||||
#undef HAVE_CTYPE_H
|
||||
|
||||
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_ASPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_VASPRINTF
|
||||
|
||||
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <direct.h> header file. */
|
||||
#undef HAVE_DIRECT_H
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
|
||||
/* Define to 1 if you have the `dlclose' function. */
|
||||
#undef HAVE_DLCLOSE
|
||||
|
||||
/* Define to 1 if you have the `dlerror' function. */
|
||||
#undef HAVE_DLERROR
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `dlopen' function. */
|
||||
#undef HAVE_DLOPEN
|
||||
|
||||
/* Define to 1 if you have the `dlsym' function. */
|
||||
#undef HAVE_DLSYM
|
||||
|
||||
/* Define to 1 if you have the `endnetgrent' function. */
|
||||
#undef HAVE_ENDNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `epoll_create' function. */
|
||||
#undef HAVE_EPOLL_CREATE
|
||||
|
||||
/* Whether errno() is available */
|
||||
#undef HAVE_ERRNO_DECL
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <fnmatch.h> header file. */
|
||||
#undef HAVE_FNMATCH_H
|
||||
|
||||
/* Define to 1 if you have the `ftruncate' function. */
|
||||
#undef HAVE_FTRUNCATE
|
||||
|
||||
/* Whether there is a __FUNCTION__ macro */
|
||||
#undef HAVE_FUNCTION_MACRO
|
||||
|
||||
/* Define to 1 if you have the `getdents' function. */
|
||||
#undef HAVE_GETDENTS
|
||||
|
||||
/* Define to 1 if you have the `getdirentries' function. */
|
||||
#undef HAVE_GETDIRENTRIES
|
||||
|
||||
/* Define to 1 if you have the `getnetgrent' function. */
|
||||
#undef HAVE_GETNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `getpgrp' function. */
|
||||
#undef HAVE_GETPGRP
|
||||
|
||||
/* Define to 1 if you have the <grp.h> header file. */
|
||||
#undef HAVE_GRP_H
|
||||
|
||||
/* Whether the compiler supports immediate structures */
|
||||
#undef HAVE_IMMEDIATE_STRUCTURES
|
||||
|
||||
/* Define to 1 if you have the `initgroups' function. */
|
||||
#undef HAVE_INITGROUPS
|
||||
|
||||
/* Define to 1 if you have the `innetgr' function. */
|
||||
#undef HAVE_INNETGR
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define to 1 if the system has the type `long long'. */
|
||||
#undef HAVE_LONG_LONG
|
||||
|
||||
/* Define to 1 if you have the `lstat' function. */
|
||||
#undef HAVE_LSTAT
|
||||
|
||||
/* Define to 1 if you have the `memcpy' function. */
|
||||
#undef HAVE_MEMCPY
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#undef HAVE_MEMMOVE
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define if target mkdir supports mode option */
|
||||
#undef HAVE_MKDIR_MODE
|
||||
|
||||
/* Define to 1 if you have the `mkdtemp' function. */
|
||||
#undef HAVE_MKDTEMP
|
||||
|
||||
/* Define to 1 if you have the `mktime' function. */
|
||||
#undef HAVE_MKTIME
|
||||
|
||||
/* Whether mmap works */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#undef HAVE_NETDB_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#undef HAVE_NETINET_IN_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in_ip.h> header file. */
|
||||
#undef HAVE_NETINET_IN_IP_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in_systm.h> header file. */
|
||||
#undef HAVE_NETINET_IN_SYSTM_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/ip.h> header file. */
|
||||
#undef HAVE_NETINET_IP_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/tcp.h> header file. */
|
||||
#undef HAVE_NETINET_TCP_H
|
||||
|
||||
/* usability of net/if.h */
|
||||
#undef HAVE_NET_IF_H
|
||||
|
||||
/* Whether the open(2) accepts O_DIRECT */
|
||||
#undef HAVE_OPEN_O_DIRECT
|
||||
|
||||
/* Define to 1 if you have the `pipe' function. */
|
||||
#undef HAVE_PIPE
|
||||
|
||||
/* Define to 1 if you have the `pread' function. */
|
||||
#undef HAVE_PREAD
|
||||
|
||||
/* Define to 1 if you have the `printf' function. */
|
||||
#undef HAVE_PRINTF
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#undef HAVE_PWD_H
|
||||
|
||||
/* Define to 1 if you have the `pwrite' function. */
|
||||
#undef HAVE_PWRITE
|
||||
|
||||
/* Define to 1 if you have the `rand' function. */
|
||||
#undef HAVE_RAND
|
||||
|
||||
/* Define to 1 if you have the `random' function. */
|
||||
#undef HAVE_RANDOM
|
||||
|
||||
/* Define to 1 if you have the `rename' function. */
|
||||
#undef HAVE_RENAME
|
||||
|
||||
/* Whether mkstemp is secure */
|
||||
#undef HAVE_SECURE_MKSTEMP
|
||||
|
||||
/* Define to 1 if you have the `setbuffer' function. */
|
||||
#undef HAVE_SETBUFFER
|
||||
|
||||
/* Define to 1 if you have the `setegid' function. */
|
||||
#undef HAVE_SETEGID
|
||||
|
||||
/* Define to 1 if you have the `setenv' function. */
|
||||
#undef HAVE_SETENV
|
||||
|
||||
/* Define to 1 if you have the `seteuid' function. */
|
||||
#undef HAVE_SETEUID
|
||||
|
||||
/* Define to 1 if you have the `setlinebuf' function. */
|
||||
#undef HAVE_SETLINEBUF
|
||||
|
||||
/* Define to 1 if you have the `setnetgrent' function. */
|
||||
#undef HAVE_SETNETGRENT
|
||||
|
||||
/* Define to 1 if you have the `setresgid' function. */
|
||||
#undef HAVE_SETRESGID
|
||||
|
||||
/* Whether setresgid() is available */
|
||||
#undef HAVE_SETRESGID_DECL
|
||||
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
#undef HAVE_SETRESUID
|
||||
|
||||
/* Whether setresuid() is available */
|
||||
#undef HAVE_SETRESUID_DECL
|
||||
|
||||
/* Define to 1 if you have the <shadow.h> header file. */
|
||||
#undef HAVE_SHADOW_H
|
||||
|
||||
/* Whether we have the atomic_t variable type */
|
||||
#undef HAVE_SIG_ATOMIC_T_TYPE
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `socketpair' function. */
|
||||
#undef HAVE_SOCKETPAIR
|
||||
|
||||
/* Define to 1 if you have the `srand' function. */
|
||||
#undef HAVE_SRAND
|
||||
|
||||
/* Define to 1 if you have the `srandom' function. */
|
||||
#undef HAVE_SRANDOM
|
||||
|
||||
/* Define to 1 if you have the <standards.h> header file. */
|
||||
#undef HAVE_STANDARDS_H
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#undef HAVE_STDARG_H
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#undef HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#undef HAVE_STDIO_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strcasestr' function. */
|
||||
#undef HAVE_STRCASESTR
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#undef HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the `strftime' function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcat' function. */
|
||||
#undef HAVE_STRLCAT
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#undef HAVE_STRNDUP
|
||||
|
||||
/* Define to 1 if you have the `strnlen' function. */
|
||||
#undef HAVE_STRNLEN
|
||||
|
||||
/* Define to 1 if you have the `strtok_r' function. */
|
||||
#undef HAVE_STRTOK_R
|
||||
|
||||
/* Define to 1 if you have the `strtoll' function. */
|
||||
#undef HAVE_STRTOLL
|
||||
|
||||
/* Define to 1 if you have the `strtoq' function. */
|
||||
#undef HAVE_STRTOQ
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
#undef HAVE_STRTOULL
|
||||
|
||||
/* Define to 1 if you have the `strtouq' function. */
|
||||
#undef HAVE_STRTOUQ
|
||||
|
||||
/* Define to 1 if `st_rdev' is member of `struct stat'. */
|
||||
#undef HAVE_STRUCT_STAT_ST_RDEV
|
||||
|
||||
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
|
||||
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
|
||||
#undef HAVE_ST_RDEV
|
||||
|
||||
/* Define to 1 if you have the `syslog' function. */
|
||||
#undef HAVE_SYSLOG
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#undef HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/acl.h> header file. */
|
||||
#undef HAVE_SYS_ACL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/capability.h> header file. */
|
||||
#undef HAVE_SYS_CAPABILITY_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/epoll.h> header file. */
|
||||
#undef HAVE_SYS_EPOLL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fcntl.h> header file. */
|
||||
#undef HAVE_SYS_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filio.h> header file. */
|
||||
#undef HAVE_SYS_FILIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filsys.h> header file. */
|
||||
#undef HAVE_SYS_FILSYS_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fs/s5param.h> header file. */
|
||||
#undef HAVE_SYS_FS_S5PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/id.h> header file. */
|
||||
#undef HAVE_SYS_ID_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ipc.h> header file. */
|
||||
#undef HAVE_SYS_IPC_H
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#undef HAVE_SYS_MMAN_H
|
||||
|
||||
/* Define to 1 if you have the <sys/mode.h> header file. */
|
||||
#undef HAVE_SYS_MODE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/priv.h> header file. */
|
||||
#undef HAVE_SYS_PRIV_H
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
#undef HAVE_SYS_RESOURCE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/security.h> header file. */
|
||||
#undef HAVE_SYS_SECURITY_H
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/shm.h> header file. */
|
||||
#undef HAVE_SYS_SHM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/sockio.h> header file. */
|
||||
#undef HAVE_SYS_SOCKIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/syslog.h> header file. */
|
||||
#undef HAVE_SYS_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/termio.h> header file. */
|
||||
#undef HAVE_SYS_TERMIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <sys/un.h> header file. */
|
||||
#undef HAVE_SYS_UN_H
|
||||
|
||||
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the <termios.h> header file. */
|
||||
#undef HAVE_TERMIOS_H
|
||||
|
||||
/* Define to 1 if you have the <termio.h> header file. */
|
||||
#undef HAVE_TERMIO_H
|
||||
|
||||
/* Define to 1 if you have the `timegm' function. */
|
||||
#undef HAVE_TIMEGM
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#undef HAVE_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
/* Define to 1 if you have the <vararg.h> header file. */
|
||||
#undef HAVE_VARARG_H
|
||||
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#undef HAVE_VASPRINTF
|
||||
|
||||
/* Whether va_copy() is available */
|
||||
#undef HAVE_VA_COPY
|
||||
|
||||
/* Whether the C compiler understands volatile */
|
||||
#undef HAVE_VOLATILE
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `vsyslog' function. */
|
||||
#undef HAVE_VSYSLOG
|
||||
|
||||
/* Define to 1 if you have the `waitpid' function. */
|
||||
#undef HAVE_WAITPID
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Define to 1 if you have the <winsock2.h> header file. */
|
||||
#undef HAVE_WINSOCK2_H
|
||||
|
||||
/* Define to 1 if you have the <ws2tcpip.h> header file. */
|
||||
#undef HAVE_WS2TCPIP_H
|
||||
|
||||
/* Whether the _Bool type is available */
|
||||
#undef HAVE__Bool
|
||||
|
||||
/* Whether the __VA_ARGS__ macro is available */
|
||||
#undef HAVE__VA_ARGS__MACRO
|
||||
|
||||
/* Define to 1 if you have the `__strtoll' function. */
|
||||
#undef HAVE___STRTOLL
|
||||
|
||||
/* Define to 1 if you have the `__strtoull' function. */
|
||||
#undef HAVE___STRTOULL
|
||||
|
||||
/* Whether __va_copy() is available */
|
||||
#undef HAVE___VA_COPY
|
||||
|
||||
/* Whether there is a __func__ macro */
|
||||
#undef HAVE_func_MACRO
|
||||
|
||||
/* Whether MMAP is broken */
|
||||
#undef MMAP_BLACKLIST
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Whether getpass should be replaced */
|
||||
#undef REPLACE_GETPASS
|
||||
|
||||
/* Whether inet_ntoa should be replaced */
|
||||
#undef REPLACE_INET_NTOA
|
||||
|
||||
/* replace readdir */
|
||||
#undef REPLACE_READDIR
|
||||
|
||||
/* replace readdir using getdents() */
|
||||
#undef REPLACE_READDIR_GETDENTS
|
||||
|
||||
/* replace readdir using getdirentries() */
|
||||
#undef REPLACE_READDIR_GETDIRENTRIES
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Whether seekdir returns an int */
|
||||
#undef SEEKDIR_RETURNS_INT
|
||||
|
||||
/* The size of `char', as computed by sizeof. */
|
||||
#undef SIZEOF_CHAR
|
||||
|
||||
/* The size of `int', as computed by sizeof. */
|
||||
#undef SIZEOF_INT
|
||||
|
||||
/* The size of `long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG
|
||||
|
||||
/* The size of `long long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG_LONG
|
||||
|
||||
/* The size of `off_t', as computed by sizeof. */
|
||||
#undef SIZEOF_OFF_T
|
||||
|
||||
/* The size of `short', as computed by sizeof. */
|
||||
#undef SIZEOF_SHORT
|
||||
|
||||
/* The size of `size_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SIZE_T
|
||||
|
||||
/* The size of `ssize_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SSIZE_T
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#undef SIZEOF_VOID_P
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Whether telldir takes a const pointer */
|
||||
#undef TELLDIR_TAKES_CONST_DIR
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to 1 if on MINIX. */
|
||||
#undef _MINIX
|
||||
|
||||
#ifndef _OSF_SOURCE
|
||||
# define _OSF_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
||||
this defined. */
|
||||
#undef _POSIX_1_SOURCE
|
||||
|
||||
/* Whether to enable POSIX support */
|
||||
#undef _POSIX_C_SOURCE
|
||||
|
||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Whether to enable System V compatibility */
|
||||
#undef _SYSV
|
||||
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
# define _XOPEN_SOURCE_EXTENDED 1
|
||||
#endif
|
||||
|
||||
/* Enable extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef ino_t
|
||||
|
||||
/* Define to `short' if <sys/types.h> does not define. */
|
||||
#undef int16_t
|
||||
|
||||
/* Define to `long' if <sys/types.h> does not define. */
|
||||
#undef int32_t
|
||||
|
||||
/* Define to `long long' if <sys/types.h> does not define. */
|
||||
#undef int64_t
|
||||
|
||||
/* Define to `char' if <sys/types.h> does not define. */
|
||||
#undef int8_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef intptr_t
|
||||
|
||||
/* Define to `off_t' if <sys/types.h> does not define. */
|
||||
#undef loff_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `loff_t' if <sys/types.h> does not define. */
|
||||
#undef offset_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef ptrdiff_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Socket length type */
|
||||
#undef socklen_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Define to `unsigned short' if <sys/types.h> does not define. */
|
||||
#undef uint16_t
|
||||
|
||||
/* Define to `unsigned long' if <sys/types.h> does not define. */
|
||||
#undef uint32_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef uint64_t
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#undef uint8_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef uint_t
|
13
ctdb/lib/talloc/config.mk
Normal file
13
ctdb/lib/talloc/config.mk
Normal file
@ -0,0 +1,13 @@
|
||||
################################################
|
||||
# Start LIBRARY LIBTALLOC
|
||||
[LIBRARY::LIBTALLOC]
|
||||
VERSION = 0.0.1
|
||||
SO_VERSION = 0
|
||||
OBJ_FILES = talloc.o
|
||||
MANPAGE = talloc.3
|
||||
CFLAGS = -Ilib/talloc
|
||||
PUBLIC_HEADERS = talloc.h
|
||||
DESCRIPTION = A hierarchical pool based memory system with destructors
|
||||
#
|
||||
# End LIBRARY LIBTALLOC
|
||||
################################################
|
1579
ctdb/lib/talloc/config.sub
vendored
Executable file
1579
ctdb/lib/talloc/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
18
ctdb/lib/talloc/configure.ac
Normal file
18
ctdb/lib/talloc/configure.ac
Normal file
@ -0,0 +1,18 @@
|
||||
AC_PREREQ(2.50)
|
||||
AC_INIT(talloc.h)
|
||||
AC_CONFIG_SRCDIR([talloc.c])
|
||||
AC_SUBST(datarootdir)
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_LIBREPLACE_ALL_CHECKS
|
||||
|
||||
m4_include(libtalloc.m4)
|
||||
|
||||
AC_PATH_PROG(XSLTPROC,xsltproc)
|
||||
DOC_TARGET=""
|
||||
if test -n "$XSLTPROC"; then
|
||||
DOC_TARGET=doc
|
||||
fi
|
||||
AC_SUBST(DOC_TARGET)
|
||||
|
||||
AC_OUTPUT(Makefile talloc.pc)
|
238
ctdb/lib/talloc/install-sh
Executable file
238
ctdb/lib/talloc/install-sh
Executable file
@ -0,0 +1,238 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
#
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
27
ctdb/lib/talloc/libtalloc.m4
Normal file
27
ctdb/lib/talloc/libtalloc.m4
Normal file
@ -0,0 +1,27 @@
|
||||
dnl find the talloc sources. This is meant to work both for
|
||||
dnl talloc standalone builds, and builds of packages using talloc
|
||||
tallocdir=""
|
||||
tallocpaths="$srcdir $srcdir/lib/talloc $srcdir/talloc $srcdir/../talloc"
|
||||
for d in $tallocpaths; do
|
||||
if test -f "$d/talloc.c"; then
|
||||
tallocdir="$d"
|
||||
AC_SUBST(tallocdir)
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if test x"$tallocdir" = "x"; then
|
||||
AC_MSG_ERROR([cannot find talloc source in $tallocpaths])
|
||||
fi
|
||||
TALLOCOBJ="talloc.o"
|
||||
AC_SUBST(TALLOCOBJ)
|
||||
|
||||
AC_CHECK_SIZEOF(size_t,cross)
|
||||
AC_CHECK_SIZEOF(void *,cross)
|
||||
|
||||
if test $ac_cv_sizeof_size_t -lt $ac_cv_sizeof_void_p; then
|
||||
AC_WARN([size_t cannot represent the amount of used memory of a process])
|
||||
AC_WARN([please report this to <samba-technical@samba.org>])
|
||||
AC_WARN([sizeof(size_t) = $ac_cv_sizeof_size_t])
|
||||
AC_WARN([sizeof(void *) = $ac_cv_sizeof_void_p])
|
||||
AC_ERROR([sizeof(size_t) < sizeof(void *)])
|
||||
fi
|
500
ctdb/lib/talloc/talloc.3
Normal file
500
ctdb/lib/talloc/talloc.3
Normal file
@ -0,0 +1,500 @@
|
||||
.\" Title: talloc
|
||||
.\" Author:
|
||||
.\" Generator: DocBook XSL Stylesheets v1.71.0 <http://docbook.sf.net/>
|
||||
.\" Date: 12/09/2006
|
||||
.\" Manual:
|
||||
.\" Source:
|
||||
.\"
|
||||
.TH "TALLOC" "3" "12/09/2006" "" ""
|
||||
.\" disable hyphenation
|
||||
.nh
|
||||
.\" disable justification (adjust text to left margin only)
|
||||
.ad l
|
||||
.SH "NAME"
|
||||
talloc \- hierarchical reference counted memory pool system with destructors
|
||||
.SH "SYNOPSIS"
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
#include <talloc/talloc.h>
|
||||
.fi
|
||||
.RE
|
||||
.SH "DESCRIPTION"
|
||||
.PP
|
||||
If you are used to talloc from Samba3 then please read this carefully, as talloc has changed a lot.
|
||||
.PP
|
||||
The new talloc is a hierarchical, reference counted memory pool system with destructors. Quite a mouthful really, but not too bad once you get used to it.
|
||||
.PP
|
||||
Perhaps the biggest change from Samba3 is that there is no distinction between a "talloc context" and a "talloc pointer". Any pointer returned from talloc() is itself a valid talloc context. This means you can do this:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
struct foo *X = talloc(mem_ctx, struct foo);
|
||||
X\->name = talloc_strdup(X, "foo");
|
||||
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
and the pointer
|
||||
X\->name
|
||||
would be a "child" of the talloc context
|
||||
X
|
||||
which is itself a child of
|
||||
mem_ctx. So if you do
|
||||
talloc_free(mem_ctx)
|
||||
then it is all destroyed, whereas if you do
|
||||
talloc_free(X)
|
||||
then just
|
||||
X
|
||||
and
|
||||
X\->name
|
||||
are destroyed, and if you do
|
||||
talloc_free(X\->name)
|
||||
then just the name element of
|
||||
X
|
||||
is destroyed.
|
||||
.PP
|
||||
If you think about this, then what this effectively gives you is an n\-ary tree, where you can free any part of the tree with talloc_free().
|
||||
.PP
|
||||
If you find this confusing, then I suggest you run the
|
||||
testsuite
|
||||
program to watch talloc in action. You may also like to add your own tests to
|
||||
testsuite.c
|
||||
to clarify how some particular situation is handled.
|
||||
.SH "TALLOC API"
|
||||
.PP
|
||||
The following is a complete guide to the talloc API. Read it all at least twice.
|
||||
.SS "(type *)talloc(const void *ctx, type);"
|
||||
.PP
|
||||
The talloc() macro is the core of the talloc library. It takes a memory
|
||||
\fIctx\fR
|
||||
and a
|
||||
\fItype\fR, and returns a pointer to a new area of memory of the given
|
||||
\fItype\fR.
|
||||
.PP
|
||||
The returned pointer is itself a talloc context, so you can use it as the
|
||||
\fIctx\fR
|
||||
argument to more calls to talloc() if you wish.
|
||||
.PP
|
||||
The returned pointer is a "child" of the supplied context. This means that if you talloc_free() the
|
||||
\fIctx\fR
|
||||
then the new child disappears as well. Alternatively you can free just the child.
|
||||
.PP
|
||||
The
|
||||
\fIctx\fR
|
||||
argument to talloc() can be NULL, in which case a new top level context is created.
|
||||
.SS "void *talloc_size(const void *ctx, size_t size);"
|
||||
.PP
|
||||
The function talloc_size() should be used when you don't have a convenient type to pass to talloc(). Unlike talloc(), it is not type safe (as it returns a void *), so you are on your own for type checking.
|
||||
.SS "(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);"
|
||||
.PP
|
||||
The talloc_ptrtype() macro should be used when you have a pointer and want to allocate memory to point at with this pointer. When compiling with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size() and talloc_get_name() will return the current location in the source file. and not the type.
|
||||
.SS "int talloc_free(void *ptr);"
|
||||
.PP
|
||||
The talloc_free() function frees a piece of talloc memory, and all its children. You can call talloc_free() on any pointer returned by talloc().
|
||||
.PP
|
||||
The return value of talloc_free() indicates success or failure, with 0 returned for success and \-1 for failure. The only possible failure condition is if
|
||||
\fIptr\fR
|
||||
had a destructor attached to it and the destructor returned \-1. See
|
||||
\(lqtalloc_set_destructor()\(rq
|
||||
for details on destructors.
|
||||
.PP
|
||||
If this pointer has an additional parent when talloc_free() is called then the memory is not actually released, but instead the most recently established parent is destroyed. See
|
||||
\(lqtalloc_reference()\(rq
|
||||
for details on establishing additional parents.
|
||||
.PP
|
||||
For more control on which parent is removed, see
|
||||
\(lqtalloc_unlink()\(rq.
|
||||
.PP
|
||||
talloc_free() operates recursively on its children.
|
||||
.SS "void *talloc_reference(const void *ctx, const void *ptr);"
|
||||
.PP
|
||||
The talloc_reference() function makes
|
||||
\fIctx\fR
|
||||
an additional parent of
|
||||
\fIptr\fR.
|
||||
.PP
|
||||
The return value of talloc_reference() is always the original pointer
|
||||
\fIptr\fR, unless talloc ran out of memory in creating the reference in which case it will return NULL (each additional reference consumes around 48 bytes of memory on intel x86 platforms).
|
||||
.PP
|
||||
If
|
||||
\fIptr\fR
|
||||
is NULL, then the function is a no\-op, and simply returns NULL.
|
||||
.PP
|
||||
After creating a reference you can free it in one of the following ways:
|
||||
.PP
|
||||
.TP 3n
|
||||
\(bu
|
||||
you can talloc_free() any parent of the original pointer. That will reduce the number of parents of this pointer by 1, and will cause this pointer to be freed if it runs out of parents.
|
||||
.TP 3n
|
||||
\(bu
|
||||
you can talloc_free() the pointer itself. That will destroy the most recently established parent to the pointer and leave the pointer as a child of its current parent.
|
||||
.sp
|
||||
.RE
|
||||
.PP
|
||||
For more control on which parent to remove, see
|
||||
\(lqtalloc_unlink()\(rq.
|
||||
.SS "int talloc_unlink(const void *ctx, const void *ptr);"
|
||||
.PP
|
||||
The talloc_unlink() function removes a specific parent from
|
||||
\fIptr\fR. The
|
||||
\fIctx\fR
|
||||
passed must either be a context used in talloc_reference() with this pointer, or must be a direct parent of ptr.
|
||||
.PP
|
||||
Note that if the parent has already been removed using talloc_free() then this function will fail and will return \-1. Likewise, if
|
||||
\fIptr\fR
|
||||
is NULL, then the function will make no modifications and return \-1.
|
||||
.PP
|
||||
Usually you can just use talloc_free() instead of talloc_unlink(), but sometimes it is useful to have the additional control on which parent is removed.
|
||||
.SS "void talloc_set_destructor(const void *ptr, int (*destructor)(void *));"
|
||||
.PP
|
||||
The function talloc_set_destructor() sets the
|
||||
\fIdestructor\fR
|
||||
for the pointer
|
||||
\fIptr\fR. A
|
||||
\fIdestructor\fR
|
||||
is a function that is called when the memory used by a pointer is about to be released. The destructor receives
|
||||
\fIptr\fR
|
||||
as an argument, and should return 0 for success and \-1 for failure.
|
||||
.PP
|
||||
The
|
||||
\fIdestructor\fR
|
||||
can do anything it wants to, including freeing other pieces of memory. A common use for destructors is to clean up operating system resources (such as open file descriptors) contained in the structure the destructor is placed on.
|
||||
.PP
|
||||
You can only place one destructor on a pointer. If you need more than one destructor then you can create a zero\-length child of the pointer and place an additional destructor on that.
|
||||
.PP
|
||||
To remove a destructor call talloc_set_destructor() with NULL for the destructor.
|
||||
.PP
|
||||
If your destructor attempts to talloc_free() the pointer that it is the destructor for then talloc_free() will return \-1 and the free will be ignored. This would be a pointless operation anyway, as the destructor is only called when the memory is just about to go away.
|
||||
.SS "int talloc_increase_ref_count(const void *\fIptr\fR);"
|
||||
.PP
|
||||
The talloc_increase_ref_count(\fIptr\fR) function is exactly equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_reference(NULL, ptr);
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
You can use either syntax, depending on which you think is clearer in your code.
|
||||
.PP
|
||||
It returns 0 on success and \-1 on failure.
|
||||
.SS "size_t talloc_reference_count(const void *\fIptr\fR);"
|
||||
.PP
|
||||
Return the number of references to the pointer.
|
||||
.SS "void talloc_set_name(const void *ptr, const char *fmt, ...);"
|
||||
.PP
|
||||
Each talloc pointer has a "name". The name is used principally for debugging purposes, although it is also possible to set and get the name on a pointer in as a way of "marking" pointers in your code.
|
||||
.PP
|
||||
The main use for names on pointer is for "talloc reports". See
|
||||
\(lqtalloc_report_depth_cb()\(rq,
|
||||
\(lqtalloc_report_depth_file()\(rq,
|
||||
\(lqtalloc_report()\(rq
|
||||
\(lqtalloc_report()\(rq
|
||||
and
|
||||
\(lqtalloc_report_full()\(rq
|
||||
for details. Also see
|
||||
\(lqtalloc_enable_leak_report()\(rq
|
||||
and
|
||||
\(lqtalloc_enable_leak_report_full()\(rq.
|
||||
.PP
|
||||
The talloc_set_name() function allocates memory as a child of the pointer. It is logically equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
Note that multiple calls to talloc_set_name() will allocate more memory without releasing the name. All of the memory is released when the ptr is freed using talloc_free().
|
||||
.SS "void talloc_set_name_const(const void *\fIptr\fR, const char *\fIname\fR);"
|
||||
.PP
|
||||
The function talloc_set_name_const() is just like talloc_set_name(), but it takes a string constant, and is much faster. It is extensively used by the "auto naming" macros, such as talloc_p().
|
||||
.PP
|
||||
This function does not allocate any memory. It just copies the supplied pointer into the internal representation of the talloc ptr. This means you must not pass a
|
||||
\fIname\fR
|
||||
pointer to memory that will disappear before
|
||||
\fIptr\fR
|
||||
is freed with talloc_free().
|
||||
.SS "void *talloc_named(const void *\fIctx\fR, size_t \fIsize\fR, const char *\fIfmt\fR, ...);"
|
||||
.PP
|
||||
The talloc_named() function creates a named talloc pointer. It is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
ptr = talloc_size(ctx, size);
|
||||
talloc_set_name(ptr, fmt, ....);
|
||||
.fi
|
||||
.RE
|
||||
.SS "void *talloc_named_const(const void *\fIctx\fR, size_t \fIsize\fR, const char *\fIname\fR);"
|
||||
.PP
|
||||
This is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
ptr = talloc_size(ctx, size);
|
||||
talloc_set_name_const(ptr, name);
|
||||
.fi
|
||||
.RE
|
||||
.SS "const char *talloc_get_name(const void *\fIptr\fR);"
|
||||
.PP
|
||||
This returns the current name for the given talloc pointer,
|
||||
\fIptr\fR. See
|
||||
\(lqtalloc_set_name()\(rq
|
||||
for details.
|
||||
.SS "void *talloc_init(const char *\fIfmt\fR, ...);"
|
||||
.PP
|
||||
This function creates a zero length named talloc context as a top level context. It is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_named(NULL, 0, fmt, ...);
|
||||
.fi
|
||||
.RE
|
||||
.SS "void *talloc_new(void *\fIctx\fR);"
|
||||
.PP
|
||||
This is a utility macro that creates a new memory context hanging off an exiting context, automatically naming it "talloc_new: __location__" where __location__ is the source line it is called from. It is particularly useful for creating a new temporary working context.
|
||||
.SS "(\fItype\fR *)talloc_realloc(const void *\fIctx\fR, void *\fIptr\fR, \fItype\fR, \fIcount\fR);"
|
||||
.PP
|
||||
The talloc_realloc() macro changes the size of a talloc pointer. It has the following equivalences:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
|
||||
talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The
|
||||
\fIctx\fR
|
||||
argument is only used if
|
||||
\fIptr\fR
|
||||
is not NULL, otherwise it is ignored.
|
||||
.PP
|
||||
talloc_realloc() returns the new pointer, or NULL on failure. The call will fail either due to a lack of memory, or because the pointer has more than one parent (see
|
||||
\(lqtalloc_reference()\(rq).
|
||||
.SS "void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);"
|
||||
.PP
|
||||
the talloc_realloc_size() function is useful when the type is not known so the type\-safe talloc_realloc() cannot be used.
|
||||
.SS "TYPE *talloc_steal(const void *\fInew_ctx\fR, const TYPE *\fIptr\fR);"
|
||||
.PP
|
||||
The talloc_steal() function changes the parent context of a talloc pointer. It is typically used when the context that the pointer is currently a child of is going to be freed and you wish to keep the memory for a longer time.
|
||||
.PP
|
||||
The talloc_steal() function returns the pointer that you pass it. It does not have any failure modes.
|
||||
.PP
|
||||
NOTE: It is possible to produce loops in the parent/child relationship if you are not careful with talloc_steal(). No guarantees are provided as to your sanity or the safety of your data if you do this.
|
||||
.SS "TYPE *talloc_move(const void *\fInew_ctx\fR, TYPE **\fIptr\fR);"
|
||||
.PP
|
||||
The talloc_move() function is a wrapper around talloc_steal() which zeros the source pointer after the move. This avoids a potential source of bugs where a programmer leaves a pointer in two structures, and uses the pointer from the old structure after it has been moved to a new one.
|
||||
.SS "size_t talloc_total_size(const void *\fIptr\fR);"
|
||||
.PP
|
||||
The talloc_total_size() function returns the total size in bytes used by this pointer and all child pointers. Mostly useful for debugging.
|
||||
.PP
|
||||
Passing NULL is allowed, but it will only give a meaningful result if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called.
|
||||
.SS "size_t talloc_total_blocks(const void *\fIptr\fR);"
|
||||
.PP
|
||||
The talloc_total_blocks() function returns the total memory block count used by this pointer and all child pointers. Mostly useful for debugging.
|
||||
.PP
|
||||
Passing NULL is allowed, but it will only give a meaningful result if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called.
|
||||
.SS "void talloc_report(const void *ptr, FILE *f);"
|
||||
.PP
|
||||
The talloc_report() function prints a summary report of all memory used by
|
||||
\fIptr\fR. One line of report is printed for each immediate child of ptr, showing the total memory and number of blocks used by that child.
|
||||
.PP
|
||||
You can pass NULL for the pointer, in which case a report is printed for the top level memory context, but only if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called.
|
||||
.SS "void talloc_report_full(const void *\fIptr\fR, FILE *\fIf\fR);"
|
||||
.PP
|
||||
This provides a more detailed report than talloc_report(). It will recursively print the entire tree of memory referenced by the pointer. References in the tree are shown by giving the name of the pointer that is referenced.
|
||||
.PP
|
||||
You can pass NULL for the pointer, in which case a report is printed for the top level memory context, but only if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called.
|
||||
.SS ""
|
||||
.HP 28
|
||||
.BI "void talloc_report_depth_cb(" "const\ void\ *ptr" ", " "int\ depth" ", " "int\ max_depth" ", " "void\ (*callback)(const\ void\ *ptr,\ int\ depth,\ int\ max_depth,\ int\ is_ref,\ void\ *priv)" ", " "void\ *priv" ");"
|
||||
.PP
|
||||
This provides a more flexible reports than talloc_report(). It will recursively call the callback for the entire tree of memory referenced by the pointer. References in the tree are passed with
|
||||
\fIis_ref = 1\fR
|
||||
and the pointer that is referenced.
|
||||
.PP
|
||||
You can pass NULL for the pointer, in which case a report is printed for the top level memory context, but only if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called.
|
||||
.PP
|
||||
The recursion is stopped when depth >= max_depth. max_depth = \-1 means only stop at leaf nodes.
|
||||
.SS ""
|
||||
.HP 30
|
||||
.BI "void talloc_report_depth_file(" "const\ void\ *ptr" ", " "int\ depth" ", " "int\ max_depth" ", " "FILE\ *f" ");"
|
||||
.PP
|
||||
This provides a more flexible reports than talloc_report(). It will let you specify the depth and max_depth.
|
||||
.SS "void talloc_enable_leak_report(void);"
|
||||
.PP
|
||||
This enables calling of talloc_report(NULL, stderr) when the program exits. In Samba4 this is enabled by using the \-\-leak\-report command line option.
|
||||
.PP
|
||||
For it to be useful, this function must be called before any other talloc function as it establishes a "null context" that acts as the top of the tree. If you don't call this function first then passing NULL to talloc_report() or talloc_report_full() won't give you the full tree printout.
|
||||
.PP
|
||||
Here is a typical talloc report:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc report on 'null_context' (total 267 bytes in 15 blocks)
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(UTF8,CP850) contains 42 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(CP850,UTF8) contains 42 bytes in 2 blocks
|
||||
iconv(UTF8,UTF\-16LE) contains 45 bytes in 2 blocks
|
||||
iconv(UTF\-16LE,UTF8) contains 45 bytes in 2 blocks
|
||||
|
||||
.fi
|
||||
.RE
|
||||
.SS "void talloc_enable_leak_report_full(void);"
|
||||
.PP
|
||||
This enables calling of talloc_report_full(NULL, stderr) when the program exits. In Samba4 this is enabled by using the \-\-leak\-report\-full command line option.
|
||||
.PP
|
||||
For it to be useful, this function must be called before any other talloc function as it establishes a "null context" that acts as the top of the tree. If you don't call this function first then passing NULL to talloc_report() or talloc_report_full() won't give you the full tree printout.
|
||||
.PP
|
||||
Here is a typical full report:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
full talloc report on 'root' (total 18 bytes in 8 blocks)
|
||||
p1 contains 18 bytes in 7 blocks (ref 0)
|
||||
r1 contains 13 bytes in 2 blocks (ref 0)
|
||||
reference to: p2
|
||||
p2 contains 1 bytes in 1 blocks (ref 1)
|
||||
x3 contains 1 bytes in 1 blocks (ref 0)
|
||||
x2 contains 1 bytes in 1 blocks (ref 0)
|
||||
x1 contains 1 bytes in 1 blocks (ref 0)
|
||||
|
||||
.fi
|
||||
.RE
|
||||
.SS "(\fItype\fR *)talloc_zero(const void *\fIctx\fR, \fItype\fR);"
|
||||
.PP
|
||||
The talloc_zero() macro is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
ptr = talloc(ctx, type);
|
||||
if (ptr) memset(ptr, 0, sizeof(type));
|
||||
.fi
|
||||
.RE
|
||||
.SS "void *talloc_zero_size(const void *\fIctx\fR, size_t \fIsize\fR)"
|
||||
.PP
|
||||
The talloc_zero_size() function is useful when you don't have a known type.
|
||||
.SS "void *talloc_memdup(const void *\fIctx\fR, const void *\fIp\fR, size_t size);"
|
||||
.PP
|
||||
The talloc_memdup() function is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
ptr = talloc_size(ctx, size);
|
||||
if (ptr) memcpy(ptr, p, size);
|
||||
.fi
|
||||
.RE
|
||||
.SS "char *talloc_strdup(const void *\fIctx\fR, const char *\fIp\fR);"
|
||||
.PP
|
||||
The talloc_strdup() function is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
ptr = talloc_size(ctx, strlen(p)+1);
|
||||
if (ptr) memcpy(ptr, p, strlen(p)+1);
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
This function sets the name of the new pointer to the passed string. This is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
.fi
|
||||
.RE
|
||||
.SS "char *talloc_strndup(const void *\fIt\fR, const char *\fIp\fR, size_t \fIn\fR);"
|
||||
.PP
|
||||
The talloc_strndup() function is the talloc equivalent of the C library function strndup(3).
|
||||
.PP
|
||||
This function sets the name of the new pointer to the passed string. This is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
.fi
|
||||
.RE
|
||||
.SS "char *talloc_vasprintf(const void *\fIt\fR, const char *\fIfmt\fR, va_list \fIap\fR);"
|
||||
.PP
|
||||
The talloc_vasprintf() function is the talloc equivalent of the C library function vasprintf(3).
|
||||
.SS "char *talloc_asprintf(const void *\fIt\fR, const char *\fIfmt\fR, ...);"
|
||||
.PP
|
||||
The talloc_asprintf() function is the talloc equivalent of the C library function asprintf(3).
|
||||
.PP
|
||||
This function sets the name of the new pointer to the passed string. This is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
.fi
|
||||
.RE
|
||||
.SS "char *talloc_asprintf_append(char *s, const char *fmt, ...);"
|
||||
.PP
|
||||
The talloc_asprintf_append() function appends the given formatted string to the given string.
|
||||
.SS "(type *)talloc_array(const void *ctx, type, uint_t count);"
|
||||
.PP
|
||||
The talloc_array() macro is equivalent to:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
(type *)talloc_size(ctx, sizeof(type) * count);
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
except that it provides integer overflow protection for the multiply, returning NULL if the multiply overflows.
|
||||
.SS "void *talloc_array_size(const void *ctx, size_t size, uint_t count);"
|
||||
.PP
|
||||
The talloc_array_size() function is useful when the type is not known. It operates in the same way as talloc_array(), but takes a size instead of a type.
|
||||
.SS "(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);"
|
||||
.PP
|
||||
The talloc_ptrtype() macro should be used when you have a pointer to an array and want to allocate memory of an array to point at with this pointer. When compiling with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size() and talloc_get_name() will return the current location in the source file. and not the type.
|
||||
.SS "void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)"
|
||||
.PP
|
||||
This is a non\-macro version of talloc_realloc(), which is useful as libraries sometimes want a realloc function pointer. A realloc(3) implementation encapsulates the functionality of malloc(3), free(3) and realloc(3) in one call, which is why it is useful to be able to pass around a single function pointer.
|
||||
.SS "void *talloc_autofree_context(void);"
|
||||
.PP
|
||||
This is a handy utility function that returns a talloc context which will be automatically freed on program exit. This can be used to reduce the noise in memory leak reports.
|
||||
.SS "void *talloc_check_name(const void *ptr, const char *name);"
|
||||
.PP
|
||||
This function checks if a pointer has the specified
|
||||
\fIname\fR. If it does then the pointer is returned. It it doesn't then NULL is returned.
|
||||
.SS "(type *)talloc_get_type(const void *ptr, type);"
|
||||
.PP
|
||||
This macro allows you to do type checking on talloc pointers. It is particularly useful for void* private pointers. It is equivalent to this:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
(type *)talloc_check_name(ptr, #type)
|
||||
.fi
|
||||
.RE
|
||||
.SS "talloc_set_type(const void *ptr, type);"
|
||||
.PP
|
||||
This macro allows you to force the name of a pointer to be a particular
|
||||
\fItype\fR. This can be used in conjunction with talloc_get_type() to do type checking on void* pointers.
|
||||
.PP
|
||||
It is equivalent to this:
|
||||
.sp
|
||||
.RS 3n
|
||||
.nf
|
||||
talloc_set_name_const(ptr, #type)
|
||||
.fi
|
||||
.RE
|
||||
.SH "PERFORMANCE"
|
||||
.PP
|
||||
All the additional features of talloc(3) over malloc(3) do come at a price. We have a simple performance test in Samba4 that measures talloc() versus malloc() performance, and it seems that talloc() is about 10% slower than malloc() on my x86 Debian Linux box. For Samba, the great reduction in code complexity that we get by using talloc makes this worthwhile, especially as the total overhead of talloc/malloc in Samba is already quite small.
|
||||
.SH "SEE ALSO"
|
||||
.PP
|
||||
malloc(3), strndup(3), vasprintf(3), asprintf(3),
|
||||
\fI\%http://talloc.samba.org/\fR
|
||||
.SH "COPYRIGHT/LICENSE"
|
||||
.PP
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
.PP
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
.PP
|
||||
This program 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 General Public License for more details.
|
||||
.PP
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
433
ctdb/lib/talloc/talloc.3.html
Normal file
433
ctdb/lib/talloc/talloc.3.html
Normal file
@ -0,0 +1,433 @@
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>talloc</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.0"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="id2478266"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>talloc — hierarchical reference counted memory pool system with destructors</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <talloc/talloc.h></pre></div><div class="refsect1" lang="en"><a name="id2517036"></a><h2>DESCRIPTION</h2><p>
|
||||
If you are used to talloc from Samba3 then please read this
|
||||
carefully, as talloc has changed a lot.
|
||||
</p><p>
|
||||
The new talloc is a hierarchical, reference counted memory pool
|
||||
system with destructors. Quite a mouthful really, but not too bad
|
||||
once you get used to it.
|
||||
</p><p>
|
||||
Perhaps the biggest change from Samba3 is that there is no
|
||||
distinction between a "talloc context" and a "talloc pointer". Any
|
||||
pointer returned from talloc() is itself a valid talloc context.
|
||||
This means you can do this:
|
||||
</p><pre class="programlisting">
|
||||
struct foo *X = talloc(mem_ctx, struct foo);
|
||||
X->name = talloc_strdup(X, "foo");
|
||||
</pre><p>
|
||||
and the pointer <code class="literal">X->name</code>
|
||||
would be a "child" of the talloc context <code class="literal">X</code> which is itself a child of
|
||||
<code class="literal">mem_ctx</code>. So if you do
|
||||
<code class="literal">talloc_free(mem_ctx)</code> then
|
||||
it is all destroyed, whereas if you do <code class="literal">talloc_free(X)</code> then just <code class="literal">X</code> and <code class="literal">X->name</code> are destroyed, and if
|
||||
you do <code class="literal">talloc_free(X->name)</code> then just
|
||||
the name element of <code class="literal">X</code> is
|
||||
destroyed.
|
||||
</p><p>
|
||||
If you think about this, then what this effectively gives you is an
|
||||
n-ary tree, where you can free any part of the tree with
|
||||
talloc_free().
|
||||
</p><p>
|
||||
If you find this confusing, then I suggest you run the <code class="literal">testsuite</code> program to watch talloc
|
||||
in action. You may also like to add your own tests to <code class="literal">testsuite.c</code> to clarify how some
|
||||
particular situation is handled.
|
||||
</p></div><div class="refsect1" lang="en"><a name="id2478366"></a><h2>TALLOC API</h2><p>
|
||||
The following is a complete guide to the talloc API. Read it all at
|
||||
least twice.
|
||||
</p><div class="refsect2" lang="en"><a name="id2478375"></a><h3>(type *)talloc(const void *ctx, type);</h3><p>
|
||||
The talloc() macro is the core of the talloc library. It takes a
|
||||
memory <span class="italic">ctx</span> and a <span class="italic">type</span>, and returns a pointer to a new
|
||||
area of memory of the given <span class="italic">type</span>.
|
||||
</p><p>
|
||||
The returned pointer is itself a talloc context, so you can use
|
||||
it as the <span class="italic">ctx</span> argument to more
|
||||
calls to talloc() if you wish.
|
||||
</p><p>
|
||||
The returned pointer is a "child" of the supplied context. This
|
||||
means that if you talloc_free() the <span class="italic">ctx</span> then the new child disappears as
|
||||
well. Alternatively you can free just the child.
|
||||
</p><p>
|
||||
The <span class="italic">ctx</span> argument to talloc()
|
||||
can be NULL, in which case a new top level context is created.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2478439"></a><h3>void *talloc_size(const void *ctx, size_t size);</h3><p>
|
||||
The function talloc_size() should be used when you don't have a
|
||||
convenient type to pass to talloc(). Unlike talloc(), it is not
|
||||
type safe (as it returns a void *), so you are on your own for
|
||||
type checking.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2478452"></a><h3>(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);</h3><p>
|
||||
The talloc_ptrtype() macro should be used when you have a pointer and
|
||||
want to allocate memory to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2478467"></a><h3>int talloc_free(void *ptr);</h3><p>
|
||||
The talloc_free() function frees a piece of talloc memory, and
|
||||
all its children. You can call talloc_free() on any pointer
|
||||
returned by talloc().
|
||||
</p><p>
|
||||
The return value of talloc_free() indicates success or failure,
|
||||
with 0 returned for success and -1 for failure. The only
|
||||
possible failure condition is if <span class="italic">ptr</span> had a destructor attached to it and
|
||||
the destructor returned -1. See <a href="#talloc_set_destructor" title="void talloc_set_destructor(const void *ptr, int (*destructor)(void *));">“<span class="quote">talloc_set_destructor()</span>”</a>
|
||||
for details on destructors.
|
||||
</p><p>
|
||||
If this pointer has an additional parent when talloc_free() is
|
||||
called then the memory is not actually released, but instead the
|
||||
most recently established parent is destroyed. See <a href="#talloc_reference" title="void *talloc_reference(const void *ctx, const void *ptr);">“<span class="quote">talloc_reference()</span>”</a>
|
||||
for details on establishing additional parents.
|
||||
</p><p>
|
||||
For more control on which parent is removed, see <a href="#talloc_unlink" title="int talloc_unlink(const void *ctx, const void *ptr);">“<span class="quote">talloc_unlink()</span>”</a>.
|
||||
</p><p>
|
||||
talloc_free() operates recursively on its children.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_reference"></a><h3>void *talloc_reference(const void *ctx, const void *ptr);</h3><p>
|
||||
The talloc_reference() function makes <span class="italic">ctx</span> an additional parent of <span class="italic">ptr</span>.
|
||||
</p><p>
|
||||
The return value of talloc_reference() is always the original
|
||||
pointer <span class="italic">ptr</span>, unless talloc ran
|
||||
out of memory in creating the reference in which case it will
|
||||
return NULL (each additional reference consumes around 48 bytes
|
||||
of memory on intel x86 platforms).
|
||||
</p><p>
|
||||
If <span class="italic">ptr</span> is NULL, then the
|
||||
function is a no-op, and simply returns NULL.
|
||||
</p><p>
|
||||
After creating a reference you can free it in one of the
|
||||
following ways:
|
||||
</p><p>
|
||||
</p><div class="itemizedlist"><ul type="disc"><li><p>
|
||||
you can talloc_free() any parent of the original pointer.
|
||||
That will reduce the number of parents of this pointer by 1,
|
||||
and will cause this pointer to be freed if it runs out of
|
||||
parents.
|
||||
</p></li><li><p>
|
||||
you can talloc_free() the pointer itself. That will destroy
|
||||
the most recently established parent to the pointer and leave
|
||||
the pointer as a child of its current parent.
|
||||
</p></li></ul></div><p>
|
||||
</p><p>
|
||||
For more control on which parent to remove, see <a href="#talloc_unlink" title="int talloc_unlink(const void *ctx, const void *ptr);">“<span class="quote">talloc_unlink()</span>”</a>.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_unlink"></a><h3>int talloc_unlink(const void *ctx, const void *ptr);</h3><p>
|
||||
The talloc_unlink() function removes a specific parent from
|
||||
<span class="italic">ptr</span>. The <span class="italic">ctx</span> passed must either be a context used
|
||||
in talloc_reference() with this pointer, or must be a direct
|
||||
parent of ptr.
|
||||
</p><p>
|
||||
Note that if the parent has already been removed using
|
||||
talloc_free() then this function will fail and will return -1.
|
||||
Likewise, if <span class="italic">ptr</span> is NULL, then
|
||||
the function will make no modifications and return -1.
|
||||
</p><p>
|
||||
Usually you can just use talloc_free() instead of
|
||||
talloc_unlink(), but sometimes it is useful to have the
|
||||
additional control on which parent is removed.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_set_destructor"></a><h3>void talloc_set_destructor(const void *ptr, int (*destructor)(void *));</h3><p>
|
||||
The function talloc_set_destructor() sets the <span class="italic">destructor</span> for the pointer <span class="italic">ptr</span>. A <span class="italic">destructor</span> is a function that is called
|
||||
when the memory used by a pointer is about to be released. The
|
||||
destructor receives <span class="italic">ptr</span> as an
|
||||
argument, and should return 0 for success and -1 for failure.
|
||||
</p><p>
|
||||
The <span class="italic">destructor</span> can do anything
|
||||
it wants to, including freeing other pieces of memory. A common
|
||||
use for destructors is to clean up operating system resources
|
||||
(such as open file descriptors) contained in the structure the
|
||||
destructor is placed on.
|
||||
</p><p>
|
||||
You can only place one destructor on a pointer. If you need more
|
||||
than one destructor then you can create a zero-length child of
|
||||
the pointer and place an additional destructor on that.
|
||||
</p><p>
|
||||
To remove a destructor call talloc_set_destructor() with NULL for
|
||||
the destructor.
|
||||
</p><p>
|
||||
If your destructor attempts to talloc_free() the pointer that it
|
||||
is the destructor for then talloc_free() will return -1 and the
|
||||
free will be ignored. This would be a pointless operation
|
||||
anyway, as the destructor is only called when the memory is just
|
||||
about to go away.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2479422"></a><h3>int talloc_increase_ref_count(const void *<span class="italic">ptr</span>);</h3><p>
|
||||
The talloc_increase_ref_count(<span class="italic">ptr</span>) function is exactly equivalent to:
|
||||
</p><pre class="programlisting">talloc_reference(NULL, ptr);</pre><p>
|
||||
You can use either syntax, depending on which you think is
|
||||
clearer in your code.
|
||||
</p><p>
|
||||
It returns 0 on success and -1 on failure.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2479459"></a><h3>size_t talloc_reference_count(const void *<span class="italic">ptr</span>);</h3><p>
|
||||
Return the number of references to the pointer.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_set_name"></a><h3>void talloc_set_name(const void *ptr, const char *fmt, ...);</h3><p>
|
||||
Each talloc pointer has a "name". The name is used principally
|
||||
for debugging purposes, although it is also possible to set and
|
||||
get the name on a pointer in as a way of "marking" pointers in
|
||||
your code.
|
||||
</p><p>
|
||||
The main use for names on pointer is for "talloc reports". See
|
||||
<a href="#talloc_report" title="void talloc_report(const void *ptr, FILE *f);">“<span class="quote">talloc_report_depth_cb()</span>”</a>,
|
||||
<a href="#talloc_report" title="void talloc_report(const void *ptr, FILE *f);">“<span class="quote">talloc_report_depth_file()</span>”</a>,
|
||||
<a href="#talloc_report" title="void talloc_report(const void *ptr, FILE *f);">“<span class="quote">talloc_report()</span>”</a>
|
||||
<a href="#talloc_report" title="void talloc_report(const void *ptr, FILE *f);">“<span class="quote">talloc_report()</span>”</a>
|
||||
and <a href="#talloc_report_full" title="void talloc_report_full(const void *ptr, FILE *f);">“<span class="quote">talloc_report_full()</span>”</a>
|
||||
for details. Also see <a href="#talloc_enable_leak_report" title="void talloc_enable_leak_report(void);">“<span class="quote">talloc_enable_leak_report()</span>”</a>
|
||||
and <a href="#talloc_enable_leak_report_full" title="void talloc_enable_leak_report_full(void);">“<span class="quote">talloc_enable_leak_report_full()</span>”</a>.
|
||||
</p><p>
|
||||
The talloc_set_name() function allocates memory as a child of the
|
||||
pointer. It is logically equivalent to:
|
||||
</p><pre class="programlisting">talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));</pre><p>
|
||||
Note that multiple calls to talloc_set_name() will allocate more
|
||||
memory without releasing the name. All of the memory is released
|
||||
when the ptr is freed using talloc_free().
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2479578"></a><h3>void talloc_set_name_const(const void *<span class="italic">ptr</span>, const char *<span class="italic">name</span>);</h3><p>
|
||||
The function talloc_set_name_const() is just like
|
||||
talloc_set_name(), but it takes a string constant, and is much
|
||||
faster. It is extensively used by the "auto naming" macros, such
|
||||
as talloc_p().
|
||||
</p><p>
|
||||
This function does not allocate any memory. It just copies the
|
||||
supplied pointer into the internal representation of the talloc
|
||||
ptr. This means you must not pass a <span class="italic">name</span> pointer to memory that will
|
||||
disappear before <span class="italic">ptr</span> is freed
|
||||
with talloc_free().
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2479622"></a><h3>void *talloc_named(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">fmt</span>, ...);</h3><p>
|
||||
The talloc_named() function creates a named talloc pointer. It
|
||||
is equivalent to:
|
||||
</p><pre class="programlisting">ptr = talloc_size(ctx, size);
|
||||
talloc_set_name(ptr, fmt, ....);</pre></div><div class="refsect2" lang="en"><a name="id2479657"></a><h3>void *talloc_named_const(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">name</span>);</h3><p>
|
||||
This is equivalent to:
|
||||
</p><pre class="programlisting">ptr = talloc_size(ctx, size);
|
||||
talloc_set_name_const(ptr, name);</pre></div><div class="refsect2" lang="en"><a name="id2479692"></a><h3>const char *talloc_get_name(const void *<span class="italic">ptr</span>);</h3><p>
|
||||
This returns the current name for the given talloc pointer,
|
||||
<span class="italic">ptr</span>. See <a href="#talloc_set_name" title="void talloc_set_name(const void *ptr, const char *fmt, ...);">“<span class="quote">talloc_set_name()</span>”</a>
|
||||
for details.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2479723"></a><h3>void *talloc_init(const char *<span class="italic">fmt</span>, ...);</h3><p>
|
||||
This function creates a zero length named talloc context as a top
|
||||
level context. It is equivalent to:
|
||||
</p><pre class="programlisting">talloc_named(NULL, 0, fmt, ...);</pre></div><div class="refsect2" lang="en"><a name="id2479746"></a><h3>void *talloc_new(void *<span class="italic">ctx</span>);</h3><p>
|
||||
This is a utility macro that creates a new memory context hanging
|
||||
off an exiting context, automatically naming it "talloc_new:
|
||||
__location__" where __location__ is the source line it is called
|
||||
from. It is particularly useful for creating a new temporary
|
||||
working context.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526437"></a><h3>(<span class="italic">type</span> *)talloc_realloc(const void *<span class="italic">ctx</span>, void *<span class="italic">ptr</span>, <span class="italic">type</span>, <span class="italic">count</span>);</h3><p>
|
||||
The talloc_realloc() macro changes the size of a talloc pointer.
|
||||
It has the following equivalences:
|
||||
</p><pre class="programlisting">talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
|
||||
talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</pre><p>
|
||||
The <span class="italic">ctx</span> argument is only used
|
||||
if <span class="italic">ptr</span> is not NULL, otherwise
|
||||
it is ignored.
|
||||
</p><p>
|
||||
talloc_realloc() returns the new pointer, or NULL on failure.
|
||||
The call will fail either due to a lack of memory, or because the
|
||||
pointer has more than one parent (see <a href="#talloc_reference" title="void *talloc_reference(const void *ctx, const void *ptr);">“<span class="quote">talloc_reference()</span>”</a>).
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526515"></a><h3>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</h3><p>
|
||||
the talloc_realloc_size() function is useful when the type is not
|
||||
known so the type-safe talloc_realloc() cannot be used.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526527"></a><h3>TYPE *talloc_steal(const void *<span class="italic">new_ctx</span>, const TYPE *<span class="italic">ptr</span>);</h3><p>
|
||||
The talloc_steal() function changes the parent context of a
|
||||
talloc pointer. It is typically used when the context that the
|
||||
pointer is currently a child of is going to be freed and you wish
|
||||
to keep the memory for a longer time.
|
||||
</p><p>
|
||||
The talloc_steal() function returns the pointer that you pass it.
|
||||
It does not have any failure modes.
|
||||
</p><p>
|
||||
NOTE: It is possible to produce loops in the parent/child
|
||||
relationship if you are not careful with talloc_steal(). No
|
||||
guarantees are provided as to your sanity or the safety of your
|
||||
data if you do this.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526564"></a><h3>TYPE *talloc_move(const void *<span class="italic">new_ctx</span>, TYPE **<span class="italic">ptr</span>);</h3><p>
|
||||
The talloc_move() function is a wrapper around
|
||||
talloc_steal() which zeros the source pointer after the
|
||||
move. This avoids a potential source of bugs where a
|
||||
programmer leaves a pointer in two structures, and uses the
|
||||
pointer from the old structure after it has been moved to a
|
||||
new one.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526590"></a><h3>size_t talloc_total_size(const void *<span class="italic">ptr</span>);</h3><p>
|
||||
The talloc_total_size() function returns the total size in bytes
|
||||
used by this pointer and all child pointers. Mostly useful for
|
||||
debugging.
|
||||
</p><p>
|
||||
Passing NULL is allowed, but it will only give a meaningful
|
||||
result if talloc_enable_leak_report() or
|
||||
talloc_enable_leak_report_full() has been called.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526614"></a><h3>size_t talloc_total_blocks(const void *<span class="italic">ptr</span>);</h3><p>
|
||||
The talloc_total_blocks() function returns the total memory block
|
||||
count used by this pointer and all child pointers. Mostly useful
|
||||
for debugging.
|
||||
</p><p>
|
||||
Passing NULL is allowed, but it will only give a meaningful
|
||||
result if talloc_enable_leak_report() or
|
||||
talloc_enable_leak_report_full() has been called.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_report"></a><h3>void talloc_report(const void *ptr, FILE *f);</h3><p>
|
||||
The talloc_report() function prints a summary report of all
|
||||
memory used by <span class="italic">ptr</span>. One line
|
||||
of report is printed for each immediate child of ptr, showing the
|
||||
total memory and number of blocks used by that child.
|
||||
</p><p>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_report_full"></a><h3>void talloc_report_full(const void *<span class="italic">ptr</span>, FILE *<span class="italic">f</span>);</h3><p>
|
||||
This provides a more detailed report than talloc_report(). It
|
||||
will recursively print the entire tree of memory referenced by
|
||||
the pointer. References in the tree are shown by giving the name
|
||||
of the pointer that is referenced.
|
||||
</p><p>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_report_depth_cb"></a><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">void <b class="fsfunc">talloc_report_depth_cb</b>(</code></td><td><var class="pdparam">const void *ptr</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">int depth</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">int max_depth</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">void (*callback)(const void *ptr, int depth, int max_depth, int is_ref, void *priv)</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">void *priv</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code></code> </td><td><code><var class="pdparam">const void *ptr</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">int depth</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">int max_depth</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">void (*callback)(const void *ptr, int depth, int max_depth, int is_ref, void *priv)</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">void *priv</var>;</code></td></tr></table></div><p>
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will recursively call the callback for the entire tree of memory
|
||||
referenced by the pointer. References in the tree are passed with
|
||||
<span class="italic">is_ref = 1</span> and the pointer that is referenced.
|
||||
</p><p>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</p><p>
|
||||
The recursion is stopped when depth >= max_depth.
|
||||
max_depth = -1 means only stop at leaf nodes.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_report_depth_file"></a><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr><td><code class="funcdef">void <b class="fsfunc">talloc_report_depth_file</b>(</code></td><td><var class="pdparam">const void *ptr</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">int depth</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">int max_depth</var>, </td><td> </td></tr><tr><td> </td><td><var class="pdparam">FILE *f</var><code>)</code>;</td><td> </td></tr></table><table border="0" summary="Function argument synopsis" cellspacing="0" cellpadding="0"><tr><td><code></code> </td><td><code><var class="pdparam">const void *ptr</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">int depth</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">int max_depth</var>;</code></td></tr><tr><td><code></code> </td><td><code><var class="pdparam">FILE *f</var>;</code></td></tr></table></div><p>
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will let you specify the depth and max_depth.
|
||||
</p></div><div class="refsect2" lang="en"><a name="talloc_enable_leak_report"></a><h3>void talloc_enable_leak_report(void);</h3><p>
|
||||
This enables calling of talloc_report(NULL, stderr) when the
|
||||
program exits. In Samba4 this is enabled by using the
|
||||
--leak-report command line option.
|
||||
</p><p>
|
||||
For it to be useful, this function must be called before any
|
||||
other talloc function as it establishes a "null context" that
|
||||
acts as the top of the tree. If you don't call this function
|
||||
first then passing NULL to talloc_report() or
|
||||
talloc_report_full() won't give you the full tree printout.
|
||||
</p><p>
|
||||
Here is a typical talloc report:
|
||||
</p><pre class="screen">talloc report on 'null_context' (total 267 bytes in 15 blocks)
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(UTF8,CP850) contains 42 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(CP850,UTF8) contains 42 bytes in 2 blocks
|
||||
iconv(UTF8,UTF-16LE) contains 45 bytes in 2 blocks
|
||||
iconv(UTF-16LE,UTF8) contains 45 bytes in 2 blocks
|
||||
</pre></div><div class="refsect2" lang="en"><a name="talloc_enable_leak_report_full"></a><h3>void talloc_enable_leak_report_full(void);</h3><p>
|
||||
This enables calling of talloc_report_full(NULL, stderr) when the
|
||||
program exits. In Samba4 this is enabled by using the
|
||||
--leak-report-full command line option.
|
||||
</p><p>
|
||||
For it to be useful, this function must be called before any
|
||||
other talloc function as it establishes a "null context" that
|
||||
acts as the top of the tree. If you don't call this function
|
||||
first then passing NULL to talloc_report() or
|
||||
talloc_report_full() won't give you the full tree printout.
|
||||
</p><p>
|
||||
Here is a typical full report:
|
||||
</p><pre class="screen">full talloc report on 'root' (total 18 bytes in 8 blocks)
|
||||
p1 contains 18 bytes in 7 blocks (ref 0)
|
||||
r1 contains 13 bytes in 2 blocks (ref 0)
|
||||
reference to: p2
|
||||
p2 contains 1 bytes in 1 blocks (ref 1)
|
||||
x3 contains 1 bytes in 1 blocks (ref 0)
|
||||
x2 contains 1 bytes in 1 blocks (ref 0)
|
||||
x1 contains 1 bytes in 1 blocks (ref 0)
|
||||
</pre></div><div class="refsect2" lang="en"><a name="id2526922"></a><h3>(<span class="italic">type</span> *)talloc_zero(const void *<span class="italic">ctx</span>, <span class="italic">type</span>);</h3><p>
|
||||
The talloc_zero() macro is equivalent to:
|
||||
</p><pre class="programlisting">ptr = talloc(ctx, type);
|
||||
if (ptr) memset(ptr, 0, sizeof(type));</pre></div><div class="refsect2" lang="en"><a name="id2526956"></a><h3>void *talloc_zero_size(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>)</h3><p>
|
||||
The talloc_zero_size() function is useful when you don't have a
|
||||
known type.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2526977"></a><h3>void *talloc_memdup(const void *<span class="italic">ctx</span>, const void *<span class="italic">p</span>, size_t size);</h3><p>
|
||||
The talloc_memdup() function is equivalent to:
|
||||
</p><pre class="programlisting">ptr = talloc_size(ctx, size);
|
||||
if (ptr) memcpy(ptr, p, size);</pre></div><div class="refsect2" lang="en"><a name="id2527006"></a><h3>char *talloc_strdup(const void *<span class="italic">ctx</span>, const char *<span class="italic">p</span>);</h3><p>
|
||||
The talloc_strdup() function is equivalent to:
|
||||
</p><pre class="programlisting">ptr = talloc_size(ctx, strlen(p)+1);
|
||||
if (ptr) memcpy(ptr, p, strlen(p)+1);</pre><p>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527046"></a><h3>char *talloc_strndup(const void *<span class="italic">t</span>, const char *<span class="italic">p</span>, size_t <span class="italic">n</span>);</h3><p>
|
||||
The talloc_strndup() function is the talloc equivalent of the C
|
||||
library function strndup(3).
|
||||
</p><p>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527086"></a><h3>char *talloc_vasprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, va_list <span class="italic">ap</span>);</h3><p>
|
||||
The talloc_vasprintf() function is the talloc equivalent of the C
|
||||
library function vasprintf(3).
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527114"></a><h3>char *talloc_asprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, ...);</h3><p>
|
||||
The talloc_asprintf() function is the talloc equivalent of the C
|
||||
library function asprintf(3).
|
||||
</p><p>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527148"></a><h3>char *talloc_asprintf_append(char *s, const char *fmt, ...);</h3><p>
|
||||
The talloc_asprintf_append() function appends the given formatted
|
||||
string to the given string.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527160"></a><h3>(type *)talloc_array(const void *ctx, type, uint_t count);</h3><p>
|
||||
The talloc_array() macro is equivalent to:
|
||||
</p><pre class="programlisting">(type *)talloc_size(ctx, sizeof(type) * count);</pre><p>
|
||||
except that it provides integer overflow protection for the
|
||||
multiply, returning NULL if the multiply overflows.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527183"></a><h3>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</h3><p>
|
||||
The talloc_array_size() function is useful when the type is not
|
||||
known. It operates in the same way as talloc_array(), but takes a
|
||||
size instead of a type.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527196"></a><h3>(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);</h3><p>
|
||||
The talloc_ptrtype() macro should be used when you have a pointer to an array
|
||||
and want to allocate memory of an array to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527212"></a><h3>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</h3><p>
|
||||
This is a non-macro version of talloc_realloc(), which is useful
|
||||
as libraries sometimes want a realloc function pointer. A
|
||||
realloc(3) implementation encapsulates the functionality of
|
||||
malloc(3), free(3) and realloc(3) in one call, which is why it is
|
||||
useful to be able to pass around a single function pointer.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527227"></a><h3>void *talloc_autofree_context(void);</h3><p>
|
||||
This is a handy utility function that returns a talloc context
|
||||
which will be automatically freed on program exit. This can be
|
||||
used to reduce the noise in memory leak reports.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527240"></a><h3>void *talloc_check_name(const void *ptr, const char *name);</h3><p>
|
||||
This function checks if a pointer has the specified <span class="italic">name</span>. If it does then the pointer is
|
||||
returned. It it doesn't then NULL is returned.
|
||||
</p></div><div class="refsect2" lang="en"><a name="id2527258"></a><h3>(type *)talloc_get_type(const void *ptr, type);</h3><p>
|
||||
This macro allows you to do type checking on talloc pointers. It
|
||||
is particularly useful for void* private pointers. It is
|
||||
equivalent to this:
|
||||
</p><pre class="programlisting">(type *)talloc_check_name(ptr, #type)</pre></div><div class="refsect2" lang="en"><a name="id2527277"></a><h3>talloc_set_type(const void *ptr, type);</h3><p>
|
||||
This macro allows you to force the name of a pointer to be a
|
||||
particular <span class="emphasis"><em>type</em></span>. This can be
|
||||
used in conjunction with talloc_get_type() to do type checking on
|
||||
void* pointers.
|
||||
</p><p>
|
||||
It is equivalent to this:
|
||||
</p><pre class="programlisting">talloc_set_name_const(ptr, #type)</pre></div></div><div class="refsect1" lang="en"><a name="id2527304"></a><h2>PERFORMANCE</h2><p>
|
||||
All the additional features of talloc(3) over malloc(3) do come at a
|
||||
price. We have a simple performance test in Samba4 that measures
|
||||
talloc() versus malloc() performance, and it seems that talloc() is
|
||||
about 10% slower than malloc() on my x86 Debian Linux box. For
|
||||
Samba, the great reduction in code complexity that we get by using
|
||||
talloc makes this worthwhile, especially as the total overhead of
|
||||
talloc/malloc in Samba is already quite small.
|
||||
</p></div><div class="refsect1" lang="en"><a name="id2527322"></a><h2>SEE ALSO</h2><p>
|
||||
malloc(3), strndup(3), vasprintf(3), asprintf(3),
|
||||
<a href="http://talloc.samba.org/" target="_top">http://talloc.samba.org/</a>
|
||||
</p></div><div class="refsect1" lang="en"><a name="id2527336"></a><h2>COPYRIGHT/LICENSE</h2><p>
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
</p><p>
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or (at
|
||||
your option) any later version.
|
||||
</p><p>
|
||||
This program 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
|
||||
General Public License for more details.
|
||||
</p><p>
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</p></div></div></body></html>
|
718
ctdb/lib/talloc/talloc.3.xml
Normal file
718
ctdb/lib/talloc/talloc.3.xml
Normal file
@ -0,0 +1,718 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
||||
<refentry>
|
||||
<refmeta>
|
||||
<refentrytitle>talloc</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
<refnamediv>
|
||||
<refname>talloc</refname>
|
||||
<refpurpose>hierarchical reference counted memory pool system with destructors</refpurpose>
|
||||
</refnamediv>
|
||||
<refsynopsisdiv>
|
||||
<synopsis>#include <talloc/talloc.h></synopsis>
|
||||
</refsynopsisdiv>
|
||||
<refsect1><title>DESCRIPTION</title>
|
||||
<para>
|
||||
If you are used to talloc from Samba3 then please read this
|
||||
carefully, as talloc has changed a lot.
|
||||
</para>
|
||||
<para>
|
||||
The new talloc is a hierarchical, reference counted memory pool
|
||||
system with destructors. Quite a mouthful really, but not too bad
|
||||
once you get used to it.
|
||||
</para>
|
||||
<para>
|
||||
Perhaps the biggest change from Samba3 is that there is no
|
||||
distinction between a "talloc context" and a "talloc pointer". Any
|
||||
pointer returned from talloc() is itself a valid talloc context.
|
||||
This means you can do this:
|
||||
</para>
|
||||
<programlisting>
|
||||
struct foo *X = talloc(mem_ctx, struct foo);
|
||||
X->name = talloc_strdup(X, "foo");
|
||||
</programlisting>
|
||||
<para>
|
||||
and the pointer <literal role="code">X->name</literal>
|
||||
would be a "child" of the talloc context <literal
|
||||
role="code">X</literal> which is itself a child of
|
||||
<literal role="code">mem_ctx</literal>. So if you do
|
||||
<literal role="code">talloc_free(mem_ctx)</literal> then
|
||||
it is all destroyed, whereas if you do <literal
|
||||
role="code">talloc_free(X)</literal> then just <literal
|
||||
role="code">X</literal> and <literal
|
||||
role="code">X->name</literal> are destroyed, and if
|
||||
you do <literal
|
||||
role="code">talloc_free(X->name)</literal> then just
|
||||
the name element of <literal role="code">X</literal> is
|
||||
destroyed.
|
||||
</para>
|
||||
<para>
|
||||
If you think about this, then what this effectively gives you is an
|
||||
n-ary tree, where you can free any part of the tree with
|
||||
talloc_free().
|
||||
</para>
|
||||
<para>
|
||||
If you find this confusing, then I suggest you run the <literal
|
||||
role="code">testsuite</literal> program to watch talloc
|
||||
in action. You may also like to add your own tests to <literal
|
||||
role="code">testsuite.c</literal> to clarify how some
|
||||
particular situation is handled.
|
||||
</para>
|
||||
</refsect1>
|
||||
<refsect1><title>TALLOC API</title>
|
||||
<para>
|
||||
The following is a complete guide to the talloc API. Read it all at
|
||||
least twice.
|
||||
</para>
|
||||
<refsect2><title>(type *)talloc(const void *ctx, type);</title>
|
||||
<para>
|
||||
The talloc() macro is the core of the talloc library. It takes a
|
||||
memory <emphasis role="italic">ctx</emphasis> and a <emphasis
|
||||
role="italic">type</emphasis>, and returns a pointer to a new
|
||||
area of memory of the given <emphasis
|
||||
role="italic">type</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
The returned pointer is itself a talloc context, so you can use
|
||||
it as the <emphasis role="italic">ctx</emphasis> argument to more
|
||||
calls to talloc() if you wish.
|
||||
</para>
|
||||
<para>
|
||||
The returned pointer is a "child" of the supplied context. This
|
||||
means that if you talloc_free() the <emphasis
|
||||
role="italic">ctx</emphasis> then the new child disappears as
|
||||
well. Alternatively you can free just the child.
|
||||
</para>
|
||||
<para>
|
||||
The <emphasis role="italic">ctx</emphasis> argument to talloc()
|
||||
can be NULL, in which case a new top level context is created.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_size(const void *ctx, size_t size);</title>
|
||||
<para>
|
||||
The function talloc_size() should be used when you don't have a
|
||||
convenient type to pass to talloc(). Unlike talloc(), it is not
|
||||
type safe (as it returns a void *), so you are on your own for
|
||||
type checking.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);</title>
|
||||
<para>
|
||||
The talloc_ptrtype() macro should be used when you have a pointer and
|
||||
want to allocate memory to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>int talloc_free(void *ptr);</title>
|
||||
<para>
|
||||
The talloc_free() function frees a piece of talloc memory, and
|
||||
all its children. You can call talloc_free() on any pointer
|
||||
returned by talloc().
|
||||
</para>
|
||||
<para>
|
||||
The return value of talloc_free() indicates success or failure,
|
||||
with 0 returned for success and -1 for failure. The only
|
||||
possible failure condition is if <emphasis
|
||||
role="italic">ptr</emphasis> had a destructor attached to it and
|
||||
the destructor returned -1. See <link
|
||||
linkend="talloc_set_destructor"><quote>talloc_set_destructor()</quote></link>
|
||||
for details on destructors.
|
||||
</para>
|
||||
<para>
|
||||
If this pointer has an additional parent when talloc_free() is
|
||||
called then the memory is not actually released, but instead the
|
||||
most recently established parent is destroyed. See <link
|
||||
linkend="talloc_reference"><quote>talloc_reference()</quote></link>
|
||||
for details on establishing additional parents.
|
||||
</para>
|
||||
<para>
|
||||
For more control on which parent is removed, see <link
|
||||
linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
|
||||
</para>
|
||||
<para>
|
||||
talloc_free() operates recursively on its children.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_reference"><title>void *talloc_reference(const void *ctx, const void *ptr);</title>
|
||||
<para>
|
||||
The talloc_reference() function makes <emphasis
|
||||
role="italic">ctx</emphasis> an additional parent of <emphasis
|
||||
role="italic">ptr</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
The return value of talloc_reference() is always the original
|
||||
pointer <emphasis role="italic">ptr</emphasis>, unless talloc ran
|
||||
out of memory in creating the reference in which case it will
|
||||
return NULL (each additional reference consumes around 48 bytes
|
||||
of memory on intel x86 platforms).
|
||||
</para>
|
||||
<para>
|
||||
If <emphasis role="italic">ptr</emphasis> is NULL, then the
|
||||
function is a no-op, and simply returns NULL.
|
||||
</para>
|
||||
<para>
|
||||
After creating a reference you can free it in one of the
|
||||
following ways:
|
||||
</para>
|
||||
<para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
you can talloc_free() any parent of the original pointer.
|
||||
That will reduce the number of parents of this pointer by 1,
|
||||
and will cause this pointer to be freed if it runs out of
|
||||
parents.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
you can talloc_free() the pointer itself. That will destroy
|
||||
the most recently established parent to the pointer and leave
|
||||
the pointer as a child of its current parent.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
For more control on which parent to remove, see <link
|
||||
linkend="talloc_unlink"><quote>talloc_unlink()</quote></link>.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_unlink"><title>int talloc_unlink(const void *ctx, const void *ptr);</title>
|
||||
<para>
|
||||
The talloc_unlink() function removes a specific parent from
|
||||
<emphasis role="italic">ptr</emphasis>. The <emphasis
|
||||
role="italic">ctx</emphasis> passed must either be a context used
|
||||
in talloc_reference() with this pointer, or must be a direct
|
||||
parent of ptr.
|
||||
</para>
|
||||
<para>
|
||||
Note that if the parent has already been removed using
|
||||
talloc_free() then this function will fail and will return -1.
|
||||
Likewise, if <emphasis role="italic">ptr</emphasis> is NULL, then
|
||||
the function will make no modifications and return -1.
|
||||
</para>
|
||||
<para>
|
||||
Usually you can just use talloc_free() instead of
|
||||
talloc_unlink(), but sometimes it is useful to have the
|
||||
additional control on which parent is removed.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_set_destructor"><title>void talloc_set_destructor(const void *ptr, int (*destructor)(void *));</title>
|
||||
<para>
|
||||
The function talloc_set_destructor() sets the <emphasis
|
||||
role="italic">destructor</emphasis> for the pointer <emphasis
|
||||
role="italic">ptr</emphasis>. A <emphasis
|
||||
role="italic">destructor</emphasis> is a function that is called
|
||||
when the memory used by a pointer is about to be released. The
|
||||
destructor receives <emphasis role="italic">ptr</emphasis> as an
|
||||
argument, and should return 0 for success and -1 for failure.
|
||||
</para>
|
||||
<para>
|
||||
The <emphasis role="italic">destructor</emphasis> can do anything
|
||||
it wants to, including freeing other pieces of memory. A common
|
||||
use for destructors is to clean up operating system resources
|
||||
(such as open file descriptors) contained in the structure the
|
||||
destructor is placed on.
|
||||
</para>
|
||||
<para>
|
||||
You can only place one destructor on a pointer. If you need more
|
||||
than one destructor then you can create a zero-length child of
|
||||
the pointer and place an additional destructor on that.
|
||||
</para>
|
||||
<para>
|
||||
To remove a destructor call talloc_set_destructor() with NULL for
|
||||
the destructor.
|
||||
</para>
|
||||
<para>
|
||||
If your destructor attempts to talloc_free() the pointer that it
|
||||
is the destructor for then talloc_free() will return -1 and the
|
||||
free will be ignored. This would be a pointless operation
|
||||
anyway, as the destructor is only called when the memory is just
|
||||
about to go away.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>int talloc_increase_ref_count(const void *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_increase_ref_count(<emphasis
|
||||
role="italic">ptr</emphasis>) function is exactly equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_reference(NULL, ptr);</programlisting>
|
||||
<para>
|
||||
You can use either syntax, depending on which you think is
|
||||
clearer in your code.
|
||||
</para>
|
||||
<para>
|
||||
It returns 0 on success and -1 on failure.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>size_t talloc_reference_count(const void *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
Return the number of references to the pointer.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_set_name"><title>void talloc_set_name(const void *ptr, const char *fmt, ...);</title>
|
||||
<para>
|
||||
Each talloc pointer has a "name". The name is used principally
|
||||
for debugging purposes, although it is also possible to set and
|
||||
get the name on a pointer in as a way of "marking" pointers in
|
||||
your code.
|
||||
</para>
|
||||
<para>
|
||||
The main use for names on pointer is for "talloc reports". See
|
||||
<link
|
||||
linkend="talloc_report"><quote>talloc_report_depth_cb()</quote></link>,
|
||||
<link
|
||||
linkend="talloc_report"><quote>talloc_report_depth_file()</quote></link>,
|
||||
<link
|
||||
linkend="talloc_report"><quote>talloc_report()</quote></link>
|
||||
<link
|
||||
linkend="talloc_report"><quote>talloc_report()</quote></link>
|
||||
and <link
|
||||
linkend="talloc_report_full"><quote>talloc_report_full()</quote></link>
|
||||
for details. Also see <link
|
||||
linkend="talloc_enable_leak_report"><quote>talloc_enable_leak_report()</quote></link>
|
||||
and <link
|
||||
linkend="talloc_enable_leak_report_full"><quote>talloc_enable_leak_report_full()</quote></link>.
|
||||
</para>
|
||||
<para>
|
||||
The talloc_set_name() function allocates memory as a child of the
|
||||
pointer. It is logically equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));</programlisting>
|
||||
<para>
|
||||
Note that multiple calls to talloc_set_name() will allocate more
|
||||
memory without releasing the name. All of the memory is released
|
||||
when the ptr is freed using talloc_free().
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void talloc_set_name_const(const void *<emphasis role="italic">ptr</emphasis>, const char *<emphasis role="italic">name</emphasis>);</title>
|
||||
<para>
|
||||
The function talloc_set_name_const() is just like
|
||||
talloc_set_name(), but it takes a string constant, and is much
|
||||
faster. It is extensively used by the "auto naming" macros, such
|
||||
as talloc_p().
|
||||
</para>
|
||||
<para>
|
||||
This function does not allocate any memory. It just copies the
|
||||
supplied pointer into the internal representation of the talloc
|
||||
ptr. This means you must not pass a <emphasis
|
||||
role="italic">name</emphasis> pointer to memory that will
|
||||
disappear before <emphasis role="italic">ptr</emphasis> is freed
|
||||
with talloc_free().
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_named(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
|
||||
<para>
|
||||
The talloc_named() function creates a named talloc pointer. It
|
||||
is equivalent to:
|
||||
</para>
|
||||
<programlisting>ptr = talloc_size(ctx, size);
|
||||
talloc_set_name(ptr, fmt, ....);</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_named_const(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>, const char *<emphasis role="italic">name</emphasis>);</title>
|
||||
<para>
|
||||
This is equivalent to:
|
||||
</para>
|
||||
<programlisting>ptr = talloc_size(ctx, size);
|
||||
talloc_set_name_const(ptr, name);</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>const char *talloc_get_name(const void *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
This returns the current name for the given talloc pointer,
|
||||
<emphasis role="italic">ptr</emphasis>. See <link
|
||||
linkend="talloc_set_name"><quote>talloc_set_name()</quote></link>
|
||||
for details.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_init(const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
|
||||
<para>
|
||||
This function creates a zero length named talloc context as a top
|
||||
level context. It is equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_named(NULL, 0, fmt, ...);</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_new(void *<emphasis role="italic">ctx</emphasis>);</title>
|
||||
<para>
|
||||
This is a utility macro that creates a new memory context hanging
|
||||
off an exiting context, automatically naming it "talloc_new:
|
||||
__location__" where __location__ is the source line it is called
|
||||
from. It is particularly useful for creating a new temporary
|
||||
working context.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>(<emphasis role="italic">type</emphasis> *)talloc_realloc(const void *<emphasis role="italic">ctx</emphasis>, void *<emphasis role="italic">ptr</emphasis>, <emphasis role="italic">type</emphasis>, <emphasis role="italic">count</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_realloc() macro changes the size of a talloc pointer.
|
||||
It has the following equivalences:
|
||||
</para>
|
||||
<programlisting>talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
|
||||
talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</programlisting>
|
||||
<para>
|
||||
The <emphasis role="italic">ctx</emphasis> argument is only used
|
||||
if <emphasis role="italic">ptr</emphasis> is not NULL, otherwise
|
||||
it is ignored.
|
||||
</para>
|
||||
<para>
|
||||
talloc_realloc() returns the new pointer, or NULL on failure.
|
||||
The call will fail either due to a lack of memory, or because the
|
||||
pointer has more than one parent (see <link
|
||||
linkend="talloc_reference"><quote>talloc_reference()</quote></link>).
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</title>
|
||||
<para>
|
||||
the talloc_realloc_size() function is useful when the type is not
|
||||
known so the type-safe talloc_realloc() cannot be used.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>TYPE *talloc_steal(const void *<emphasis role="italic">new_ctx</emphasis>, const TYPE *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_steal() function changes the parent context of a
|
||||
talloc pointer. It is typically used when the context that the
|
||||
pointer is currently a child of is going to be freed and you wish
|
||||
to keep the memory for a longer time.
|
||||
</para>
|
||||
<para>
|
||||
The talloc_steal() function returns the pointer that you pass it.
|
||||
It does not have any failure modes.
|
||||
</para>
|
||||
<para>
|
||||
NOTE: It is possible to produce loops in the parent/child
|
||||
relationship if you are not careful with talloc_steal(). No
|
||||
guarantees are provided as to your sanity or the safety of your
|
||||
data if you do this.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>TYPE *talloc_move(const void *<emphasis role="italic">new_ctx</emphasis>, TYPE **<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_move() function is a wrapper around
|
||||
talloc_steal() which zeros the source pointer after the
|
||||
move. This avoids a potential source of bugs where a
|
||||
programmer leaves a pointer in two structures, and uses the
|
||||
pointer from the old structure after it has been moved to a
|
||||
new one.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>size_t talloc_total_size(const void *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_total_size() function returns the total size in bytes
|
||||
used by this pointer and all child pointers. Mostly useful for
|
||||
debugging.
|
||||
</para>
|
||||
<para>
|
||||
Passing NULL is allowed, but it will only give a meaningful
|
||||
result if talloc_enable_leak_report() or
|
||||
talloc_enable_leak_report_full() has been called.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>size_t talloc_total_blocks(const void *<emphasis role="italic">ptr</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_total_blocks() function returns the total memory block
|
||||
count used by this pointer and all child pointers. Mostly useful
|
||||
for debugging.
|
||||
</para>
|
||||
<para>
|
||||
Passing NULL is allowed, but it will only give a meaningful
|
||||
result if talloc_enable_leak_report() or
|
||||
talloc_enable_leak_report_full() has been called.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_report"><title>void talloc_report(const void *ptr, FILE *f);</title>
|
||||
<para>
|
||||
The talloc_report() function prints a summary report of all
|
||||
memory used by <emphasis role="italic">ptr</emphasis>. One line
|
||||
of report is printed for each immediate child of ptr, showing the
|
||||
total memory and number of blocks used by that child.
|
||||
</para>
|
||||
<para>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_report_full"><title>void talloc_report_full(const void *<emphasis role="italic">ptr</emphasis>, FILE *<emphasis role="italic">f</emphasis>);</title>
|
||||
<para>
|
||||
This provides a more detailed report than talloc_report(). It
|
||||
will recursively print the entire tree of memory referenced by
|
||||
the pointer. References in the tree are shown by giving the name
|
||||
of the pointer that is referenced.
|
||||
</para>
|
||||
<para>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_report_depth_cb">
|
||||
<funcsynopsis><funcprototype>
|
||||
<funcdef>void <function>talloc_report_depth_cb</function></funcdef>
|
||||
<paramdef><parameter>const void *ptr</parameter></paramdef>
|
||||
<paramdef><parameter>int depth</parameter></paramdef>
|
||||
<paramdef><parameter>int max_depth</parameter></paramdef>
|
||||
<paramdef><parameter>void (*callback)(const void *ptr, int depth, int max_depth, int is_ref, void *priv)</parameter></paramdef>
|
||||
<paramdef><parameter>void *priv</parameter></paramdef>
|
||||
</funcprototype></funcsynopsis>
|
||||
<para>
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will recursively call the callback for the entire tree of memory
|
||||
referenced by the pointer. References in the tree are passed with
|
||||
<emphasis role="italic">is_ref = 1</emphasis> and the pointer that is referenced.
|
||||
</para>
|
||||
<para>
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
</para>
|
||||
<para>
|
||||
The recursion is stopped when depth >= max_depth.
|
||||
max_depth = -1 means only stop at leaf nodes.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_report_depth_file">
|
||||
<funcsynopsis><funcprototype>
|
||||
<funcdef>void <function>talloc_report_depth_file</function></funcdef>
|
||||
<paramdef><parameter>const void *ptr</parameter></paramdef>
|
||||
<paramdef><parameter>int depth</parameter></paramdef>
|
||||
<paramdef><parameter>int max_depth</parameter></paramdef>
|
||||
<paramdef><parameter>FILE *f</parameter></paramdef>
|
||||
</funcprototype></funcsynopsis>
|
||||
<para>
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will let you specify the depth and max_depth.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_enable_leak_report"><title>void talloc_enable_leak_report(void);</title>
|
||||
<para>
|
||||
This enables calling of talloc_report(NULL, stderr) when the
|
||||
program exits. In Samba4 this is enabled by using the
|
||||
--leak-report command line option.
|
||||
</para>
|
||||
<para>
|
||||
For it to be useful, this function must be called before any
|
||||
other talloc function as it establishes a "null context" that
|
||||
acts as the top of the tree. If you don't call this function
|
||||
first then passing NULL to talloc_report() or
|
||||
talloc_report_full() won't give you the full tree printout.
|
||||
</para>
|
||||
<para>
|
||||
Here is a typical talloc report:
|
||||
</para>
|
||||
<screen format="linespecific">talloc report on 'null_context' (total 267 bytes in 15 blocks)
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(UTF8,CP850) contains 42 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(CP850,UTF8) contains 42 bytes in 2 blocks
|
||||
iconv(UTF8,UTF-16LE) contains 45 bytes in 2 blocks
|
||||
iconv(UTF-16LE,UTF8) contains 45 bytes in 2 blocks
|
||||
</screen>
|
||||
</refsect2>
|
||||
<refsect2 id="talloc_enable_leak_report_full"><title>void talloc_enable_leak_report_full(void);</title>
|
||||
<para>
|
||||
This enables calling of talloc_report_full(NULL, stderr) when the
|
||||
program exits. In Samba4 this is enabled by using the
|
||||
--leak-report-full command line option.
|
||||
</para>
|
||||
<para>
|
||||
For it to be useful, this function must be called before any
|
||||
other talloc function as it establishes a "null context" that
|
||||
acts as the top of the tree. If you don't call this function
|
||||
first then passing NULL to talloc_report() or
|
||||
talloc_report_full() won't give you the full tree printout.
|
||||
</para>
|
||||
<para>
|
||||
Here is a typical full report:
|
||||
</para>
|
||||
<screen format="linespecific">full talloc report on 'root' (total 18 bytes in 8 blocks)
|
||||
p1 contains 18 bytes in 7 blocks (ref 0)
|
||||
r1 contains 13 bytes in 2 blocks (ref 0)
|
||||
reference to: p2
|
||||
p2 contains 1 bytes in 1 blocks (ref 1)
|
||||
x3 contains 1 bytes in 1 blocks (ref 0)
|
||||
x2 contains 1 bytes in 1 blocks (ref 0)
|
||||
x1 contains 1 bytes in 1 blocks (ref 0)
|
||||
</screen>
|
||||
</refsect2>
|
||||
<refsect2><title>(<emphasis role="italic">type</emphasis> *)talloc_zero(const void *<emphasis role="italic">ctx</emphasis>, <emphasis role="italic">type</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_zero() macro is equivalent to:
|
||||
</para>
|
||||
<programlisting>ptr = talloc(ctx, type);
|
||||
if (ptr) memset(ptr, 0, sizeof(type));</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_zero_size(const void *<emphasis role="italic">ctx</emphasis>, size_t <emphasis role="italic">size</emphasis>)</title>
|
||||
<para>
|
||||
The talloc_zero_size() function is useful when you don't have a
|
||||
known type.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_memdup(const void *<emphasis role="italic">ctx</emphasis>, const void *<emphasis role="italic">p</emphasis>, size_t size);</title>
|
||||
<para>
|
||||
The talloc_memdup() function is equivalent to:
|
||||
</para>
|
||||
<programlisting>ptr = talloc_size(ctx, size);
|
||||
if (ptr) memcpy(ptr, p, size);</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>char *talloc_strdup(const void *<emphasis role="italic">ctx</emphasis>, const char *<emphasis role="italic">p</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_strdup() function is equivalent to:
|
||||
</para>
|
||||
<programlisting>ptr = talloc_size(ctx, strlen(p)+1);
|
||||
if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
|
||||
<para>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>char *talloc_strndup(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">p</emphasis>, size_t <emphasis role="italic">n</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_strndup() function is the talloc equivalent of the C
|
||||
library function strndup(3).
|
||||
</para>
|
||||
<para>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>char *talloc_vasprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, va_list <emphasis role="italic">ap</emphasis>);</title>
|
||||
<para>
|
||||
The talloc_vasprintf() function is the talloc equivalent of the C
|
||||
library function vasprintf(3).
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>char *talloc_asprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
|
||||
<para>
|
||||
The talloc_asprintf() function is the talloc equivalent of the C
|
||||
library function asprintf(3).
|
||||
</para>
|
||||
<para>
|
||||
This function sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
</para>
|
||||
<programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>char *talloc_asprintf_append(char *s, const char *fmt, ...);</title>
|
||||
<para>
|
||||
The talloc_asprintf_append() function appends the given formatted
|
||||
string to the given string.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>(type *)talloc_array(const void *ctx, type, uint_t count);</title>
|
||||
<para>
|
||||
The talloc_array() macro is equivalent to:
|
||||
</para>
|
||||
<programlisting>(type *)talloc_size(ctx, sizeof(type) * count);</programlisting>
|
||||
<para>
|
||||
except that it provides integer overflow protection for the
|
||||
multiply, returning NULL if the multiply overflows.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</title>
|
||||
<para>
|
||||
The talloc_array_size() function is useful when the type is not
|
||||
known. It operates in the same way as talloc_array(), but takes a
|
||||
size instead of a type.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);</title>
|
||||
<para>
|
||||
The talloc_ptrtype() macro should be used when you have a pointer to an array
|
||||
and want to allocate memory of an array to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</title>
|
||||
<para>
|
||||
This is a non-macro version of talloc_realloc(), which is useful
|
||||
as libraries sometimes want a realloc function pointer. A
|
||||
realloc(3) implementation encapsulates the functionality of
|
||||
malloc(3), free(3) and realloc(3) in one call, which is why it is
|
||||
useful to be able to pass around a single function pointer.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_autofree_context(void);</title>
|
||||
<para>
|
||||
This is a handy utility function that returns a talloc context
|
||||
which will be automatically freed on program exit. This can be
|
||||
used to reduce the noise in memory leak reports.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>void *talloc_check_name(const void *ptr, const char *name);</title>
|
||||
<para>
|
||||
This function checks if a pointer has the specified <emphasis
|
||||
role="italic">name</emphasis>. If it does then the pointer is
|
||||
returned. It it doesn't then NULL is returned.
|
||||
</para>
|
||||
</refsect2>
|
||||
<refsect2><title>(type *)talloc_get_type(const void *ptr, type);</title>
|
||||
<para>
|
||||
This macro allows you to do type checking on talloc pointers. It
|
||||
is particularly useful for void* private pointers. It is
|
||||
equivalent to this:
|
||||
</para>
|
||||
<programlisting>(type *)talloc_check_name(ptr, #type)</programlisting>
|
||||
</refsect2>
|
||||
<refsect2><title>talloc_set_type(const void *ptr, type);</title>
|
||||
<para>
|
||||
This macro allows you to force the name of a pointer to be a
|
||||
particular <emphasis>type</emphasis>. This can be
|
||||
used in conjunction with talloc_get_type() to do type checking on
|
||||
void* pointers.
|
||||
</para>
|
||||
<para>
|
||||
It is equivalent to this:
|
||||
</para>
|
||||
<programlisting>talloc_set_name_const(ptr, #type)</programlisting>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
<refsect1><title>PERFORMANCE</title>
|
||||
<para>
|
||||
All the additional features of talloc(3) over malloc(3) do come at a
|
||||
price. We have a simple performance test in Samba4 that measures
|
||||
talloc() versus malloc() performance, and it seems that talloc() is
|
||||
about 10% slower than malloc() on my x86 Debian Linux box. For
|
||||
Samba, the great reduction in code complexity that we get by using
|
||||
talloc makes this worthwhile, especially as the total overhead of
|
||||
talloc/malloc in Samba is already quite small.
|
||||
</para>
|
||||
</refsect1>
|
||||
<refsect1><title>SEE ALSO</title>
|
||||
<para>
|
||||
malloc(3), strndup(3), vasprintf(3), asprintf(3),
|
||||
<ulink url="http://talloc.samba.org/"/>
|
||||
</para>
|
||||
</refsect1>
|
||||
<refsect1><title>COPYRIGHT/LICENSE</title>
|
||||
<para>
|
||||
Copyright (C) Andrew Tridgell 2004
|
||||
</para>
|
||||
<para>
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or (at
|
||||
your option) any later version.
|
||||
</para>
|
||||
<para>
|
||||
This program 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
|
||||
General Public License for more details.
|
||||
</para>
|
||||
<para>
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
1418
ctdb/lib/talloc/talloc.c
Normal file
1418
ctdb/lib/talloc/talloc.c
Normal file
File diff suppressed because it is too large
Load Diff
168
ctdb/lib/talloc/talloc.h
Normal file
168
ctdb/lib/talloc/talloc.h
Normal file
@ -0,0 +1,168 @@
|
||||
#ifndef _TALLOC_H_
|
||||
#define _TALLOC_H_
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Samba temporary memory allocation functions
|
||||
|
||||
Copyright (C) Andrew Tridgell 2004-2005
|
||||
Copyright (C) Stefan Metzmacher 2006
|
||||
|
||||
** NOTE! The following LGPL license applies to the talloc
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* this is only needed for compatibility with the old talloc */
|
||||
typedef void TALLOC_CTX;
|
||||
|
||||
/*
|
||||
this uses a little trick to allow __LINE__ to be stringified
|
||||
*/
|
||||
#define _STRING_LINE_(s) #s
|
||||
#define _STRING_LINE2_(s) _STRING_LINE_(s)
|
||||
#define __LINESTR__ _STRING_LINE2_(__LINE__)
|
||||
#define __location__ __FILE__ ":" __LINESTR__
|
||||
|
||||
#ifndef TALLOC_DEPRECATED
|
||||
#define TALLOC_DEPRECATED 0
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_ATTRIBUTE
|
||||
#if (__GNUC__ >= 3)
|
||||
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
|
||||
* the parameter containing the format, and a2 the index of the first
|
||||
* argument. Note that some gcc 2.x versions don't handle this
|
||||
* properly **/
|
||||
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
|
||||
#else
|
||||
#define PRINTF_ATTRIBUTE(a1, a2)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* try to make talloc_set_destructor() and talloc_steal() type safe,
|
||||
if we have a recent gcc */
|
||||
#if (__GNUC__ >= 3)
|
||||
#define _TALLOC_TYPEOF(ptr) __typeof__(ptr)
|
||||
#define talloc_set_destructor(ptr, function) \
|
||||
do { \
|
||||
int (*_talloc_destructor_fn)(_TALLOC_TYPEOF(ptr)) = (function); \
|
||||
_talloc_set_destructor((ptr), (int (*)(void *))_talloc_destructor_fn); \
|
||||
} while(0)
|
||||
/* this extremely strange macro is to avoid some braindamaged warning
|
||||
stupidity in gcc 4.1.x */
|
||||
#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr)); __talloc_steal_ret; })
|
||||
#else
|
||||
#define talloc_set_destructor(ptr, function) \
|
||||
_talloc_set_destructor((ptr), (int (*)(void *))(function))
|
||||
#define _TALLOC_TYPEOF(ptr) void *
|
||||
#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr))
|
||||
#endif
|
||||
|
||||
#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr))
|
||||
#define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(void *)(ptr))
|
||||
|
||||
/* useful macros for creating type checked pointers */
|
||||
#define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
|
||||
#define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
|
||||
#define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr))talloc_size(ctx, sizeof(*(ptr)))
|
||||
|
||||
#define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
|
||||
|
||||
#define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
|
||||
#define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__)
|
||||
|
||||
#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
|
||||
#define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
|
||||
#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
|
||||
#define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
|
||||
|
||||
#define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, #type)
|
||||
#define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
|
||||
|
||||
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
|
||||
|
||||
#define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type)
|
||||
#define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type)
|
||||
|
||||
#define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type)
|
||||
|
||||
#if TALLOC_DEPRECATED
|
||||
#define talloc_zero_p(ctx, type) talloc_zero(ctx, type)
|
||||
#define talloc_p(ctx, type) talloc(ctx, type)
|
||||
#define talloc_array_p(ctx, type, count) talloc_array(ctx, type, count)
|
||||
#define talloc_realloc_p(ctx, p, type, count) talloc_realloc(ctx, p, type, count)
|
||||
#define talloc_destroy(ctx) talloc_free(ctx)
|
||||
#endif
|
||||
|
||||
/* The following definitions come from talloc.c */
|
||||
void *_talloc(const void *context, size_t size);
|
||||
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
|
||||
int talloc_increase_ref_count(const void *ptr);
|
||||
size_t talloc_reference_count(const void *ptr);
|
||||
void *_talloc_reference(const void *context, const void *ptr);
|
||||
int talloc_unlink(const void *context, void *ptr);
|
||||
const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
void talloc_set_name_const(const void *ptr, const char *name);
|
||||
void *talloc_named(const void *context, size_t size,
|
||||
const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
|
||||
void *talloc_named_const(const void *context, size_t size, const char *name);
|
||||
const char *talloc_get_name(const void *ptr);
|
||||
void *talloc_check_name(const void *ptr, const char *name);
|
||||
void *talloc_parent(const void *ptr);
|
||||
const char *talloc_parent_name(const void *ptr);
|
||||
void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
|
||||
int talloc_free(void *ptr);
|
||||
void talloc_free_children(void *ptr);
|
||||
void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
|
||||
void *_talloc_steal(const void *new_ctx, const void *ptr);
|
||||
void *_talloc_move(const void *new_ctx, const void *pptr);
|
||||
size_t talloc_total_size(const void *ptr);
|
||||
size_t talloc_total_blocks(const void *ptr);
|
||||
void talloc_report_depth_cb(const void *ptr, int depth, int max_depth,
|
||||
void (*callback)(const void *ptr,
|
||||
int depth, int max_depth,
|
||||
int is_ref,
|
||||
void *private_data),
|
||||
void *private_data);
|
||||
void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f);
|
||||
void talloc_report_full(const void *ptr, FILE *f);
|
||||
void talloc_report(const void *ptr, FILE *f);
|
||||
void talloc_enable_null_tracking(void);
|
||||
void talloc_disable_null_tracking(void);
|
||||
void talloc_enable_leak_report(void);
|
||||
void talloc_enable_leak_report_full(void);
|
||||
void *_talloc_zero(const void *ctx, size_t size, const char *name);
|
||||
void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
|
||||
char *talloc_strdup(const void *t, const char *p);
|
||||
char *talloc_strndup(const void *t, const char *p, size_t n);
|
||||
char *talloc_append_string(const void *t, char *orig, const char *append);
|
||||
char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
|
||||
char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
|
||||
char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name);
|
||||
void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name);
|
||||
void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
|
||||
void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
|
||||
void *talloc_autofree_context(void);
|
||||
size_t talloc_get_size(const void *ctx);
|
||||
void *talloc_find_parent_byname(const void *ctx, const char *name);
|
||||
void talloc_show_parents(const void *context, FILE *file);
|
||||
int talloc_is_parent(const void *context, const void *ptr);
|
||||
|
||||
#endif
|
||||
|
36
ctdb/lib/talloc/talloc.h.rej
Normal file
36
ctdb/lib/talloc/talloc.h.rej
Normal file
@ -0,0 +1,36 @@
|
||||
***************
|
||||
*** 80,106 ****
|
||||
#define talloc_destroy(ctx) talloc_free(ctx)
|
||||
#endif
|
||||
|
||||
- #ifndef PRINTF_ATTRIBUTE
|
||||
- #if (__GNUC__ >= 3)
|
||||
- /** Use gcc attribute to check printf fns. a1 is the 1-based index of
|
||||
- * the parameter containing the format, and a2 the index of the first
|
||||
- * argument. Note that some gcc 2.x versions don't handle this
|
||||
- * properly **/
|
||||
- #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
|
||||
- /* We need __typeof__ to make this type-safe. */
|
||||
- #define talloc_set_destructor(ptr, function) \
|
||||
- do { \
|
||||
- int (*_talloc_destructor_fn)(typeof(ptr)) = (function); \
|
||||
- _talloc_set_destructor((ptr), _talloc_destructor_fn); \
|
||||
- } while(0)
|
||||
- #else
|
||||
- #define PRINTF_ATTRIBUTE(a1, a2)
|
||||
- #define talloc_set_destructor(ptr, function) \
|
||||
- _talloc_set_destructor((ptr), (int (*)(void *))(function))
|
||||
- #endif
|
||||
- #endif
|
||||
-
|
||||
-
|
||||
/* The following definitions come from talloc.c */
|
||||
void *_talloc(const void *context, size_t size);
|
||||
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
|
||||
--- 103,108 ----
|
||||
#define talloc_destroy(ctx) talloc_free(ctx)
|
||||
#endif
|
||||
|
||||
/* The following definitions come from talloc.c */
|
||||
void *_talloc(const void *context, size_t size);
|
||||
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
|
11
ctdb/lib/talloc/talloc.pc
Normal file
11
ctdb/lib/talloc/talloc.pc
Normal file
@ -0,0 +1,11 @@
|
||||
prefix=/home/tridge/samba/samba4/prefix
|
||||
exec_prefix=/home/tridge/samba/samba4/prefix
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: talloc
|
||||
Description: A hierarchical pool based memory system with destructors
|
||||
Version: 0.0.1
|
||||
Libs: -L${libdir} -ltalloc
|
||||
Libs.private: -lreplace
|
||||
Cflags: -I${includedir} -DHAVE_IMMEDIATE_STRUCTURES=1
|
11
ctdb/lib/talloc/talloc.pc.in
Normal file
11
ctdb/lib/talloc/talloc.pc.in
Normal file
@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: talloc
|
||||
Description: A hierarchical pool based memory system with destructors
|
||||
Version: 4.0
|
||||
Libs: -L${libdir} -ltalloc
|
||||
Cflags: -I${includedir}
|
||||
URL: http://talloc.samba.org/
|
653
ctdb/lib/talloc/talloc_guide.txt
Normal file
653
ctdb/lib/talloc/talloc_guide.txt
Normal file
@ -0,0 +1,653 @@
|
||||
Using talloc in Samba4
|
||||
----------------------
|
||||
|
||||
Andrew Tridgell
|
||||
September 2004
|
||||
|
||||
The most current version of this document is available at
|
||||
http://samba.org/ftp/unpacked/samba4/source/lib/talloc/talloc_guide.txt
|
||||
|
||||
If you are used to the "old" talloc from Samba3 before 3.0.20 then please read
|
||||
this carefully, as talloc has changed a lot. With 3.0.20 (or 3.0.14?) the
|
||||
Samba4 talloc has been ported back to Samba3, so this guide applies to both.
|
||||
|
||||
The new talloc is a hierarchical, reference counted memory pool system
|
||||
with destructors. Quite a mounthful really, but not too bad once you
|
||||
get used to it.
|
||||
|
||||
Perhaps the biggest change from Samba3 is that there is no distinction
|
||||
between a "talloc context" and a "talloc pointer". Any pointer
|
||||
returned from talloc() is itself a valid talloc context. This means
|
||||
you can do this:
|
||||
|
||||
struct foo *X = talloc(mem_ctx, struct foo);
|
||||
X->name = talloc_strdup(X, "foo");
|
||||
|
||||
and the pointer X->name would be a "child" of the talloc context "X"
|
||||
which is itself a child of mem_ctx. So if you do talloc_free(mem_ctx)
|
||||
then it is all destroyed, whereas if you do talloc_free(X) then just X
|
||||
and X->name are destroyed, and if you do talloc_free(X->name) then
|
||||
just the name element of X is destroyed.
|
||||
|
||||
If you think about this, then what this effectively gives you is an
|
||||
n-ary tree, where you can free any part of the tree with
|
||||
talloc_free().
|
||||
|
||||
If you find this confusing, then I suggest you run the testsuite to
|
||||
watch talloc in action. You may also like to add your own tests to
|
||||
testsuite.c to clarify how some particular situation is handled.
|
||||
|
||||
|
||||
Performance
|
||||
-----------
|
||||
|
||||
All the additional features of talloc() over malloc() do come at a
|
||||
price. We have a simple performance test in Samba4 that measures
|
||||
talloc() versus malloc() performance, and it seems that talloc() is
|
||||
about 4% slower than malloc() on my x86 Debian Linux box. For Samba,
|
||||
the great reduction in code complexity that we get by using talloc
|
||||
makes this worthwhile, especially as the total overhead of
|
||||
talloc/malloc in Samba is already quite small.
|
||||
|
||||
|
||||
talloc API
|
||||
----------
|
||||
|
||||
The following is a complete guide to the talloc API. Read it all at
|
||||
least twice.
|
||||
|
||||
Multi-threading
|
||||
---------------
|
||||
|
||||
talloc itself does not deal with threads. It is thread-safe (assuming
|
||||
the underlying "malloc" is), as long as each thread uses different
|
||||
memory contexts.
|
||||
If two threads uses the same context then they need to synchronize in
|
||||
order to be safe. In particular:
|
||||
- when using talloc_enable_leak_report(), giving directly NULL as a
|
||||
parent context implicitly refers to a hidden "null context" global
|
||||
variable, so this should not be used in a multi-threaded environment
|
||||
without proper synchronization ;
|
||||
- the context returned by talloc_autofree_context() is also global so
|
||||
shouldn't be used by several threads simultaneously without
|
||||
synchronization.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc(const void *context, type);
|
||||
|
||||
The talloc() macro is the core of the talloc library. It takes a
|
||||
memory context and a type, and returns a pointer to a new area of
|
||||
memory of the given type.
|
||||
|
||||
The returned pointer is itself a talloc context, so you can use it as
|
||||
the context argument to more calls to talloc if you wish.
|
||||
|
||||
The returned pointer is a "child" of the supplied context. This means
|
||||
that if you talloc_free() the context then the new child disappears as
|
||||
well. Alternatively you can free just the child.
|
||||
|
||||
The context argument to talloc() can be NULL, in which case a new top
|
||||
level context is created.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_size(const void *context, size_t size);
|
||||
|
||||
The function talloc_size() should be used when you don't have a
|
||||
convenient type to pass to talloc(). Unlike talloc(), it is not type
|
||||
safe (as it returns a void *), so you are on your own for type checking.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);
|
||||
|
||||
The talloc_ptrtype() macro should be used when you have a pointer and
|
||||
want to allocate memory to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
int talloc_free(void *ptr);
|
||||
|
||||
The talloc_free() function frees a piece of talloc memory, and all its
|
||||
children. You can call talloc_free() on any pointer returned by
|
||||
talloc().
|
||||
|
||||
The return value of talloc_free() indicates success or failure, with 0
|
||||
returned for success and -1 for failure. The only possible failure
|
||||
condition is if the pointer had a destructor attached to it and the
|
||||
destructor returned -1. See talloc_set_destructor() for details on
|
||||
destructors.
|
||||
|
||||
If this pointer has an additional parent when talloc_free() is called
|
||||
then the memory is not actually released, but instead the most
|
||||
recently established parent is destroyed. See talloc_reference() for
|
||||
details on establishing additional parents.
|
||||
|
||||
For more control on which parent is removed, see talloc_unlink()
|
||||
|
||||
talloc_free() operates recursively on its children.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
int talloc_free_children(void *ptr);
|
||||
|
||||
The talloc_free_children() walks along the list of all children of a
|
||||
talloc context and talloc_free()s only the children, not the context
|
||||
itself.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_reference(const void *context, const void *ptr);
|
||||
|
||||
The talloc_reference() function makes "context" an additional parent
|
||||
of "ptr".
|
||||
|
||||
The return value of talloc_reference() is always the original pointer
|
||||
"ptr", unless talloc ran out of memory in creating the reference in
|
||||
which case it will return NULL (each additional reference consumes
|
||||
around 48 bytes of memory on intel x86 platforms).
|
||||
|
||||
If "ptr" is NULL, then the function is a no-op, and simply returns NULL.
|
||||
|
||||
After creating a reference you can free it in one of the following
|
||||
ways:
|
||||
|
||||
- you can talloc_free() any parent of the original pointer. That
|
||||
will reduce the number of parents of this pointer by 1, and will
|
||||
cause this pointer to be freed if it runs out of parents.
|
||||
|
||||
- you can talloc_free() the pointer itself. That will destroy the
|
||||
most recently established parent to the pointer and leave the
|
||||
pointer as a child of its current parent.
|
||||
|
||||
For more control on which parent to remove, see talloc_unlink()
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
int talloc_unlink(const void *context, const void *ptr);
|
||||
|
||||
The talloc_unlink() function removes a specific parent from ptr. The
|
||||
context passed must either be a context used in talloc_reference()
|
||||
with this pointer, or must be a direct parent of ptr.
|
||||
|
||||
Note that if the parent has already been removed using talloc_free()
|
||||
then this function will fail and will return -1. Likewise, if "ptr"
|
||||
is NULL, then the function will make no modifications and return -1.
|
||||
|
||||
Usually you can just use talloc_free() instead of talloc_unlink(), but
|
||||
sometimes it is useful to have the additional control on which parent
|
||||
is removed.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_set_destructor(const void *ptr, int (*destructor)(void *));
|
||||
|
||||
The function talloc_set_destructor() sets the "destructor" for the
|
||||
pointer "ptr". A destructor is a function that is called when the
|
||||
memory used by a pointer is about to be released. The destructor
|
||||
receives the pointer as an argument, and should return 0 for success
|
||||
and -1 for failure.
|
||||
|
||||
The destructor can do anything it wants to, including freeing other
|
||||
pieces of memory. A common use for destructors is to clean up
|
||||
operating system resources (such as open file descriptors) contained
|
||||
in the structure the destructor is placed on.
|
||||
|
||||
You can only place one destructor on a pointer. If you need more than
|
||||
one destructor then you can create a zero-length child of the pointer
|
||||
and place an additional destructor on that.
|
||||
|
||||
To remove a destructor call talloc_set_destructor() with NULL for the
|
||||
destructor.
|
||||
|
||||
If your destructor attempts to talloc_free() the pointer that it is
|
||||
the destructor for then talloc_free() will return -1 and the free will
|
||||
be ignored. This would be a pointless operation anyway, as the
|
||||
destructor is only called when the memory is just about to go away.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
int talloc_increase_ref_count(const void *ptr);
|
||||
|
||||
The talloc_increase_ref_count(ptr) function is exactly equivalent to:
|
||||
|
||||
talloc_reference(NULL, ptr);
|
||||
|
||||
You can use either syntax, depending on which you think is clearer in
|
||||
your code.
|
||||
|
||||
It returns 0 on success and -1 on failure.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
size_t talloc_reference_count(const void *ptr);
|
||||
|
||||
Return the number of references to the pointer.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_set_name(const void *ptr, const char *fmt, ...);
|
||||
|
||||
Each talloc pointer has a "name". The name is used principally for
|
||||
debugging purposes, although it is also possible to set and get the
|
||||
name on a pointer in as a way of "marking" pointers in your code.
|
||||
|
||||
The main use for names on pointer is for "talloc reports". See
|
||||
talloc_report() and talloc_report_full() for details. Also see
|
||||
talloc_enable_leak_report() and talloc_enable_leak_report_full().
|
||||
|
||||
The talloc_set_name() function allocates memory as a child of the
|
||||
pointer. It is logically equivalent to:
|
||||
talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));
|
||||
|
||||
Note that multiple calls to talloc_set_name() will allocate more
|
||||
memory without releasing the name. All of the memory is released when
|
||||
the ptr is freed using talloc_free().
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_set_name_const(const void *ptr, const char *name);
|
||||
|
||||
The function talloc_set_name_const() is just like talloc_set_name(),
|
||||
but it takes a string constant, and is much faster. It is extensively
|
||||
used by the "auto naming" macros, such as talloc_p().
|
||||
|
||||
This function does not allocate any memory. It just copies the
|
||||
supplied pointer into the internal representation of the talloc
|
||||
ptr. This means you must not pass a name pointer to memory that will
|
||||
disappear before the ptr is freed with talloc_free().
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_named(const void *context, size_t size, const char *fmt, ...);
|
||||
|
||||
The talloc_named() function creates a named talloc pointer. It is
|
||||
equivalent to:
|
||||
|
||||
ptr = talloc_size(context, size);
|
||||
talloc_set_name(ptr, fmt, ....);
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_named_const(const void *context, size_t size, const char *name);
|
||||
|
||||
This is equivalent to:
|
||||
|
||||
ptr = talloc_size(context, size);
|
||||
talloc_set_name_const(ptr, name);
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
const char *talloc_get_name(const void *ptr);
|
||||
|
||||
This returns the current name for the given talloc pointer. See
|
||||
talloc_set_name() for details.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_init(const char *fmt, ...);
|
||||
|
||||
This function creates a zero length named talloc context as a top
|
||||
level context. It is equivalent to:
|
||||
|
||||
talloc_named(NULL, 0, fmt, ...);
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_new(void *ctx);
|
||||
|
||||
This is a utility macro that creates a new memory context hanging
|
||||
off an exiting context, automatically naming it "talloc_new: __location__"
|
||||
where __location__ is the source line it is called from. It is
|
||||
particularly useful for creating a new temporary working context.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc_realloc(const void *context, void *ptr, type, count);
|
||||
|
||||
The talloc_realloc() macro changes the size of a talloc
|
||||
pointer. The "count" argument is the number of elements of type "type"
|
||||
that you want the resulting pointer to hold.
|
||||
|
||||
talloc_realloc() has the following equivalences:
|
||||
|
||||
talloc_realloc(context, NULL, type, 1) ==> talloc(context, type);
|
||||
talloc_realloc(context, NULL, type, N) ==> talloc_array(context, type, N);
|
||||
talloc_realloc(context, ptr, type, 0) ==> talloc_free(ptr);
|
||||
|
||||
The "context" argument is only used if "ptr" is NULL, otherwise it is
|
||||
ignored.
|
||||
|
||||
talloc_realloc() returns the new pointer, or NULL on failure. The call
|
||||
will fail either due to a lack of memory, or because the pointer has
|
||||
more than one parent (see talloc_reference()).
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_realloc_size(const void *context, void *ptr, size_t size);
|
||||
|
||||
the talloc_realloc_size() function is useful when the type is not
|
||||
known so the typesafe talloc_realloc() cannot be used.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_steal(const void *new_ctx, const void *ptr);
|
||||
|
||||
The talloc_steal() function changes the parent context of a talloc
|
||||
pointer. It is typically used when the context that the pointer is
|
||||
currently a child of is going to be freed and you wish to keep the
|
||||
memory for a longer time.
|
||||
|
||||
The talloc_steal() function returns the pointer that you pass it. It
|
||||
does not have any failure modes.
|
||||
|
||||
NOTE: It is possible to produce loops in the parent/child relationship
|
||||
if you are not careful with talloc_steal(). No guarantees are provided
|
||||
as to your sanity or the safety of your data if you do this.
|
||||
|
||||
talloc_steal (new_ctx, NULL) will return NULL with no sideeffects.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
size_t talloc_total_size(const void *ptr);
|
||||
|
||||
The talloc_total_size() function returns the total size in bytes used
|
||||
by this pointer and all child pointers. Mostly useful for debugging.
|
||||
|
||||
Passing NULL is allowed, but it will only give a meaningful result if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full() has
|
||||
been called.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
size_t talloc_total_blocks(const void *ptr);
|
||||
|
||||
The talloc_total_blocks() function returns the total memory block
|
||||
count used by this pointer and all child pointers. Mostly useful for
|
||||
debugging.
|
||||
|
||||
Passing NULL is allowed, but it will only give a meaningful result if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full() has
|
||||
been called.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_report_depth_cb(const void *ptr, int depth, int max_depth,
|
||||
void (*callback)(const void *ptr,
|
||||
int depth, int max_depth,
|
||||
int is_ref,
|
||||
void *priv),
|
||||
void *priv);
|
||||
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will recursively call the callback for the entire tree of memory
|
||||
referenced by the pointer. References in the tree are passed with
|
||||
is_ref = 1 and the pointer that is referenced.
|
||||
|
||||
You can pass NULL for the pointer, in which case a report is
|
||||
printed for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full()
|
||||
has been called.
|
||||
|
||||
The recursion is stopped when depth >= max_depth.
|
||||
max_depth = -1 means only stop at leaf nodes.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f);
|
||||
|
||||
This provides a more flexible reports than talloc_report(). It
|
||||
will let you specify the depth and max_depth.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_report(const void *ptr, FILE *f);
|
||||
|
||||
The talloc_report() function prints a summary report of all memory
|
||||
used by ptr. One line of report is printed for each immediate child of
|
||||
ptr, showing the total memory and number of blocks used by that child.
|
||||
|
||||
You can pass NULL for the pointer, in which case a report is printed
|
||||
for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full() has
|
||||
been called.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_report_full(const void *ptr, FILE *f);
|
||||
|
||||
This provides a more detailed report than talloc_report(). It will
|
||||
recursively print the ensire tree of memory referenced by the
|
||||
pointer. References in the tree are shown by giving the name of the
|
||||
pointer that is referenced.
|
||||
|
||||
You can pass NULL for the pointer, in which case a report is printed
|
||||
for the top level memory context, but only if
|
||||
talloc_enable_leak_report() or talloc_enable_leak_report_full() has
|
||||
been called.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_enable_leak_report(void);
|
||||
|
||||
This enables calling of talloc_report(NULL, stderr) when the program
|
||||
exits. In Samba4 this is enabled by using the --leak-report command
|
||||
line option.
|
||||
|
||||
For it to be useful, this function must be called before any other
|
||||
talloc function as it establishes a "null context" that acts as the
|
||||
top of the tree. If you don't call this function first then passing
|
||||
NULL to talloc_report() or talloc_report_full() won't give you the
|
||||
full tree printout.
|
||||
|
||||
Here is a typical talloc report:
|
||||
|
||||
talloc report on 'null_context' (total 267 bytes in 15 blocks)
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(UTF8,CP850) contains 42 bytes in 2 blocks
|
||||
libcli/auth/spnego_parse.c:55 contains 31 bytes in 2 blocks
|
||||
iconv(CP850,UTF8) contains 42 bytes in 2 blocks
|
||||
iconv(UTF8,UTF-16LE) contains 45 bytes in 2 blocks
|
||||
iconv(UTF-16LE,UTF8) contains 45 bytes in 2 blocks
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_enable_leak_report_full(void);
|
||||
|
||||
This enables calling of talloc_report_full(NULL, stderr) when the
|
||||
program exits. In Samba4 this is enabled by using the
|
||||
--leak-report-full command line option.
|
||||
|
||||
For it to be useful, this function must be called before any other
|
||||
talloc function as it establishes a "null context" that acts as the
|
||||
top of the tree. If you don't call this function first then passing
|
||||
NULL to talloc_report() or talloc_report_full() won't give you the
|
||||
full tree printout.
|
||||
|
||||
Here is a typical full report:
|
||||
|
||||
full talloc report on 'root' (total 18 bytes in 8 blocks)
|
||||
p1 contains 18 bytes in 7 blocks (ref 0)
|
||||
r1 contains 13 bytes in 2 blocks (ref 0)
|
||||
reference to: p2
|
||||
p2 contains 1 bytes in 1 blocks (ref 1)
|
||||
x3 contains 1 bytes in 1 blocks (ref 0)
|
||||
x2 contains 1 bytes in 1 blocks (ref 0)
|
||||
x1 contains 1 bytes in 1 blocks (ref 0)
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_enable_null_tracking(void);
|
||||
|
||||
This enables tracking of the NULL memory context without enabling leak
|
||||
reporting on exit. Useful for when you want to do your own leak
|
||||
reporting call via talloc_report_null_full();
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void talloc_disable_null_tracking(void);
|
||||
|
||||
This disables tracking of the NULL memory context.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc_zero(const void *ctx, type);
|
||||
|
||||
The talloc_zero() macro is equivalent to:
|
||||
|
||||
ptr = talloc(ctx, type);
|
||||
if (ptr) memset(ptr, 0, sizeof(type));
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_zero_size(const void *ctx, size_t size)
|
||||
|
||||
The talloc_zero_size() function is useful when you don't have a known type
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_memdup(const void *ctx, const void *p, size_t size);
|
||||
|
||||
The talloc_memdup() function is equivalent to:
|
||||
|
||||
ptr = talloc_size(ctx, size);
|
||||
if (ptr) memcpy(ptr, p, size);
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
char *talloc_strdup(const void *ctx, const char *p);
|
||||
|
||||
The talloc_strdup() function is equivalent to:
|
||||
|
||||
ptr = talloc_size(ctx, strlen(p)+1);
|
||||
if (ptr) memcpy(ptr, p, strlen(p)+1);
|
||||
|
||||
This functions sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
char *talloc_strndup(const void *t, const char *p, size_t n);
|
||||
|
||||
The talloc_strndup() function is the talloc equivalent of the C
|
||||
library function strndup()
|
||||
|
||||
This functions sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
char *talloc_vasprintf(const void *t, const char *fmt, va_list ap);
|
||||
|
||||
The talloc_vasprintf() function is the talloc equivalent of the C
|
||||
library function vasprintf()
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
char *talloc_asprintf(const void *t, const char *fmt, ...);
|
||||
|
||||
The talloc_asprintf() function is the talloc equivalent of the C
|
||||
library function asprintf()
|
||||
|
||||
This functions sets the name of the new pointer to the passed
|
||||
string. This is equivalent to:
|
||||
talloc_set_name_const(ptr, ptr)
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
char *talloc_asprintf_append(char *s, const char *fmt, ...);
|
||||
|
||||
The talloc_asprintf_append() function appends the given formatted
|
||||
string to the given string.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc_array(const void *ctx, type, uint_t count);
|
||||
|
||||
The talloc_array() macro is equivalent to:
|
||||
|
||||
(type *)talloc_size(ctx, sizeof(type) * count);
|
||||
|
||||
except that it provides integer overflow protection for the multiply,
|
||||
returning NULL if the multiply overflows.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_array_size(const void *ctx, size_t size, uint_t count);
|
||||
|
||||
The talloc_array_size() function is useful when the type is not
|
||||
known. It operates in the same way as talloc_array(), but takes a size
|
||||
instead of a type.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);
|
||||
|
||||
The talloc_ptrtype() macro should be used when you have a pointer to an array
|
||||
and want to allocate memory of an array to point at with this pointer. When compiling
|
||||
with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()
|
||||
and talloc_get_name() will return the current location in the source file.
|
||||
and not the type.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size);
|
||||
|
||||
This is a non-macro version of talloc_realloc(), which is useful
|
||||
as libraries sometimes want a ralloc function pointer. A realloc()
|
||||
implementation encapsulates the functionality of malloc(), free() and
|
||||
realloc() in one call, which is why it is useful to be able to pass
|
||||
around a single function pointer.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_autofree_context(void);
|
||||
|
||||
This is a handy utility function that returns a talloc context
|
||||
which will be automatically freed on program exit. This can be used
|
||||
to reduce the noise in memory leak reports.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_check_name(const void *ptr, const char *name);
|
||||
|
||||
This function checks if a pointer has the specified name. If it does
|
||||
then the pointer is returned. It it doesn't then NULL is returned.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc_get_type(const void *ptr, type);
|
||||
|
||||
This macro allows you to do type checking on talloc pointers. It is
|
||||
particularly useful for void* private pointers. It is equivalent to
|
||||
this:
|
||||
|
||||
(type *)talloc_check_name(ptr, #type)
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
talloc_set_type(const void *ptr, type);
|
||||
|
||||
This macro allows you to force the name of a pointer to be a
|
||||
particular type. This can be used in conjunction with
|
||||
talloc_get_type() to do type checking on void* pointers.
|
||||
|
||||
It is equivalent to this:
|
||||
talloc_set_name_const(ptr, #type)
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
talloc_get_size(const void *ctx);
|
||||
|
||||
This function lets you know the amount of memory alloced so far by
|
||||
this context. It does NOT account for subcontext memory.
|
||||
This can be used to calculate the size of an array.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
void *talloc_find_parent_byname(const void *ctx, const char *name);
|
||||
|
||||
Find a parent memory context of the current context that has the given
|
||||
name. This can be very useful in complex programs where it may be
|
||||
difficult to pass all information down to the level you need, but you
|
||||
know the structure you want is a parent of another context.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
(type *)talloc_find_parent_bytype(ctx, type);
|
||||
|
||||
Like talloc_find_parent_byname() but takes a type, making it typesafe.
|
||||
|
1075
ctdb/lib/talloc/testsuite.c
Normal file
1075
ctdb/lib/talloc/testsuite.c
Normal file
File diff suppressed because it is too large
Load Diff
49
ctdb/lib/talloc/web/index.html
Normal file
49
ctdb/lib/talloc/web/index.html
Normal file
@ -0,0 +1,49 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>talloc</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#ffffff" TEXT="#000000" VLINK="#292555" LINK="#292555" ALINK="#cc0033">
|
||||
|
||||
<h1>talloc</h1>
|
||||
|
||||
talloc is a hierarchical pool based memory allocator with
|
||||
destructors. It is the core memory allocator used in Samba4, and has
|
||||
made a huge difference in many aspects of Samba4 development.<p>
|
||||
|
||||
To get started with talloc, I would recommend you read the <a
|
||||
href="http://samba.org/ftp/unpacked/samba4/source/lib/talloc/talloc_guide.txt">talloc guide</a>.
|
||||
|
||||
<h2>Discussion and bug reports</h2>
|
||||
|
||||
talloc does not currently have its own mailing list or bug tracking
|
||||
system. For now, please use the <a
|
||||
href="https://lists.samba.org/mailman/listinfo/samba-technical">samba-technical</a>
|
||||
mailing list, and the <a href="http://bugzilla.samba.org/">Samba
|
||||
bugzilla</a> bug tracking system.
|
||||
|
||||
<h2>Download</h2>
|
||||
|
||||
You can download the latest release either via rsync or anonymous
|
||||
svn. To fetch via svn use the following command:
|
||||
|
||||
<pre>
|
||||
svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/talloc talloc
|
||||
svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/replace libreplace
|
||||
</pre>
|
||||
|
||||
To fetch via rsync use this command:
|
||||
|
||||
<pre>
|
||||
rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/talloc .
|
||||
rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/libreplace .
|
||||
</pre>
|
||||
|
||||
<hr>
|
||||
<tiny>
|
||||
<a href="http://samba.org/~tridge/">Andrew Tridgell</a><br>
|
||||
talloc AT tridgell.net
|
||||
</tiny>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
89
ctdb/lib/tdb/Makefile.in
Normal file
89
ctdb/lib/tdb/Makefile.in
Normal file
@ -0,0 +1,89 @@
|
||||
#!gmake
|
||||
#
|
||||
# Makefile for tdb directory
|
||||
#
|
||||
|
||||
CC = @CC@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
VPATH = @srcdir@:@libreplacedir@
|
||||
srcdir = @srcdir@
|
||||
builddir = @builddir@
|
||||
CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude -I@libreplacedir@
|
||||
CFLAGS = $(CPPFLAGS) @CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
EXEEXT = @EXEEXT@
|
||||
|
||||
.PHONY: test
|
||||
|
||||
PROGS = bin/tdbtool$(EXEEXT) bin/tdbtorture$(EXEEXT)
|
||||
PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT)
|
||||
ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL)
|
||||
|
||||
TDB_OBJ = @TDBOBJ@ @LIBREPLACEOBJ@
|
||||
|
||||
DIRS = bin common tools
|
||||
|
||||
all: showflags dirs $(PROGS)
|
||||
|
||||
showflags:
|
||||
@echo 'tdb will be compiled with flags:'
|
||||
@echo ' CFLAGS = $(CFLAGS)'
|
||||
@echo ' CPPFLAGS = $(CPPFLAGS)'
|
||||
@echo ' LDFLAGS = $(LDFLAGS)'
|
||||
@echo ' LIBS = $(LIBS)'
|
||||
|
||||
.c.o:
|
||||
@echo Compiling $*.c
|
||||
@mkdir -p `dirname $@`
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
dirs:
|
||||
@mkdir -p $(DIRS)
|
||||
|
||||
install: all
|
||||
mkdir -p $(bindir)
|
||||
mkdir -p $(includedir)
|
||||
mkdir -p $(libdir)
|
||||
mkdir -p $(libdir)/pkgconfig
|
||||
cp $(PROGS) $(bindir)
|
||||
cp $(srcdir)/include/tdb.h $(includedir)
|
||||
cp tdb.pc $(libdir)/pkgconfig
|
||||
|
||||
libtdb.a: $(TDB_OBJ)
|
||||
ar -rv libtdb.a $(TDB_OBJ)
|
||||
|
||||
bin/tdbtest$(EXEEXT): tools/tdbtest.o libtdb.a
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm
|
||||
|
||||
bin/tdbtool$(EXEEXT): tools/tdbtool.o libtdb.a
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb
|
||||
|
||||
bin/tdbtorture$(EXEEXT): tools/tdbtorture.o libtdb.a
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb
|
||||
|
||||
bin/tdbdump$(EXEEXT): tools/tdbdump.o libtdb.a
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb
|
||||
|
||||
bin/tdbbackup$(EXEEXT): tools/tdbbackup.o libtdb.a
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb
|
||||
|
||||
test: bin/tdbtorture$(EXEEXT)
|
||||
bin/tdbtorture$(EXEEXT)
|
||||
|
||||
installcheck: test install
|
||||
|
||||
clean:
|
||||
rm -f $(ALL_PROGS) *.o *.a common/*.o tools/*.o tdb.pc
|
||||
rm -f test.db test.tdb torture.tdb test.gdbm
|
||||
|
||||
distclean: clean
|
||||
rm -f *~ */*~
|
||||
rm -f config.log config.status include/config.h config.cache
|
||||
rm -f Makefile
|
||||
|
||||
realdistclean: distclean
|
||||
rm -f configure include/config.h.in
|
1
ctdb/lib/tdb/aclocal.m4
vendored
Normal file
1
ctdb/lib/tdb/aclocal.m4
vendored
Normal file
@ -0,0 +1 @@
|
||||
m4_include(libreplace.m4)
|
14
ctdb/lib/tdb/autogen.sh
Executable file
14
ctdb/lib/tdb/autogen.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf autom4te.cache
|
||||
rm -f configure config.h.in
|
||||
|
||||
IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace"
|
||||
autoconf $IPATHS || exit 1
|
||||
autoheader $IPATHS || exit 1
|
||||
|
||||
rm -rf autom4te.cache
|
||||
|
||||
echo "Now run ./configure and then make."
|
||||
exit 0
|
||||
|
1466
ctdb/lib/tdb/config.guess
vendored
Executable file
1466
ctdb/lib/tdb/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
70
ctdb/lib/tdb/config.mk
Normal file
70
ctdb/lib/tdb/config.mk
Normal file
@ -0,0 +1,70 @@
|
||||
################################################
|
||||
# Start SUBSYSTEM LIBTDB
|
||||
[LIBRARY::LIBTDB]
|
||||
VERSION = 0.0.1
|
||||
SO_VERSION = 0
|
||||
DESCRIPTION = Trivial Database Library
|
||||
OBJ_FILES = \
|
||||
common/tdb.o common/dump.o common/io.o common/lock.o \
|
||||
common/open.o common/traverse.o common/freelist.o \
|
||||
common/error.o common/transaction.o
|
||||
CFLAGS = -Ilib/tdb/include
|
||||
PUBLIC_HEADERS = include/tdb.h
|
||||
#
|
||||
# End SUBSYSTEM ldb
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Start BINARY tdbtool
|
||||
[BINARY::tdbtool]
|
||||
INSTALLDIR = BINDIR
|
||||
ENABLE = NO
|
||||
OBJ_FILES= \
|
||||
tools/tdbtool.o
|
||||
PRIVATE_DEPENDENCIES = \
|
||||
LIBTDB
|
||||
# End BINARY tdbtool
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Start BINARY tdbtorture
|
||||
[BINARY::tdbtorture]
|
||||
INSTALLDIR = BINDIR
|
||||
OBJ_FILES= \
|
||||
tools/tdbtorture.o
|
||||
PRIVATE_DEPENDENCIES = \
|
||||
LIBTDB
|
||||
# End BINARY tdbtorture
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Start BINARY tdbdump
|
||||
[BINARY::tdbdump]
|
||||
INSTALLDIR = BINDIR
|
||||
OBJ_FILES= \
|
||||
tools/tdbdump.o
|
||||
PRIVATE_DEPENDENCIES = \
|
||||
LIBTDB
|
||||
# End BINARY tdbdump
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Start BINARY tdbbackup
|
||||
[BINARY::tdbbackup]
|
||||
INSTALLDIR = BINDIR
|
||||
ENABLE = NO
|
||||
OBJ_FILES= \
|
||||
tools/tdbbackup.o
|
||||
PRIVATE_DEPENDENCIES = \
|
||||
LIBTDB
|
||||
# End BINARY tdbbackup
|
||||
################################################
|
||||
|
||||
#######################
|
||||
# Start LIBRARY swig_tdb
|
||||
[LIBRARY::swig_tdb]
|
||||
LIBRARY_REALNAME = swig/_tdb.$(SHLIBEXT)
|
||||
OBJ_FILES = swig/tdb_wrap.o
|
||||
PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG
|
||||
# End LIBRARY swig_tdb
|
||||
#######################
|
1579
ctdb/lib/tdb/config.sub
vendored
Executable file
1579
ctdb/lib/tdb/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
10
ctdb/lib/tdb/configure.ac
Normal file
10
ctdb/lib/tdb/configure.ac
Normal file
@ -0,0 +1,10 @@
|
||||
AC_PREREQ(2.50)
|
||||
AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
|
||||
AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
|
||||
AC_DEFUN([SMB_ENABLE], [echo -n ""])
|
||||
AC_INIT(include/tdb.h)
|
||||
AC_CONFIG_SRCDIR([common/tdb.c])
|
||||
AC_CONFIG_HEADER(include/config.h)
|
||||
AC_LIBREPLACE_ALL_CHECKS
|
||||
m4_include(libtdb.m4)
|
||||
AC_OUTPUT(Makefile tdb.pc)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user