lib: replace: snprintf - Fix length calculation for hex/octal 64-bit values.
[sfrench/samba-autobuild/.git] / lib / replace / replace.h
index bbea0fc77481057e7c08b16e06f6fa874752bead..7080373342a13a541549bed6395d31ec78b35afb 100644 (file)
 #include <stdarg.h>
 #include <errno.h>
 
+#ifndef HAVE_DECL_EWOULDBLOCK
+#define EWOULDBLOCK EAGAIN
+#endif
+
 #if defined(_MSC_VER) || defined(__MINGW32__)
 #include "win32_replace.h"
 #endif
 
 
-#ifdef HAVE_STDINT_H
+#ifdef HAVE_INTTYPES_H
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#elif 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
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
 #endif
 
 #ifdef HAVE_MALLOC_H
 # define PRIu64                __PRI64_PREFIX "u"
 #endif
 
+#ifndef SCNd8
+# define SCNd8         "hhd"
+#endif
+#ifndef SCNd16
+# define SCNd16                "hd"
+#endif
+#ifndef SCNd32
+# define SCNd32                "d"
+#endif
+#ifndef SCNd64
+# define SCNd64                __PRI64_PREFIX "d"
+#endif
+
+#ifndef SCNi8
+# define SCNi8         "hhi"
+#endif
+#ifndef SCNi16
+# define SCNi16                "hi"
+#endif
+#ifndef SCNi32
+# define SCNi32                "i"
+#endif
+#ifndef SCNi64
+# define SCNi64                __PRI64_PREFIX "i"
+#endif
+
+#ifndef SCNu8
+# define SCNu8         "hhu"
+#endif
+#ifndef SCNu16
+# define SCNu16                "hu"
+#endif
+#ifndef SCNu32
+# define SCNu32                "u"
+#endif
+#ifndef SCNu64
+# define SCNu64                __PRI64_PREFIX "u"
+#endif
+
 #ifdef HAVE_BSD_STRING_H
 #include <bsd/string.h>
 #endif
@@ -306,6 +349,11 @@ void rep_setlinebuf(FILE *);
 char *rep_strcasestr(const char *haystack, const char *needle);
 #endif
 
+#ifndef HAVE_STRSEP
+#define strsep rep_strsep
+char *rep_strsep(char **pps, const char *delim);
+#endif
+
 #ifndef HAVE_STRTOK_R
 #define strtok_r rep_strtok_r
 char *rep_strtok_r(char *s, const char *delim, char **save_ptr);
@@ -376,18 +424,8 @@ int rep_dlclose(void *handle);
 /* prototype is in system/network.h */
 #endif
 
-#ifndef HAVE_VDPRINTF
-#define vdprintf rep_vdprintf
-int rep_vdprintf(int fd, const char *format, va_list ap);
-#endif
-
-#ifndef HAVE_DPRINTF
-#define dprintf rep_dprintf
-int rep_dprintf(int fd, const char *format, ...);
-#endif
-
 #ifndef PRINTF_ATTRIBUTE
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#ifdef HAVE___ATTRIBUTE__
 /** 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
@@ -399,14 +437,24 @@ int rep_dprintf(int fd, const char *format, ...);
 #endif
 
 #ifndef _DEPRECATED_
-#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#ifdef HAVE___ATTRIBUTE__
 #define _DEPRECATED_ __attribute__ ((deprecated))
 #else
 #define _DEPRECATED_
 #endif
 #endif
 
-#ifndef HAVE_VASPRINTF
+#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define vdprintf rep_vdprintf
+int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
+#endif
+
+#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define dprintf rep_dprintf
+int rep_dprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
+#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
 #define vasprintf rep_vasprintf
 int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
 #endif
@@ -421,11 +469,29 @@ int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
 int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
 #endif
 
-#ifndef HAVE_ASPRINTF
+#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
 #define asprintf rep_asprintf
 int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
 #endif
 
+#if !defined(HAVE_C99_VSNPRINTF)
+#ifdef REPLACE_BROKEN_PRINTF
+/*
+ * We do not redefine printf by default
+ * as it breaks the build if system headers
+ * use __attribute__((format(printf, 3, 0)))
+ * instead of __attribute__((format(__printf__, 3, 0)))
+ */
+#define printf rep_printf
+#endif
+int rep_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
+#endif
+
+#if !defined(HAVE_C99_VSNPRINTF)
+#define fprintf rep_fprintf
+int rep_fprintf(FILE *stream, const char *, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
 #ifndef HAVE_VSYSLOG
 #ifdef HAVE_SYSLOG
 #define vsyslog rep_vsyslog
@@ -552,8 +618,7 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
 char *rep_get_current_dir_name(void);
 #endif
 
-#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
-#undef strerror_r
+#ifndef HAVE_STRERROR_R
 #define strerror_r rep_strerror_r
 int rep_strerror_r(int errnum, char *buf, size_t buflen);
 #endif
@@ -827,17 +892,6 @@ int fdatasync(int );
 /* prototype is in "system/network.h" */
 #endif
 
-#if !defined(getpass)
-#ifdef REPLACE_GETPASS
-#if defined(REPLACE_GETPASS_BY_GETPASSPHRASE)
-#define getpass(prompt) getpassphrase(prompt)
-#else
-#define getpass(prompt) rep_getpass(prompt)
-char *rep_getpass(const char *prompt);
-#endif
-#endif
-#endif
-
 #ifndef HAVE_GETPEEREID
 #define getpeereid rep_getpeereid
 int rep_getpeereid(int s, uid_t *uid, gid_t *gid);
@@ -854,4 +908,14 @@ int usleep(useconds_t);
 void rep_setproctitle(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
 #endif
 
+bool nss_wrapper_enabled(void);
+bool nss_wrapper_hosts_enabled(void);
+bool socket_wrapper_enabled(void);
+bool uid_wrapper_enabled(void);
+
+/* Needed for Solaris atomic_add_XX functions. */
+#if defined(HAVE_SYS_ATOMIC_H)
+#include <sys/atomic.h>
+#endif
+
 #endif /* _LIBREPLACE_REPLACE_H */