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>
39 #ifndef HAVE_GETTIMEOFDAY
41 #ifndef _TIMEVAL_DEFINED
42 #define _TIMEVAL_DEFINED
48 #endif /* _TIMEVAL_DEFINED */
55 extern int gettimeofday(struct timeval *tv, struct timezone *tz);
58 /* GNU extensions to the C library that may be missing on some systems */
60 extern char* strndup(const char *s, size_t n);
61 #endif /* HAVE_STRNDUP */
64 extern size_t strnlen(const char *s, size_t maxlen);
65 #endif /* HAVE_STRNLEN */
68 static __inline unsigned usleep(unsigned int usecs)
74 #error no usleep defined for your platform
77 #endif /* HAVE_USLEEP */
79 /* Windows specific */
82 #define WIN32_LEAN_AND_MEAN
89 static __inline unsigned char inb(unsigned short int port)
92 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
96 static __inline void outb(unsigned char value, unsigned short int port)
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
101 #endif /* IS_MINGW */
104 /* generic socket functions for Windows and Posix */
105 static __inline int write_socket( int handle, const void *buffer, unsigned int count )
108 return send(handle, buffer, count, 0);
110 return write(handle, buffer, count);
114 static __inline int read_socket( int handle, void *buffer, unsigned int count )
117 return recv(handle, buffer, count, 0);
119 return read(handle, buffer, count);
123 static __inline int close_socket(int sock)
126 return closesocket(sock);
132 static __inline void socket_nonblock(int fd)
136 ioctlsocket(fd, FIONBIO, &nonblock );
138 int oldopts = fcntl(fd, F_GETFL, 0);
139 fcntl(fd, F_SETFL, oldopts | O_NONBLOCK);
143 #endif /* REPLACEMENTS_H */