diff --git a/rinetd.c b/rinetd.c index 4e63064..29e95c7 100644 --- a/rinetd.c +++ b/rinetd.c @@ -1,35 +1,35 @@ #if HAVE_CONFIG_H -#include +# include #endif #ifndef RETSIGTYPE -#define RETSIGTYPE void +# define RETSIGTYPE void #endif #ifdef WIN32 -#include -#include -#include "getopt.h" -#define syslog fprintf -#define LOG_ERR stderr +# include +# include +# include "getopt.h" +# define syslog fprintf +# define LOG_ERR stderr #else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define INVALID_SOCKET (-1) -#if TIME_WITH_SYS_TIME -# include -# include -#elif HAVE_SYS_TIME_H -# include -#endif +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# define INVALID_SOCKET (-1) +# if TIME_WITH_SYS_TIME +# include +# include +# elif HAVE_SYS_TIME_H +# include +# endif #endif /* WIN32 */ #include @@ -38,65 +38,55 @@ #include #include #if WIN32 || (!TIME_WITH_SYS_TIME && !HAVE_SYS_TIME_H) -#include +# include #endif #include #ifndef WIN32 -/* Windows sockets compatibility defines */ -#define INVALID_SOCKET (-1) -#define SOCKET_ERROR (-1) -int closesocket(int s); - -int closesocket(int s) { + /* Windows sockets compatibility defines */ +# define INVALID_SOCKET (-1) +# define SOCKET_ERROR (-1) +static int closesocket(int s) { return close(s); } -#define ioctlsocket ioctl -#define MAKEWORD(a, b) -#define WSAStartup(a, b) (0) -#define WSACleanup() -#ifdef __MAC__ -/* The constants for these are a little screwy in the prelinked - MSL GUSI lib and we can't rebuild it, so roll with it */ -#define WSAEWOULDBLOCK EWOULDBLOCK -#define WSAEAGAIN EAGAIN -#define WSAEINPROGRESS EINPROGRESS -#else -#define WSAEWOULDBLOCK EWOULDBLOCK -#define WSAEAGAIN EAGAIN -#define WSAEINPROGRESS EINPROGRESS -#endif /* __MAC__ */ -#define WSAEINTR EINTR -#define SOCKET int -#define GetLastError() (errno) +# define ioctlsocket ioctl +# define MAKEWORD(a, b) +# define WSAStartup(a, b) (0) +# define WSACleanup() +# ifdef __MAC__ + /* The constants for these are a little screwy in the prelinked + MSL GUSI lib and we can't rebuild it, so roll with it */ +# define WSAEWOULDBLOCK EWOULDBLOCK +# define WSAEAGAIN EAGAIN +# define WSAEINPROGRESS EINPROGRESS +# else +# define WSAEWOULDBLOCK EWOULDBLOCK +# define WSAEAGAIN EAGAIN +# define WSAEINPROGRESS EINPROGRESS +# endif /* __MAC__ */ +# define WSAEINTR EINTR +# define SOCKET int +# define GetLastError() (errno) typedef struct { int dummy; } WSADATA; #else -/* WIN32 doesn't really have WSAEAGAIN */ -#ifndef WSAEAGAIN -#define WSAEAGAIN WSAEWOULDBLOCK -#endif + /* WIN32 doesn't really have WSAEAGAIN */ +# ifndef WSAEAGAIN +# define WSAEAGAIN WSAEWOULDBLOCK +# endif #endif /* WIN32 */ -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - #ifdef DEBUG -#define PERROR perror +# define PERROR perror #else -#define PERROR(x) +# define PERROR(x) #endif /* DEBUG */ /* We've got to get FIONBIO from somewhere. Try the Solaris location if it isn't defined yet by the above includes. */ #ifndef FIONBIO -#include +# include #endif /* FIONBIO */ #include "match.h" @@ -162,9 +152,7 @@ FILE *logFile = 0; If 'size' bytes cannot be allocated, *data is UNCHANGED, and 0 is returned. */ -#define SAFE_REALLOC(x, y, z) safeRealloc((void **) (x), (y), (z)) - -int safeRealloc(void **data, int oldsize, int newsize); +static int safeRealloc(void **data, int oldsize, int newsize); /* se: (se)rver sockets @@ -173,7 +161,7 @@ int safeRealloc(void **data, int oldsize, int newsize); co: connections */ -#define bufferSpace 1024 +static int const bufferSpace = 1024; void readConfiguration(); @@ -994,7 +982,7 @@ void handleAccept(int i) if (cnx == NULL) { o = coTotal; coTotal *= 2; - if (!SAFE_REALLOC(&coInfo, sizeof(ConnectionInfo) * o, + if (!safeRealloc((void **)&coInfo, sizeof(ConnectionInfo) * o, sizeof(ConnectionInfo) * coTotal)) { goto shortage; @@ -1243,7 +1231,7 @@ RETSIGTYPE hup(int s) } #endif /* WIN32 */ -int safeRealloc(void **data, int oldsize, int newsize) +static int safeRealloc(void **data, int oldsize, int newsize) { void *newData = malloc(newsize + 1); if (!newData) {