1 /***************************************************************************
2 * Copyright (C) 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef REPLACEMENTS_H
21 #define REPLACEMENTS_H
27 /* include necessary headers for socket functionality */
31 #include <sys/socket.h>
33 #include <netinet/in.h>
38 #ifdef HAVE_SYS_PARAM_H
39 #include <sys/param.h> /* for MIN/MAX macros */
44 #define MIN(a,b) (((a)<(b))?(a):(b))
47 #define MAX(a,b) (((a)>(b))?(a):(b))
51 #ifndef HAVE_GETTIMEOFDAY
53 #ifndef _TIMEVAL_DEFINED
54 #define _TIMEVAL_DEFINED
60 #endif /* _TIMEVAL_DEFINED */
67 extern int gettimeofday(struct timeval *tv, struct timezone *tz);
70 /* GNU extensions to the C library that may be missing on some systems */
72 extern char* strndup(const char *s, size_t n);
73 #endif /* HAVE_STRNDUP */
76 extern size_t strnlen(const char *s, size_t maxlen);
77 #endif /* HAVE_STRNLEN */
80 static __inline unsigned usleep(unsigned int usecs)
86 #error no usleep defined for your platform
89 #endif /* HAVE_USLEEP */
91 /* Windows specific */
94 #define WIN32_LEAN_AND_MEAN
101 static __inline unsigned char inb(unsigned short int port)
104 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
108 static __inline void outb(unsigned char value, unsigned short int port)
110 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
113 #endif /* IS_MINGW */
116 /* generic socket functions for Windows and Posix */
117 static __inline int write_socket( int handle, const void *buffer, unsigned int count )
120 return send(handle, buffer, count, 0);
122 return write(handle, buffer, count);
126 static __inline int read_socket( int handle, void *buffer, unsigned int count )
129 return recv(handle, buffer, count, 0);
131 return read(handle, buffer, count);
135 static __inline int close_socket(int sock)
138 return closesocket(sock);
144 static __inline void socket_nonblock(int fd)
148 ioctlsocket(fd, FIONBIO, &nonblock );
150 int oldopts = fcntl(fd, F_GETFL, 0);
151 fcntl(fd, F_SETFL, oldopts | O_NONBLOCK);
155 #endif /* REPLACEMENTS_H */