* new common/misc.c/
[gnokii.git] / include / misc.h
index 3e91ff0..5581450 100644 (file)
   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
 
   #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 <glib.h>: */
+#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)
 #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 <stdarg.h>
+extern int gasprintf(char **destp,const char *fmt,...);
+#endif
+#ifdef HAVE_VASPRINTF
+# define gvasprintf(a...) vasprintf(a)
+#else
+#include <stdarg.h>
+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__)
 #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 */