defs.h   defs.h 
skipping to change at line 82 skipping to change at line 82
__builtin_types_compatible_p(a, const unsigned char *), \ __builtin_types_compatible_p(a, const unsigned char *), \
/* and if it has none... */ \ /* and if it has none... */ \
__builtin_types_compatible_p(a, const char *) || \ __builtin_types_compatible_p(a, const char *) || \
__builtin_types_compatible_p(a, const signed char *) || \ __builtin_types_compatible_p(a, const signed char *) || \
__builtin_types_compatible_p(a, const unsigned char *) || \ __builtin_types_compatible_p(a, const unsigned char *) || \
__builtin_types_compatible_p(a, char *) || \ __builtin_types_compatible_p(a, char *) || \
__builtin_types_compatible_p(a, signed char *) || \ __builtin_types_compatible_p(a, signed char *) || \
__builtin_types_compatible_p(a, unsigned char *) \ __builtin_types_compatible_p(a, unsigned char *) \
) )
# if defined(__GNUC__) && !defined(signed_cast) # if defined(__GNUC__) && !defined(__clang__) && !defined(signed_cast)
# define signed_cast(type, expr) ({ \ # define signed_cast(type, expr) ({ \
BUILD_BUG_ON(!__signed_cast_compatible(__typeof__(ty pe), __typeof__(expr))); \ BUILD_BUG_ON(!__signed_cast_compatible(__typeof__(ty pe), __typeof__(expr))); \
(type)(expr); \ (type)(expr); \
}) })
# endif # endif
# if defined(__GNUC__) && !defined(static_cast) # if defined(__GNUC__) && !defined(__clang__) && !defined(static_cast)
# define static_cast(type, expr) \ # define static_cast(type, expr) \
((struct { type x; }){(expr)}.x) ((struct { type x; }){(expr)}.x)
# endif # endif
# if defined(__GNUC__) && !defined(const_cast1) # if defined(__GNUC__) && !defined(__clang__) && !defined(const_cast1)
# define __const_cast_strip1(expr) \ # define __const_cast_strip1(expr) \
__typeof__(*(struct { int z; __typeof__(expr) x; }){ 0}.x) __typeof__(*(union { int z; __typeof__(expr) x; }){0 }.x)
# define __const_cast_strip2(expr) \ # define __const_cast_strip2(expr) \
__typeof__(**(struct { int z; __typeof__(expr) x; }) {0}.x) __typeof__(**(union { int z; __typeof__(expr) x; }){ 0}.x)
# define __const_cast_strip3(expr) \ # define __const_cast_strip3(expr) \
__typeof__(***(struct { int z; __typeof__(expr) x; } ){0}.x) __typeof__(***(union { int z; __typeof__(expr) x; }) {0}.x)
# define const_cast1(new_type, expr) ({ \ # define const_cast1(new_type, expr) ({ \
BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip1(expr), __const_cast_strip1(new_type))); \ BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip1(expr), __const_cast_strip1(new_type))); \
(new_type)(expr); \ (new_type)(expr); \
}) })
# define const_cast2(new_type, expr) ({ \ # define const_cast2(new_type, expr) ({ \
BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip2(expr), __const_cast_strip2(new_type))); \ BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip2(expr), __const_cast_strip2(new_type))); \
(new_type)(expr); \ (new_type)(expr); \
}) })
# define const_cast3(new_type, expr) ({ \ # define const_cast3(new_type, expr) ({ \
BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip3(expr), __const_cast_strip3(new_type))); \ BUILD_BUG_ON(!__builtin_types_compatible_p(__const_c ast_strip3(expr), __const_cast_strip3(new_type))); \
 End of changes. 6 change blocks. 
6 lines changed or deleted 6 lines changed or added


 io.h   io.h 
skipping to change at line 35 skipping to change at line 35
HX_REALPATH_SELF | HX_REALPATH_PARENT | HX_REALPATH_SYMLINK, HX_REALPATH_SELF | HX_REALPATH_PARENT | HX_REALPATH_SYMLINK,
}; };
struct HXdir; struct HXdir;
extern struct HXdir *HXdir_open(const char *); extern struct HXdir *HXdir_open(const char *);
extern const char *HXdir_read(struct HXdir *); extern const char *HXdir_read(struct HXdir *);
extern void HXdir_close(struct HXdir *); extern void HXdir_close(struct HXdir *);
extern int HX_copy_dir(const char *, const char *, unsigned int, ...); extern int HX_copy_dir(const char *, const char *, unsigned int, ...);
extern int HX_copy_file(const char *, const char *, unsigned int, ...); extern int HX_copy_file(const char *, const char *, unsigned int, ...);
extern int HX_mkdir(const char *); extern int HX_mkdir(const char *, unsigned int);
extern int HX_readlink(hxmc_t **, const char *); extern int HX_readlink(hxmc_t **, const char *);
extern int HX_realpath(hxmc_t **, const char *, unsigned int); extern int HX_realpath(hxmc_t **, const char *, unsigned int);
extern int HX_rrmdir(const char *); extern int HX_rrmdir(const char *);
extern ssize_t HXio_fullread(int, void *, size_t); extern ssize_t HXio_fullread(int, void *, size_t);
extern ssize_t HXio_fullwrite(int, const void *, size_t); extern ssize_t HXio_fullwrite(int, const void *, size_t);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 map.h   map.h 
skipping to change at line 49 skipping to change at line 49
* %HXMAP_NONE: mnemonic for no flags * %HXMAP_NONE: mnemonic for no flags
* %HXMAP_SINGULAR: Instead of an associative map, provide a set * %HXMAP_SINGULAR: Instead of an associative map, provide a set
* %HXMAP_SKEY: Key will be a C-style string (sets ops->k_*) * %HXMAP_SKEY: Key will be a C-style string (sets ops->k_*)
* %HXMAP_CKEY: Make a copy of the key on HXmap_add * %HXMAP_CKEY: Make a copy of the key on HXmap_add
* %HXMAP_SDATA: Data will be a C-style string (presets ops->d_*) * %HXMAP_SDATA: Data will be a C-style string (presets ops->d_*)
* %HXMAP_CDATA: Make a copy of the data on HXmap_add * %HXMAP_CDATA: Make a copy of the data on HXmap_add
*/ */
enum { enum {
HXMAP_NONE = 0, HXMAP_NONE = 0,
HXMAP_NOREPLACE = 1 << 0, HXMAP_NOREPLACE = 1 << 0,
HXMAP_SINGULAR = 1 << 27, HXMAP_SINGULAR = 1 << 1,
HXMAP_SKEY = 1 << 28, HXMAP_SKEY = 1 << 2,
HXMAP_CKEY = 1 << 29, HXMAP_CKEY = 1 << 3,
HXMAP_SDATA = 1 << 30, HXMAP_SDATA = 1 << 4,
HXMAP_CDATA = 1 << 31, HXMAP_CDATA = 1 << 5,
HXMAP_SCKEY = HXMAP_SKEY | HXMAP_CKEY, HXMAP_SCKEY = HXMAP_SKEY | HXMAP_CKEY,
HXMAP_SCDATA = HXMAP_SDATA | HXMAP_CDATA, HXMAP_SCDATA = HXMAP_SDATA | HXMAP_CDATA,
}; };
/** /**
* Flags for the traverser * Flags for the traverser
* %HXMAP_NOFLAGS: Mnemonic for no flags * %HXMAP_NOFLAGS: Mnemonic for no flags
* %HXMAP_DTRAV: Support deletion of elements while traversing * %HXMAP_DTRAV: Support deletion of elements while traversing
*/ */
 End of changes. 1 change blocks. 
5 lines changed or deleted 5 lines changed or added


 option.h   option.h 
skipping to change at line 30 skipping to change at line 30
struct HXoption; struct HXoption;
/* /*
* FORMAT.C * FORMAT.C
*/ */
extern struct HXformat_map *HXformat_init(void); extern struct HXformat_map *HXformat_init(void);
extern void HXformat_free(struct HXformat_map *); extern void HXformat_free(struct HXformat_map *);
extern int HXformat_add(struct HXformat_map *, const char *, const void *, extern int HXformat_add(struct HXformat_map *, const char *, const void *,
unsigned int); unsigned int);
extern int HXformat2_aprintf(const struct HXformat_map *, extern int HXformat_aprintf(const struct HXformat_map *,
hxmc_t **, const char *); hxmc_t **, const char *);
extern int HXformat2_sprintf(const struct HXformat_map *, extern int HXformat_sprintf(const struct HXformat_map *,
char *, size_t, const char *); char *, size_t, const char *);
extern int HXformat2_fprintf(const struct HXformat_map *, extern int HXformat_fprintf(const struct HXformat_map *,
FILE *, const char *); FILE *, const char *);
/* /*
* OPT.C * OPT.C
*/ */
enum {
/* .type */ /**
* Available types for struct HXoption.type.
* %HXTYPE_NONE: [-o] (int *) No argument; counts presence.
* %HXTYPE_VAL: [-o] (int *) Set to value in .val.
* %HXTYPE_SVAL: [-o] (const char *) Set to value in .uptr.
* %HXTYPE_BOOL: [fo] (int *) Parse argument as boolean
* ("yes", "no", "true", "false", 0 or non-zero)
* %HXTYPE_BYTE: [fo] (unsigned char *) Take first char of argument
* %HXTYPE_UCHAR: [fo] (unsigned char *) An integer.
* %HXTYPE_CHAR: [fo] (char *) An integer.
* %HXTYPE_USHORT: [fo] (unsigned short *) An integer.
* %HXTYPE_SHORT: [fo] (short *) An integer.
* %HXTYPE_UINT: [fo] (unsigned int *) An integer.
* %HXTYPE_INT: [fo] (int *) An integer.
* %HXTYPE_ULONG: [fo] (unsigned long *) An integer.
* %HXTYPE_LONG: [fo] (long *) An integer.
* %HXTYPE_ULLONG: [fo] (unsigned long long *) An integer.
* %HXTYPE_LLONG: [fo] (long long *) An integer.
* %HXTYPE_FLOAT: [fo] (float *) Read a floating point number
* %HXTYPE_DOUBLE: [fo] (double *) Read a floating point number
* %HXTYPE_STRING: [fo] (char **) Any string.
* %HXTYPE_STRP: [f-] (const char *const *) A string.
* %HXTYPE_STRDQ: [-o] (struct HXdeque *) A string.
* %HXTYPE_UINT8: [-o] (uint8_t *) An integer.
* %HXTYPE_UINT16: [-o] (uint8_t *) An integer.
* %HXTYPE_UINT32: [-o] (uint8_t *) An integer.
* %HXTYPE_UINT64: [-o] (uint8_t *) An integer.
* %HXTYPE_INT8: [-o] (uint8_t *) An integer.
* %HXTYPE_INT16: [-o] (uint8_t *) An integer.
* %HXTYPE_INT32: [-o] (uint8_t *) An integer.
* %HXTYPE_INT64: [-o] (uint8_t *) An integer.
* %HXTYPE_MCSTR: [-o] (hxmc_t *) A string.
* %HXTYPE_XSNTMARK: [-o] Internal sentinal marker (used in HXOPT_TABLEEN
D)
* %HXTYPE_XHELP: [-o] Internal helper marker (used in HXOPT_AUTOHELP)
*
* Type expected of struct HXoption.ptr is given in ().
* HX_getopt (o) and HXformat_* (f) support different sets, marked with [].
*/
enum HX_option_type {
HXTYPE_NONE = 0, HXTYPE_NONE = 0,
/* for opt: set specific integer value */
HXTYPE_VAL, HXTYPE_VAL,
/* for opt: set specific string value */
HXTYPE_SVAL, HXTYPE_SVAL,
/*
* accept a string "yes", "no", "true", "false" and
* put into *(unsigned int*)
*/
HXTYPE_BOOL, HXTYPE_BOOL,
/* read _one byte_ and put it into *(unsigned char *) */
HXTYPE_BYTE, HXTYPE_BYTE,
/* read an integer/float (sscanf %d/%o/%x/%f) */ HXTYPE_UCHAR, /* 5 */
HXTYPE_UCHAR,
HXTYPE_CHAR, HXTYPE_CHAR,
HXTYPE_USHORT, HXTYPE_USHORT,
HXTYPE_SHORT, HXTYPE_SHORT,
HXTYPE_UINT, HXTYPE_UINT,
HXTYPE_INT, HXTYPE_INT, /* 10 */
HXTYPE_ULONG, HXTYPE_ULONG,
HXTYPE_LONG, HXTYPE_LONG,
HXTYPE_ULLONG, HXTYPE_ULLONG,
HXTYPE_LLONG, HXTYPE_LLONG,
HXTYPE_FLOAT, HXTYPE_FLOAT, /* 15 */
HXTYPE_DOUBLE, HXTYPE_DOUBLE,
/* read string and put into *(const char **) */
HXTYPE_STRING, HXTYPE_STRING,
HXTYPE_STRP, /* (const char **) */ HXTYPE_STRP, /* (const char **) */
HXTYPE_STRDQ, HXTYPE_STRDQ,
HXTYPE_UINT8, HXTYPE_UINT8, /* 20 */
HXTYPE_UINT16, HXTYPE_UINT16,
HXTYPE_UINT32, HXTYPE_UINT32,
HXTYPE_UINT64, HXTYPE_UINT64,
HXTYPE_INT8, HXTYPE_INT8,
HXTYPE_INT16, HXTYPE_INT16, /* 25 */
HXTYPE_INT32, HXTYPE_INT32,
HXTYPE_INT64, HXTYPE_INT64,
HXTYPE_MCSTR, /* put into hxmc_t */ HXTYPE_MCSTR,
HXTYPE_XSNTMARK, /* sentinel marker */ HXTYPE_XSNTMARK,
HXTYPE_XHELP, /* 30 */
};
/* .type extra flags */ /**
/* argument is optional */ * Extra flags to be OR'ed into struct HXoption.type.
* %HXOPT_OPTIONAL: argument to option is optional
* (it's bad taste to use this)
* %HXOPT_INC: increase variable pointed to by .ptr.
* (only applies to %HXTYPE_NONE)
* %HXOPT_DEC: increase variable pointed to by .ptr.
* (only applies to %HXTYPE_NONE)
* %HXOPT_NOT: negate input (*ptr), this is done before OR/AND
* %HXOPT_OR: OR *ptr by argument
* %HXOPT_AND: AND *ptr by argument
* %HXOPT_XOR: XOR *ptr by argument
*/
enum {
HXOPT_OPTIONAL = 1 << 6, HXOPT_OPTIONAL = 1 << 6,
/* increase pointed variable */
HXOPT_INC = 1 << 7, HXOPT_INC = 1 << 7,
/* decrease pointed variable */
HXOPT_DEC = 1 << 8, HXOPT_DEC = 1 << 8,
/* negate input first */
HXOPT_NOT = 1 << 9, HXOPT_NOT = 1 << 9,
/* or pointed variable with input */
HXOPT_OR = 1 << 10, HXOPT_OR = 1 << 10,
/* and pointed variable with input */
HXOPT_AND = 1 << 11, HXOPT_AND = 1 << 11,
/* xor pointed variable with input */
HXOPT_XOR = 1 << 12, HXOPT_XOR = 1 << 12,
HXFORMAT_IMMED = 1 << 13, };
/* HX_getopt() flags */ /**
* Flags (4th arg) to HX_getopt.
* %HXOPT_PTHRU: pass-through unknown options to new argv
* %HXOPT_DESTROY_OLD: destroy old argv after parsing is successful
* %HXOPT_QUIET: do not output any warnings to stderr
* %HXOPT_HELPONERR: print out help when a parsing error occurs
* %HXOPT_USAGEONERR: print out short usage when a parsing error occurs
*/
enum {
HXOPT_PTHRU = 1 << 0, HXOPT_PTHRU = 1 << 0,
HXOPT_DESTROY_OLD = 1 << 1, HXOPT_DESTROY_OLD = 1 << 1,
HXOPT_QUIET = 1 << 2, HXOPT_QUIET = 1 << 2,
HXOPT_HELPONERR = 1 << 3, HXOPT_HELPONERR = 1 << 3,
HXOPT_USAGEONERR = 1 << 4, HXOPT_USAGEONERR = 1 << 4,
};
/* Return types for HX_getopt() */ /**
HXOPT_ERR_UNKN = 1, * (Positive-ranged) return values for HX_getopt.
* %HXOPT_ERR_SUCCESS: success
* %HXOPT_ERR_UNKN: unknown option was encountered
* %HXOPT_ERR_VOID: long option takes no value
* %HXOPT_ERR_MIS: option requires a value argument
*/
enum {
HXOPT_ERR_SUCCESS = 0,
HXOPT_ERR_UNKN,
HXOPT_ERR_VOID, HXOPT_ERR_VOID,
HXOPT_ERR_MIS, HXOPT_ERR_MIS,
};
SHCONF_ONE = 1 << 0, /* only read one configuration file */ /**
* Extra flags to be OR'ed into HXformat_add()'s 4th arg.
* %HXFORMAT_IMMED: do not dereference the 4th arg to get at the value
*/
enum {
HXFORMAT_IMMED = 1 << 13,
};
/**
* Flags for HX_shconfig_pv()
* %SHCONF_ONE: only read one configuration file
*/
enum {
SHCONF_ONE = 1 << 0,
};
/**
* Flags in struct HXoptcb.flags
* %HXOPTCB_BY_LONG: cb was called by invocation of @current->ln
* %HXOPTCB_BY_SHORT: cb was called by invocation of @current->sh
*/
enum {
HXOPTCB_BY_LONG = 1 << 0,
HXOPTCB_BY_SHORT = 1 << 1,
}; };
struct HXoptcb { struct HXoptcb {
const char *arg0;
const struct HXoption *table, *current; const struct HXoption *table, *current;
const char *data; const char *data;
union { union {
double data_dbl; double data_dbl;
long data_long; long data_long;
}; };
const char *match_ln; unsigned int flags;
char match_sh;
}; };
/**
* @ln: long option string (without "--"), or %NULL
* @sh: short option character, or '\0'
* @type: type of variable pointed to by .ptr
* @ptr: pointer to variable to set/update
* @uptr: freeform user-supplied pointer;
* in case of %HXTYPE_SVAL, this is the specific value to set
* @cb: callback function to invoke, or %NULL
* @val: specific value to set if type == HXTYPE_VAL
* @help: help string to display
* @htyp: type string to show in option's help
*/
struct HXoption { struct HXoption {
const char *ln; const char *ln;
char sh; char sh;
unsigned int type; unsigned int type;
void *ptr, *uptr; void *ptr, *uptr;
void (*cb)(const struct HXoptcb *); void (*cb)(const struct HXoptcb *);
int val; int val;
const char *sval, *help, *htyp; const char *help, *htyp;
}; };
extern int HX_getopt(const struct HXoption *, int *, const char ***, extern int HX_getopt(const struct HXoption *, int *, const char ***,
unsigned int); unsigned int);
extern void HX_getopt_help(const struct HXoptcb *, FILE *); extern void HX_getopt_help(const struct HXoptcb *, FILE *);
extern void HX_getopt_help_cb(const struct HXoptcb *); extern void HX_getopt_help_cb(const struct HXoptcb *);
extern void HX_getopt_usage(const struct HXoptcb *, FILE *); extern void HX_getopt_usage(const struct HXoptcb *, FILE *);
extern void HX_getopt_usage_cb(const struct HXoptcb *); extern void HX_getopt_usage_cb(const struct HXoptcb *);
extern int HX_shconfig(const char *, const struct HXoption *); extern int HX_shconfig(const char *, const struct HXoption *);
extern struct HXmap *HX_shconfig_map(const char *); extern struct HXmap *HX_shconfig_map(const char *);
extern int HX_shconfig_pv(const char **, const char *, extern int HX_shconfig_pv(const char **, const char *,
const struct HXoption *, unsigned int); const struct HXoption *, unsigned int);
extern void HX_shconfig_free(const struct HXoption *); extern void HX_shconfig_free(const struct HXoption *);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#ifndef __cplusplus #ifndef __cplusplus
# define HXOPT_AUTOHELP \ # define HXOPT_AUTOHELP \
{.ln = "help", .sh = '?', .type = HXTYPE_NONE, \ {.ln = "help", .sh = '?', .type = HXTYPE_XHELP, \
.cb = HX_getopt_help_cb, .help = "Show this help message"}, \ .cb = HX_getopt_help_cb, .help = "Show this help message"}, \
{.ln = "usage", .type = HXTYPE_NONE, \ {.ln = "usage", .type = HXTYPE_NONE, \
.cb = HX_getopt_usage_cb, \ .cb = HX_getopt_usage_cb, \
.help = "Display brief usage message"} .help = "Display brief usage message"}
# define HXOPT_TABLEEND {.type = HXTYPE_XSNTMARK} # define HXOPT_TABLEEND {.type = HXTYPE_XSNTMARK}
#else #else
# define HXOPT_AUTOHELP \ # define HXOPT_AUTOHELP \
{NULL, '?', HXTYPE_NONE, NULL, NULL, HX_getopt_help_cb, \ {NULL, '?', HXTYPE_XHELP, NULL, NULL, HX_getopt_help_cb, \
0, NULL, "Show this help message"} 0, "Show this help message"}
# define HXOPT_TABLEEND {NULL, 0, HXTYPE_XSNTMARK} # define HXOPT_TABLEEND {NULL, 0, HXTYPE_XSNTMARK}
#endif #endif
#endif /* _LIBHX_OPTION_H */ #endif /* _LIBHX_OPTION_H */
 End of changes. 34 change blocks. 
41 lines changed or deleted 130 lines changed or added


 string.h   string.h 
skipping to change at line 70 skipping to change at line 70
extern char *HX_basename_exact(const char *); extern char *HX_basename_exact(const char *);
extern char *HX_chomp(char *); extern char *HX_chomp(char *);
extern char *HX_dirname(const char *); extern char *HX_dirname(const char *);
extern hxmc_t *HX_getl(hxmc_t **, FILE *); extern hxmc_t *HX_getl(hxmc_t **, FILE *);
extern void *HX_memmem(const void *, size_t, const void *, size_t); extern void *HX_memmem(const void *, size_t, const void *, size_t);
extern char **HX_split(const char *, const char *, int *, int); extern char **HX_split(const char *, const char *, int *, int);
extern char **HX_split4(char *, const char *, int *, int); extern char **HX_split4(char *, const char *, int *, int);
extern int HX_split5(char *, const char *, int, char **); extern int HX_split5(char *, const char *, int, char **);
extern char *HX_strbchr(const char *, const char *, char); extern char *HX_strbchr(const char *, const char *, char);
extern char *HX_strclone(char **, const char *); extern char *HX_strclone(char **, const char *);
extern char *HX_strdup(const char *);
extern char *HX_strlcat(char *, const char *, size_t);
extern char *HX_strlcpy(char *, const char *, size_t);
extern char *HX_strlncat(char *, const char *, size_t, size_t);
extern char *HX_strlower(char *); extern char *HX_strlower(char *);
extern size_t HX_strltrim(char *); extern size_t HX_strltrim(char *);
extern char *HX_strmid(const char *, long, long); extern char *HX_strmid(const char *, long, long);
extern char *HX_strndup(const char *, size_t);
extern size_t HX_strnlen(const char *, size_t);
extern char *HX_strquote(const char *, unsigned int, char **); extern char *HX_strquote(const char *, unsigned int, char **);
extern size_t HX_strrcspn(const char *, const char *); extern size_t HX_strrcspn(const char *, const char *);
extern char *HX_strrev(char *); extern char *HX_strrev(char *);
extern size_t HX_strrtrim(char *); extern size_t HX_strrtrim(char *);
extern char *HX_strsep(char **, const char *); extern char *HX_strsep(char **, const char *);
extern char *HX_strsep2(char **, const char *); extern char *HX_strsep2(char **, const char *);
extern char *HX_strupper(char *); extern char *HX_strupper(char *);
static inline char *HX_strlcat(char *dest, const char *src, size_t len)
{
ssize_t x = len - strlen(dest) - 1;
if (x <= 0)
return dest;
return strncat(dest, src, x);
}
static inline char *HX_strlcpy(char *dest, const char *src, size_t n)
{
strncpy(dest, src, n);
dest[n-1] = '\0';
return dest;
}
static inline char *HX_strlncat(char *dest, const char *src, size_t dlen,
size_t slen)
{
ssize_t x = dlen - strlen(dest) - 1;
if (x <= 0)
return dest;
x = ((ssize_t)slen < x) ? (ssize_t)slen : x;
return strncat(dest, src, x);
}
static inline void *HX_memdup(const void *buf, size_t len) static inline void *HX_memdup(const void *buf, size_t len)
{ {
void *ret; void *ret;
if ((ret = malloc(len)) == NULL) if ((ret = malloc(len)) == NULL)
return NULL; return NULL;
return memcpy(ret, buf, len); return memcpy(ret, buf, len);
} }
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
skipping to change at line 130 skipping to change at line 111
template<typename type> static inline type template<typename type> static inline type
HX_memdup(const void *data, size_t n) HX_memdup(const void *data, size_t n)
{ {
return reinterpret_cast<type>(HX_memdup(data, n)); return reinterpret_cast<type>(HX_memdup(data, n));
} }
} /* extern "C++" */ } /* extern "C++" */
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
static inline char *HX_strdup(const char *src)
{
if (src == NULL)
return NULL;
#ifdef __cplusplus
return HX_memdup<char *>(src, strlen(src) + 1);
#else
return HX_memdup(src, strlen(src) + 1);
#endif
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _LIBHX_STRING_H */ #endif /* _LIBHX_STRING_H */
 End of changes. 4 change blocks. 
44 lines changed or deleted 6 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/