Skip to content

Commit

Permalink
Re-tweaks for accommodating the windows build and systems that do not…
Browse files Browse the repository at this point in the history
… have strnlen
  • Loading branch information
damienstuart committed Dec 1, 2012
1 parent eaba581 commit 1ec9f4a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
6 changes: 6 additions & 0 deletions common/common.h
Expand Up @@ -147,6 +147,12 @@ enum {
x == '#' || x == '\n' || x == '\r' || x == ';' || x == '\0' \
)

/* Work-around for not having strnlen
*/
#if !HAVE_STRNLEN
#define strnlen(s, l) (strlen(s) < l ? strlen(s) : l)
#endif

#endif /* _COMMON_H */

/***EOF***/
28 changes: 25 additions & 3 deletions lib/fko_common.h
Expand Up @@ -57,13 +57,29 @@
#endif

#ifdef WIN32
#include <io.h>
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define snprintf _snprintf
#define strdup _strdup
#define unlink _unlink
#define open _open
#define close _close
#define write _write
#define O_WRONLY _O_WRONLY
#define O_RDONLY _O_RDONLY
#define O_RDWR _O_RDWR
#define O_CREAT _O_CREAT
#define O_EXCL _O_EXCL
#define S_IRUSR _S_IREAD
#define S_IWUSR _S_IWRITE
#define PATH_SEP '\\'

/* These are needed for the digest code under windows.
*/
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

#define strdup _strdup
#else
#if HAVE_STDINT_H
#include <stdint.h>
Expand Down Expand Up @@ -126,7 +142,13 @@
/* Try to cover for those that do not have bzero.
*/
#if !HAVE_BZERO && HAVE_MEMSET
# define bzero(buf, bytes) ((void) memset (buf, 0, bytes))
#define bzero(buf, bytes) ((void) memset (buf, 0, bytes))
#endif

/* Work-around for not having strnlen
*/
#if !HAVE_STRNLEN
#define strnlen(s, l) (strlen(s) < l ? strlen(s) : l)
#endif

#endif /* FKO_COMMON_H */
Expand Down
12 changes: 7 additions & 5 deletions lib/fko_message.c
Expand Up @@ -33,11 +33,13 @@
#include "fko_message.h"
#include "fko.h"

/* for inet_aton() IP validation
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifndef WIN32
/* for inet_aton() IP validation
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif

static int
have_allow_ip(const char *msg)
Expand Down
3 changes: 3 additions & 0 deletions win32/config.h
Expand Up @@ -101,6 +101,9 @@
/* Define to 1 if you have the `strndup' function. */
#define HAVE_STRNDUP 1

/* Define to 1 if you have the `strnlen' function. */
#define HAVE_STRNLEN 1

/* Define to 1 if you have the `strrchr' function. */
#define HAVE_STRRCHR 1

Expand Down

0 comments on commit 1ec9f4a

Please sign in to comment.