Good bye osdep.h, you won't be missed

PUBLISHED_FROM=f08a8324dfde5f9e22eee0e5e4dbae0e3d45cb3f
This commit is contained in:
rojer committed 2016-02-13 13:59:16 +00:00
1 parent 51ad50a641
commit 00a23ee330
6 files changed
+433 -157

No files matched your search

+385 -128
View File
@@ -20,6 +20,9 @@
* license, as set out in <https://www.cesanta.com/license>.
*/
#ifndef _MG_COMMON_H_
#define _MG_COMMON_H_
#define MG_VERSION "6.2"
/* Local tweaks, applied before any of Mongoose's own headers. */
@@ -30,53 +33,89 @@
#if defined(MG_ENABLE_DEBUG) && !defined(CS_ENABLE_DEBUG)
#define CS_ENABLE_DEBUG
#endif
#if defined(MG_DISABLE_STDIO) && !defined(CS_DISABLE_STDIO)
#define CS_DISABLE_STDIO
#endif
/* All of the below features depend on filesystem access, disable them. */
#ifdef MG_DISABLE_FILESYSTEM
#ifndef MG_DISABLE_DAV
#define MG_DISABLE_DAV
#endif
#ifndef MG_DISABLE_CGI
#define MG_DISABLE_CGI
#endif
#ifndef MG_DISABLE_DIRECTORY_LISTING
#define MG_DISABLE_DIRECTORY_LISTING
#endif
#ifndef MG_DISABLE_DAV
#define MG_DISABLE_DAV
#endif
#endif /* MG_DISABLE_FILESYSTEM */
#ifdef MG_NO_BSD_SOCKETS
#ifndef MG_DISABLE_SYNC_RESOLVER
#define MG_DISABLE_SYNC_RESOLVER
#endif
#ifndef MG_DISABLE_SOCKETPAIR
#define MG_DISABLE_SOCKETPAIR
#endif
#endif /* MG_NO_BSD_SOCKETS */
#endif /* _MG_COMMON_H_ */
#ifndef _CS_PLATFORM_H_
#define _CS_PLATFORM_H_
/*
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
* For the "custom" platform, includes and dependencies can be
* provided through mg_locals.h.
*/
#define CS_P_CUSTOM 0
#define CS_P_UNIX 1
#define CS_P_WINDOWS 2
#define CS_P_ESP_LWIP 3
#define CS_P_CC3200 4
#ifndef OSDEP_HEADER_INCLUDED
#define OSDEP_HEADER_INCLUDED
/* If not specified explicitly, we guess platform by defines. */
#ifndef CS_PLATFORM
#if !defined(MG_DISABLE_FILESYSTEM) && defined(AVR_NOFS)
#define MG_DISABLE_FILESYSTEM
#if defined(__unix__) || defined(__APPLE__)
#define CS_PLATFORM CS_P_UNIX
#elif defined(_WIN32)
#define CS_PLATFORM CS_P_WINDOWS
#endif
#undef UNICODE /* Use ANSI WinAPI functions */
#undef _UNICODE /* Use multibyte encoding on Windows */
#define _MBCS /* Use multibyte encoding on Windows */
#define _INTEGRAL_MAX_BITS 64 /* Enable _stati64() on Windows */
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005+ */
#endif
#undef WIN32_LEAN_AND_MEAN /* Let windows.h always include winsock2.h */
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600 /* For flockfile() on Linux */
#define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */
#define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE /* Enable fseeko() and ftello() functions */
#endif
#define _FILE_OFFSET_BITS 64 /* Enable 64-bit file offsets */
#if !(defined(AVR_LIBC) || defined(PICOTCP))
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#ifndef CS_PLATFORM
#error "CS_PLATFORM is not specified and we couldn't guess it."
#endif
#ifndef BYTE_ORDER
#define LITTLE_ENDIAN 0x41424344
#define BIG_ENDIAN 0x44434241
#define PDP_ENDIAN 0x42414443
/* TODO(lsm): fix for big-endian machines. 'ABCD' is not portable */
/*#define BYTE_ORDER 'ABCD'*/
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* !defined(CS_PLATFORM) */
/* Common stuff */
#ifdef __GNUC__
#define NORETURN __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#define NOINLINE __attribute__((noinline))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define NORETURN
#define UNUSED
#define NOINLINE
#define WARN_UNUSED_RESULT
#endif /* __GNUC__ */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#endif /* _CS_PLATFORM_H_ */
#ifndef _CS_PLATFORM_WINDOWS_H_
#define _CS_PLATFORM_WINDOWS_H_
#if CS_PLATFORM == CS_P_WINDOWS
/*
* MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
* MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
@@ -94,34 +133,15 @@
#pragma warning(disable : 4204) /* missing c99 support */
#endif
#ifdef PICOTCP
#define time(x) PICO_TIME()
#ifndef SOMAXCONN
#define SOMAXCONN (16)
#endif
#ifdef _POSIX_VERSION
#define signal(...)
#endif
#endif
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif
#ifdef _WIN32
#define random() rand()
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib") /* Linking with winsock library */
@@ -203,93 +223,321 @@ DIR *opendir(const char *name);
int closedir(DIR *dir);
struct dirent *readdir(DIR *dir);
#elif /* not _WIN32 */ defined(MG_CC3200)
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif
#endif /* CS_PLATFORM == CS_P_WINDOWS */
#endif /* _CS_PLATFORM_WINDOWS_H_ */
#ifndef _CS_PLATFORM_UNIX_H_
#define _CS_PLATFORM_UNIX_H_
#if CS_PLATFORM == CS_P_UNIX
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
/* <inttypes.h> wants this for C++ */
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
/* C++ wants that for INT64_MAX */
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
/* Enable fseeko() and ftello() functions */
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
/* Enable 64-bit file offsets */
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <math.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <cc3200_libc.h>
#include <cc3200_socket.h>
#elif /* not CC3200 */ defined(MG_LWIP)
typedef int sock_t;
#define INVALID_SOCKET (-1)
#define SIZE_T_FMT "zu"
typedef struct stat cs_stat_t;
#define DIRSEP '/'
#define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#include <lwip/sockets.h>
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(x, y) (x) = (y)
#endif
#endif
#define closesocket(x) close(x)
#endif /* CS_PLATFORM == CS_P_UNIX */
#endif /* _CS_PLATFORM_UNIX_H_ */
#ifndef _CS_PLATFORM_ESP_LWIP_H_
#define _CS_PLATFORM_ESP_LWIP_H_
#if CS_PLATFORM == CS_P_ESP_LWIP
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <lwip/err.h>
#include <lwip/ip_addr.h>
#include <lwip/inet.h>
#include <lwip/netdb.h>
#include <lwip/dns.h>
#if defined(MG_ESP8266) && defined(RTOS_SDK)
#include <esp_libc.h>
#define random() os_random()
#endif
#define LWIP_TIMEVAL_PRIVATE 0
/* TODO(alashkin): check if zero is OK */
#define SOMAXCONN 0
#include <stdlib.h>
#elif /* not ESP8266 RTOS */ !defined(NO_LIBC) && !defined(NO_BSD_SOCKETS)
#include <dirent.h>
#include <fcntl.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h> /* For inet_pton() when MG_ENABLE_IPV6 is defined */
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/select.h>
#endif
#ifndef LWIP_PROVIDE_ERRNO
#include <errno.h>
#endif
#ifndef _WIN32
#include <inttypes.h>
#include <stdarg.h>
#ifndef AVR_LIBC
#ifndef MG_ESP8266
#define closesocket(x) close(x)
#endif
#ifndef __cdecl
#define __cdecl
#endif
#define INVALID_SOCKET (-1)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#if defined(ESP8266) || defined(MG_ESP8266) || defined(MG_CC3200)
#define SIZE_T_FMT "u"
#if LWIP_SOCKET
#include <lwip/sockets.h>
#define SOMAXCONN 10
#else
#define SIZE_T_FMT "zu"
/* We really need the definitions from sockets.h. */
#undef LWIP_SOCKET
#define LWIP_SOCKET 1
#include <lwip/sockets.h>
#undef LWIP_SOCKET
#define LWIP_SOCKET 0
#endif
#define to64(x) strtoll(x, NULL, 10)
typedef int sock_t;
#define INVALID_SOCKET (-1)
#define SIZE_T_FMT "u"
typedef struct stat cs_stat_t;
#define DIRSEP '/'
#endif /* !AVR_LIBC */
#define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#ifdef __APPLE__
int64_t strtoll(const char *str, char **endptr, int base);
#endif
#endif /* !_WIN32 */
#endif /* CS_PLATFORM == CS_P_ESP_LWIP */
#endif /* _CS_PLATFORM_ESP_LWIP_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#ifndef _CS_PLATFORM_CC3200_H_
#define _CS_PLATFORM_CC3200_H_
#if CS_PLATFORM == CS_P_CC3200
#ifdef __GNUC__
#define NORETURN __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#define NOINLINE __attribute__((noinline))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define NORETURN
#define UNUSED
#define NOINLINE
#define WARN_UNUSED_RESULT
#endif
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
#include <time.h>
#endif /* OSDEP_HEADER_INCLUDED */
#include <simplelink.h>
#define SOMAXCONN 8
/* Undefine a bunch of conflicting symbols so we can use SDK defs verbatim. */
#undef FD_CLR
#undef FD_SET
#undef FD_ZERO
#undef FD_ISSET
#undef FD_SETSIZE
#undef fd_set
#undef EACCES
#undef EBADF
#undef EAGAIN
#undef EWOULDBLOCK
#undef ENOMEM
#undef EFAULT
#undef EINVAL
#undef EDESTADDRREQ
#undef EPROTOTYPE
#undef ENOPROTOOPT
#undef EPROTONOSUPPORT
#undef EOPNOTSUPP
#undef EAFNOSUPPORT
#undef EAFNOSUPPORT
#undef EADDRINUSE
#undef EADDRNOTAVAIL
#undef ENETUNREACH
#undef ENOBUFS
#undef EISCONN
#undef ENOTCONN
#undef ETIMEDOUT
#undef ECONNREFUSED
/* The following comes from $SDK/simplelink/include/socket.h */
/* clang-format off */
#define FD_SETSIZE SL_FD_SETSIZE
#define SOCK_STREAM SL_SOCK_STREAM
#define SOCK_DGRAM SL_SOCK_DGRAM
#define SOCK_RAW SL_SOCK_RAW
#define IPPROTO_TCP SL_IPPROTO_TCP
#define IPPROTO_UDP SL_IPPROTO_UDP
#define IPPROTO_RAW SL_IPPROTO_RAW
#define AF_INET SL_AF_INET
#define AF_INET6 SL_AF_INET6
#define AF_INET6_EUI_48 SL_AF_INET6_EUI_48
#define AF_RF SL_AF_RF
#define AF_PACKET SL_AF_PACKET
#define PF_INET SL_PF_INET
#define PF_INET6 SL_PF_INET6
#define INADDR_ANY SL_INADDR_ANY
#define ERROR SL_SOC_ERROR
#define INEXE SL_INEXE
#define EBADF SL_EBADF
#define ENSOCK SL_ENSOCK
#define EAGAIN SL_EAGAIN
#define EWOULDBLOCK SL_EWOULDBLOCK
#define ENOMEM SL_ENOMEM
#define EACCES SL_EACCES
#define EFAULT SL_EFAULT
#define EINVAL SL_EINVAL
#define EDESTADDRREQ SL_EDESTADDRREQ
#define EPROTOTYPE SL_EPROTOTYPE
#define ENOPROTOOPT SL_ENOPROTOOPT
#define EPROTONOSUPPORT SL_EPROTONOSUPPORT
#define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT
#define EOPNOTSUPP SL_EOPNOTSUPP
#define EAFNOSUPPORT SL_EAFNOSUPPORT
#define EADDRINUSE SL_EADDRINUSE
#define EADDRNOTAVAIL SL_EADDRNOTAVAIL
#define ENETUNREACH SL_ENETUNREACH
#define ENOBUFS SL_ENOBUFS
#define EOBUFF SL_EOBUFF
#define EISCONN SL_EISCONN
#define ENOTCONN SL_ENOTCONN
#define ETIMEDOUT SL_ETIMEDOUT
#define ECONNREFUSED SL_ECONNREFUSED
#define SOL_SOCKET SL_SOL_SOCKET
#define IPPROTO_IP SL_IPPROTO_IP
#define SO_KEEPALIVE SL_SO_KEEPALIVE
#define SO_RCVTIMEO SL_SO_RCVTIMEO
#define SO_NONBLOCKING SL_SO_NONBLOCKING
#define IP_MULTICAST_IF SL_IP_MULTICAST_IF
#define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL
#define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP
#define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP
#define socklen_t SlSocklen_t
#define timeval SlTimeval_t
#define sockaddr SlSockAddr_t
#define in6_addr SlIn6Addr_t
#define sockaddr_in6 SlSockAddrIn6_t
#define in_addr SlInAddr_t
#define sockaddr_in SlSockAddrIn_t
#define MSG_DONTWAIT SL_MSG_DONTWAIT
#define FD_SET SL_FD_SET
#define FD_CLR SL_FD_CLR
#define FD_ISSET SL_FD_ISSET
#define FD_ZERO SL_FD_ZERO
#define fd_set SlFdSet_t
#define socket sl_Socket
#define close sl_Close
#define accept sl_Accept
#define bind sl_Bind
#define listen sl_Listen
#define connect sl_Connect
#define select sl_Select
#define setsockopt sl_SetSockOpt
#define getsockopt sl_GetSockOpt
#define recv sl_Recv
#define recvfrom sl_RecvFrom
#define write sl_Write
#define send sl_Send
#define sendto sl_SendTo
/* rojer: gethostbyname() and sl_NetAppDnsGetHostByName are NOT compatible. */
/* #define gethostbyname sl_NetAppDnsGetHostByName */
#define htonl sl_Htonl
#define ntohl sl_Ntohl
#define htons sl_Htons
#define ntohs sl_Ntohs
/* clang-format on */
typedef int sock_t;
#define INVALID_SOCKET (-1)
#define SIZE_T_FMT "u"
typedef struct stat cs_stat_t;
#define DIRSEP '/'
#define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64
#define INT64_X_FMT PRIx64
#define __cdecl
#define closesocket(x) close(x)
/* Some functions we implement for Mongoose. */
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
char *inet_ntoa(struct in_addr in);
int inet_pton(int af, const char *src, void *dst);
void cc3200_set_non_blocking_mode(int fd);
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
};
struct hostent *gethostbyname(const char *name);
struct timeval;
int gettimeofday(struct timeval *t, void *tz);
long int random(void);
#endif /* CS_PLATFORM == CS_P_CC3200 */
#endif /* _CS_PLATFORM_CC3200_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
@@ -313,6 +561,8 @@ enum cs_log_level {
extern enum cs_log_level s_cs_log_level;
void cs_log_set_level(enum cs_log_level level);
#ifndef CS_DISABLE_STDIO
void cs_log_printf(const char *fmt, ...);
#define LOG(l, x) \
@@ -335,6 +585,13 @@ void cs_log_printf(const char *fmt, ...);
#endif
#else /* CS_DISABLE_STDIO */
#define LOG(l, x)
#define DBG(x)
#endif
#endif /* _CS_DBG_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited