From ab4dd923d778048d5ba4a0bab7e730d0c157b322 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sun, 11 Dec 2016 15:27:08 +0100 Subject: Fix portability to C90 and C++. --- configure.ac | 1 + pop3.c | 1 - uid_db.c | 7 ++++--- xmalloc.c | 7 +------ xmalloc.h | 13 +++++++++++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index d6f96c2b..12ab1a4f 100644 --- a/configure.ac +++ b/configure.ac @@ -103,6 +103,7 @@ AC_CHECK_DECLS([h_errno],,,[ ]) AC_C_CONST dnl getopt needs this. +AC_C_INLINE dnl uid_db.? need this. AM_PROG_LEX AC_PROG_MAKE_SET diff --git a/pop3.c b/pop3.c index cf950545..c5da128c 100644 --- a/pop3.c +++ b/pop3.c @@ -816,7 +816,6 @@ static int pop3_fastuidl( int sock, struct query *ctl, unsigned int count, int int ok; unsigned int first_nr, last_nr, try_nr; char id [IDLEN+1]; - struct idlist *savep = NULL; /** pointer to cache save_str result, speeds up saves */ first_nr = 0; last_nr = count + 1; diff --git a/uid_db.c b/uid_db.c index 97b1c2ba..18f4d6b3 100644 --- a/uid_db.c +++ b/uid_db.c @@ -10,12 +10,13 @@ /* Have Solaris expose ffs() from strings.h: */ #define __EXTENSIONS__ +#define _XOPEN_SOURCE 700 /* includes */ #include #include #include -#include // ffs() lives here - needs #define on Solaris. +#include /* ffs() lives here - needs #define on Solaris. */ #include "xmalloc.h" #include "uid_db.h" @@ -94,8 +95,8 @@ static struct pat_node *walk_down(struct uid_db *db, struct uid_db_record *rec, *parentp = (struct pat_node *) ((unsigned char *)edge - (v & bit_mask(bit_ndx) ? - offsetof(struct pat_node, ptrs_[2]) - : offsetof(struct pat_node, ptrs_[0]))); + offsetof(struct pat_node, ptrs_) + 2 * sizeof(struct pat_node *) + : offsetof(struct pat_node, ptrs_))); *edgep = edge; return cur; } diff --git a/xmalloc.c b/xmalloc.c index c2ca4a66..44143a70 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include "xmalloc.h" #include #include #include @@ -16,12 +17,6 @@ #include "fetchmail.h" #include "i18n.h" -#if defined(HAVE_VOIDPOINTER) -#define XMALLOCTYPE void -#else -#define XMALLOCTYPE char -#endif - XMALLOCTYPE * xmalloc (size_t n) { diff --git a/xmalloc.h b/xmalloc.h index 81835828..70ed0a0b 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -4,9 +4,14 @@ #define XMALLOC_H #include "config.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif /* xmalloc.c */ -#if defined(HAVE_VOIDPOINTER) +#if defined(HAVE_VOIDPOINTER) || defined(__cplusplus) #define XMALLOCTYPE void #else #define XMALLOCTYPE char @@ -16,7 +21,7 @@ XMALLOCTYPE *xmalloc(size_t n); /** Reallocate \a n characters of memory, abort program on failure. */ -XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t n); +XMALLOCTYPE *xrealloc(/*@null@*/ void *, size_t n); /** Free memory at position \a p and set pointer \a p to NULL afterwards. */ #define xfree(p) { if (p) { free(p); } (p) = 0; } @@ -31,4 +36,8 @@ char *xstrdup(const char *src); * length including NUL byte or n + 1. */ char *xstrndup(const char *src, size_t n); +#ifdef __cplusplus +} +#endif + #endif -- cgit v1.2.3