sys_w32.h

来自「picoos源码。The RTOS and the TCP/IP stack 」· C头文件 代码 · 共 147 行

H
147
字号
/*
 *  Copyright (c) 2004, Dennis Kuschel.
 *  All rights reserved. 
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. The name of the author may not be used to endorse or promote
 *      products derived from this software without specific prior written
 *      permission. 
 *
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 *  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 *  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


/*
 *  This file contains the
 *
 *  operating system adaption for  MICROSOFT WINDOWS
 */

#ifndef MY_SYS_H
#define MY_SYS_H


/*---------------------------------------------------------------------------
 *  Include Operating System Header Files
 *-------------------------------------------------------------------------*/

#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
#include <windows.h>
#include <winsock.h>
#undef HTTP_RXBUFSIZE

/*#define read(a,b,c)  recv(a,b,c,0)*/ /* required for windows sockets */

#ifdef NOSERVLETS
#define HTTP_SERVLETS  0
#endif

#define HAVE_LOCALTIME



/*---------------------------------------------------------------------------
 *  Common Declarations - needed by ftpd and filesys
 *-------------------------------------------------------------------------*/

/* definition of common types */
typedef unsigned char   u8_t;
typedef signed   char   s8_t;
typedef unsigned short  u16_t;
typedef signed   short  s16_t;
typedef unsigned int    u32_t;
typedef signed   int    s32_t;
typedef unsigned int    uint_t;
typedef signed   int    sint_t;

/* macros */
#define sysPrintErr(x)          printf("%s",x)
#define sysSleep(ms)            Sleep(ms)
#define sysMemAlloc(s)          malloc(s)
#define sysMemFree(x)           free(x)
#define sysMemCopy(d,s,l)       memcpy(d,s,l)
#define sysMemSet(d,v,s)        memset(d,v,s)
#define sysStrcpy(d,s)          strcpy(d,s)
#define sysStrncpy(d,s,n)       strncpy(d,s,n)
#define sysStrcat(d,s)          strcat(d,s)
#define sysStrlen(s)            strlen(s)
#define sysStrcmp(s1,s2)        strcmp(s1,s2)
#define sysStricmp(s1,s2)       stricmp(s1,s2)
#define sysStrncmp(s1,s2,n)     strncmp(s1,s2,n)
#define sysStrnicmp(s1,s2,n)    strnicmp(s1,s2,n)



/*---------------------------------------------------------------------------
 *  Things needed by FTPD
 *-------------------------------------------------------------------------*/

/* Declaration of a counter variable.
   The variable is provided and exported by the operating system.
   It is incremented by the system timer. */
#define COUNTERVAR      jiffies  /* external variable that is incremented n times per second */
#define COUNTERTYPE     u32_t    /* type of external counter variable */
#define COUNTERSTYPE    s32_t    /* signed type of external counter variable */
#define COUNTERTPS      100      /* number of ticks the counter is incremented per second */

extern  COUNTERTYPE     COUNTERVAR;  /* link to the external variable */


/* socket error numbers */

#define sysGetErrno()       WSAGetLastError()

#undef  EPIPE
#undef  EBADF
#undef  ENOMEM
#undef  EADDRINUSE
#undef  EINTR

#define EPIPE               WSAENETDOWN
#define EBADF               WSAEBADF
#define ENOMEM              WSAENOBUFS
#define EADDRINUSE          WSAEADDRINUSE
#define EINTR               WSAEINTR
#define EWOULDBLOCK         WSAEWOULDBLOCK



/*---------------------------------------------------------------------------
 *  Things needed by filesys and HTTPD
 *-------------------------------------------------------------------------*/

/* Multitasking locking - done through semaphores.
 */
#define SYS_MTASK_DECLARELOCK(lock)     HANDLE lock;
#define SYS_MTASK_CREATELOCK(lock)      CreateSemaphore(NULL, 1, 1, NULL)
#define SYS_MTASK_DESTROYLOCK(lock)     CloseHandle(lock)
#define SYS_MTASK_LOCK(lock)            WaitForSingleObject(lock, INFINITE)
#define SYS_MTASK_UNLOCK(lock)          ReleaseSemaphore(lock, 1, NULL)



#endif /* MY_SYS_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?