X-Git-Url: https://git.jankratochvil.net/?a=blobdiff_plain;f=include%2Fmisc.h;fp=include%2Fmisc.h;h=5581450c4038b26ef6d6a631a13f38bb40fdafe3;hb=2a6284cf1a380b55f3ad2bf71a63946e2595b812;hp=3e91ff0eb6cef6852522127efd216662699df8c4;hpb=9d80f3acb04fd990119dbefc10aaf5a56de13ea9;p=gnokii.git diff --git a/include/misc.h b/include/misc.h index 3e91ff0..5581450 100644 --- a/include/misc.h +++ b/include/misc.h @@ -13,6 +13,14 @@ Header file for miscellaneous defines, typedefs etc. $Log$ + Revision 1.1.1.1.6.1 2001/11/25 23:04:51 short + * new common/misc.c/ + * g{,v}asprintf() - "asprintf()" compatibility emulation + * ARRAY_LEN() - sizeof(x)/sizeof(*x) + * SAFE_STRNCPY{,_SIZEOF}() - strncpy with variable-size autodetection + * G_GNUC_PRINTF - GCC attribute from glib + * N_(x) - missing in localization macros + Revision 1.1.1.1 2001/11/25 21:59:21 short :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001 @@ -48,6 +56,28 @@ #define bool int #endif +#define ARRAY_LEN(x) (sizeof((x))/sizeof((x)[0])) + +#define SAFE_STRNCPY(dest,src,n) do { \ + strncpy((dest),(src),(n)); \ + if ((n)>0) \ + (dest)[(n)-1]='\0'; \ + } while (0) + +#define SAFE_STRNCPY_SIZEOF(dest,src) \ + SAFE_STRNCPY((dest),(src),sizeof((dest))) + +/* Stolen from : */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((format (printf, format_idx, arg_idx))) +#else /* !__GNUC__ */ +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif /* !__GNUC__ */ + +#define GNOKII_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define GNOKII_MIN(a, b) (((a) < (b)) ? (a) : (b)) + /* A define to make debug printfs neat */ #ifndef DEBUG #define dprintf(a...) do { } while (0) @@ -61,6 +91,23 @@ #else # define gsprintf(a, b, c...) sprintf(a, c) #endif +#ifdef HAVE_VSNPRINTF +# define gvsprintf(a, b, c...) vsnprintf(a, b, c) +#else +# define gvsprintf(a, b, c...) vsprintf(a, c) +#endif +#ifdef HAVE_ASPRINTF +# define gasprintf(a...) asprintf(a) +#else +#include +extern int gasprintf(char **destp,const char *fmt,...); +#endif +#ifdef HAVE_VASPRINTF +# define gvasprintf(a...) vasprintf(a) +#else +#include +extern int gvasprintf(char **destp,const char *fmt,va_list ap); +#endif /* Get rid of long defines. Use #if __unices__ */ #define __unices__ defined(__svr4__) || defined(__FreeBSD__) || defined(__bsdi__) @@ -76,6 +123,7 @@ #else #define _(x) (x) #endif /* USE_NLS */ +#define N_(x) (x) /* Definitions for u8, u16, u32 and u64, borrowed from /usr/src/linux/include/asm-i38/types.h */