(posix_accept, posix_bind, posix_listen, posix_setsockopt,
posix_shutdown, posix_socket, socklen_t) [_WIN32]: Move socket related externs to sys/socket.h. (inet_ntop) [_WIN32]: Move extern to inet.h. (tcp_listen): Remove the !WIN32 includes and use the revised sys/socket.h, netinet/in.h, arpa/inet.h and netdb.h.
This commit is contained in:
parent
2b4fd27b97
commit
afedb8c9e2
6 changed files with 72 additions and 57 deletions
|
@ -40,11 +40,9 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#if !defined(_WIN32)
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include "prototypes.h"
|
||||
|
||||
|
|
|
@ -35,4 +35,8 @@
|
|||
#define ARPA_INET_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
extern const char *inet_ntop(int af, const void *src, char *dst,
|
||||
socklen_t cnt);
|
||||
|
||||
#endif /* ARPA_INET_H */
|
||||
|
|
|
@ -34,6 +34,6 @@
|
|||
#ifndef NETDB_H
|
||||
#define NETDB_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include "sys/socket.h"
|
||||
#include <ws2tcpip.h>
|
||||
#endif /* NETDB_H */
|
||||
|
|
|
@ -50,10 +50,11 @@
|
|||
#include <share.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "sys/socket.h"
|
||||
#include <sys/stat.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "sys/socket.h"
|
||||
#include "sys/uio.h"
|
||||
#include "unistd.h"
|
||||
|
||||
|
|
|
@ -37,4 +37,31 @@
|
|||
#include <winsock2.h>
|
||||
#undef NS_ALL
|
||||
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
|
||||
typedef int socklen_t;
|
||||
|
||||
#define accept(fd, addr, addrlen) \
|
||||
posix_accept((fd), (addr), (addrlen))
|
||||
#define bind(fd, name, namelen) \
|
||||
posix_bind((fd), (name), (namelen))
|
||||
#define listen(fd, backlog) \
|
||||
posix_listen((fd), (backlog))
|
||||
#define setsockopt(fd, level, optname, optval, optlen) \
|
||||
posix_setsockopt((fd), (level), (optname), (optval), (optlen))
|
||||
#define shutdown(fd, how) \
|
||||
posix_shutdown((fd), (how))
|
||||
#define socket(domain, type, protocol) \
|
||||
posix_socket((domain), (type), (protocol))
|
||||
|
||||
extern int posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
extern int posix_bind(int fd, const struct sockaddr *name, socklen_t namelen);
|
||||
extern int posix_listen(int fd, int backlog);
|
||||
extern int posix_setsockopt(int fd, int level, int optname,
|
||||
const void *optval, socklen_t optlen);
|
||||
extern int posix_shutdown(int fd, int how);
|
||||
extern int posix_socket(int domain, int type, int protocol);
|
||||
|
||||
#endif /* SYS_SOCKET_H */
|
||||
|
|
|
@ -31,15 +31,24 @@
|
|||
* Ron Koenderink, 2007
|
||||
*/
|
||||
|
||||
/*
|
||||
* We can provide POSIX headers that don't exist in Windows, but we
|
||||
* can't augment existing headers. Some stuff that should be in such
|
||||
* headers ends up here, and some in w32misc.h. Can't be helped.
|
||||
*/
|
||||
|
||||
#ifndef UNISTD_H
|
||||
#define UNISTD_H
|
||||
|
||||
/*
|
||||
* We override system functions by defining them as macros. This
|
||||
* breaks if the system's declaration is included later. Include them
|
||||
* here. Major name space pollution, can't be helped.
|
||||
*/
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#include <direct.h>
|
||||
#include "sys/socket.h"
|
||||
#include <sys/stat.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "w32misc.h"
|
||||
|
||||
|
@ -53,13 +62,14 @@ extern int optind, opterr, optopt;
|
|||
/*
|
||||
* posixfile.c
|
||||
*/
|
||||
/* Should be in sys/stat.h */
|
||||
#define mkdir(dir, perm) posix_mkdir((dir), (perm))
|
||||
|
||||
extern int posix_mkdir(const char *dirname, mode_t perm);
|
||||
|
||||
/*
|
||||
* posixio.c
|
||||
*/
|
||||
/* Should be in sys/stat.h */
|
||||
#ifndef S_IRUSR
|
||||
#define S_IRUSR _S_IREAD
|
||||
#define S_IWUSR _S_IWRITE
|
||||
|
@ -78,47 +88,18 @@ extern int posix_mkdir(const char *dirname, mode_t perm);
|
|||
#define S_IXOTH 0
|
||||
#define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH
|
||||
#endif
|
||||
|
||||
typedef int socklen_t;
|
||||
|
||||
#define accept(fd, addr, addrlen) \
|
||||
posix_accept((fd), (addr), (addrlen))
|
||||
#define bind(fd, name, namelen) \
|
||||
posix_bind((fd), (name), (namelen))
|
||||
#define listen(fd, backlog) \
|
||||
posix_listen((fd), (backlog))
|
||||
#define setsockopt(fd, level, optname, optval, optlen) \
|
||||
posix_setsockopt((fd), (level), (optname), (optval), (optlen))
|
||||
#define shutdown(fd, how) \
|
||||
posix_shutdown((fd), (how))
|
||||
#define socket(domain, type, protocol) \
|
||||
posix_socket((domain), (type), (protocol))
|
||||
|
||||
#define close(fd) \
|
||||
posix_close((fd))
|
||||
#define creat(fname, pmode) \
|
||||
posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
|
||||
#define fstat(fd, buffer) \
|
||||
posix_fstat((fd), (buffer))
|
||||
#define lseek(fd, offset, origin) \
|
||||
posix_lseek((fd), (offset), (origin))
|
||||
#define open(fname, oflag, ...) \
|
||||
posix_open((fname), (oflag), __VA_ARGS__)
|
||||
#define read posix_read
|
||||
#define write(fd, buffer, count) \
|
||||
posix_write((fd), (buffer), (count))
|
||||
#define fsync(fd) \
|
||||
posix_fsync((fd))
|
||||
extern int posix_fstat(int fd, struct stat *buffer);
|
||||
|
||||
/* Should be in fcntl.h */
|
||||
#define O_NONBLOCK 1
|
||||
|
||||
#define F_RDLCK 0
|
||||
#define F_WRLCK 1
|
||||
#define F_GETFL 1
|
||||
#define F_SETFL 2
|
||||
#define F_SETLK 3
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
|
||||
struct flock
|
||||
{
|
||||
|
@ -128,27 +109,31 @@ struct flock
|
|||
off_t l_len;
|
||||
/* intentionally missing: pid_t l_pid */
|
||||
};
|
||||
|
||||
extern int posix_fd2socket(int fd);
|
||||
|
||||
extern int posix_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
extern int posix_bind(int fd, const struct sockaddr *name, socklen_t namelen);
|
||||
extern int posix_listen(int fd, int backlog);
|
||||
extern int posix_setsockopt(int fd, int level, int optname,
|
||||
const void *optval, socklen_t optlen);
|
||||
extern int posix_shutdown(int fd, int how);
|
||||
extern int posix_socket(int domain, int type, int protocol);
|
||||
extern const char *inet_ntop(int af, const void *src, char *dst,
|
||||
socklen_t cnt);
|
||||
|
||||
extern int posix_close(int fd);
|
||||
extern int posix_fstat(int fd, struct stat *buffer);
|
||||
extern off_t posix_lseek(int fd, off_t offset, int origin);
|
||||
#define creat(fname, pmode) \
|
||||
posix_open((fname), _O_WRONLY | _O_CREAT |_O_TRUNC, (pmode))
|
||||
#define open(fname, oflag, ...) \
|
||||
posix_open((fname), (oflag), __VA_ARGS__)
|
||||
extern int posix_open(const char *fname, int oflag, ...);
|
||||
|
||||
/* Stuff that belongs here */
|
||||
#define close(fd) \
|
||||
posix_close((fd))
|
||||
#define lseek(fd, offset, origin) \
|
||||
posix_lseek((fd), (offset), (origin))
|
||||
#define read posix_read
|
||||
#define write(fd, buffer, count) \
|
||||
posix_write((fd), (buffer), (count))
|
||||
#define fsync(fd) \
|
||||
posix_fsync((fd))
|
||||
extern int posix_close(int fd);
|
||||
extern off_t posix_lseek(int fd, off_t offset, int origin);
|
||||
extern ssize_t posix_read(int fd, void *buffer, size_t count);
|
||||
extern ssize_t posix_write(int fd, const void *buffer, size_t count);
|
||||
|
||||
extern int posix_fileno(FILE *stream);
|
||||
extern int posix_fsync(int fd);
|
||||
extern int fcntl(int fd, int cmd, ...);
|
||||
|
||||
/* Low-level stuff specific to the emulation */
|
||||
extern int posix_fd2socket(int fd);
|
||||
|
||||
#endif /* UNISTD_H */
|
||||
extern int posix_fileno(FILE *stream);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue