home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / Tk / pTk / tclWinPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-10  |  9.8 KB  |  407 lines

  1. /*
  2.  * tclWinPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because of
  5.  *    differences between Windows and Unix. It should be the only
  6.  *    file that contains #ifdefs to handle different flavors of OS.
  7.  *
  8.  * Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  *
  13.  * SCCS: @(#) tclWinPort.h 1.41 96/09/30 12:00:36
  14.  */
  15.  
  16. #ifndef _TCLWINPORT
  17. #define _TCLWINPORT
  18.  
  19. #include <malloc.h>
  20. #include <stdio.h>
  21.  
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <errno.h>
  25. #include <process.h>
  26. #include <signal.h>
  27. #include <winsock.h>
  28. #include <sys/stat.h>
  29. #include <sys/timeb.h>
  30. #include <time.h>
  31. #include <io.h>
  32. #include <fcntl.h>
  33.  
  34. #define WIN32_LEAN_AND_MEAN
  35. #include <windows.h>
  36. #undef WIN32_LEAN_AND_MEAN
  37.  
  38. /*
  39.  * Define EINPROGRESS in terms of WSAEINPROGRESS.
  40.  */
  41.  
  42. #ifndef    EINPROGRESS
  43. #define EINPROGRESS WSAEINPROGRESS
  44. #endif
  45.  
  46. /*
  47.  * If ENOTSUP is not defined, define it to a value that will never occur.
  48.  */
  49.  
  50. #ifndef ENOTSUP
  51. #define    ENOTSUP        -1030507
  52. #endif
  53.  
  54. /*
  55.  * The following defines denote malloc and free as the system calls
  56.  * used to allocate new memory.  These defines are only used in the
  57.  * file tclCkalloc.c.
  58.  */
  59.  
  60. #define TclpAlloc(size)        malloc(size)
  61. #define TclpFree(ptr)        free(ptr)
  62. #define TclpRealloc(ptr, size)    realloc(ptr, size)
  63.  
  64. /*
  65.  * The default platform eol translation on Windows is TCL_TRANSLATE_CRLF:
  66.  */
  67.  
  68. #define    TCL_PLATFORM_TRANSLATION    TCL_TRANSLATE_CRLF
  69.  
  70. /*
  71.  * Declare dynamic loading extension macro.
  72.  */
  73.  
  74. #define TCL_SHLIB_EXT ".dll"
  75.  
  76. /*
  77.  * Supply definitions for macros to query wait status, if not already
  78.  * defined in header files above.
  79.  */
  80.  
  81. #if TCL_UNION_WAIT
  82. #   define WAIT_STATUS_TYPE union wait
  83. #else
  84. #   define WAIT_STATUS_TYPE int
  85. #endif
  86.  
  87. #ifndef WIFEXITED
  88. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  89. #endif
  90.  
  91. #ifndef WEXITSTATUS
  92. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  93. #endif
  94.  
  95. #ifndef WIFSIGNALED
  96. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  97. #endif
  98.  
  99. #ifndef WTERMSIG
  100. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  101. #endif
  102.  
  103. #ifndef WIFSTOPPED
  104. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  105. #endif
  106.  
  107. #ifndef WSTOPSIG
  108. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  109. #endif
  110.  
  111. /*
  112.  * Define constants for waitpid() system call if they aren't defined
  113.  * by a system header file.
  114.  */
  115.  
  116. #ifndef WNOHANG
  117. #   define WNOHANG 1
  118. #endif
  119. #ifndef WUNTRACED
  120. #   define WUNTRACED 2
  121. #endif
  122.  
  123. /*
  124.  * Define MAXPATHLEN in terms of MAXPATH if available
  125.  */
  126.  
  127. #ifndef MAXPATH
  128. #define MAXPATH MAX_PATH
  129. #endif /* MAXPATH */
  130.  
  131. #ifndef MAXPATHLEN
  132. #define MAXPATHLEN MAXPATH
  133. #endif /* MAXPATHLEN */
  134.  
  135. #ifndef F_OK
  136. #    define F_OK 00
  137. #endif
  138. #ifndef X_OK
  139. #    define X_OK 01
  140. #endif
  141. #ifndef W_OK
  142. #    define W_OK 02
  143. #endif
  144. #ifndef R_OK
  145. #    define R_OK 04
  146. #endif
  147.  
  148. /*
  149.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  150.  * define "lstat" to use "stat" instead.
  151.  */
  152.  
  153. #ifndef S_IFLNK
  154. #   define lstat stat
  155. #endif
  156.  
  157. /*
  158.  * Define macros to query file type bits, if they're not already
  159.  * defined.
  160.  */
  161.  
  162. #ifndef S_ISREG
  163. #   ifdef S_IFREG
  164. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  165. #   else
  166. #       define S_ISREG(m) 0
  167. #   endif
  168. # endif
  169. #ifndef S_ISDIR
  170. #   ifdef S_IFDIR
  171. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  172. #   else
  173. #       define S_ISDIR(m) 0
  174. #   endif
  175. # endif
  176. #ifndef S_ISCHR
  177. #   ifdef S_IFCHR
  178. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  179. #   else
  180. #       define S_ISCHR(m) 0
  181. #   endif
  182. # endif
  183. #ifndef S_ISBLK
  184. #   ifdef S_IFBLK
  185. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  186. #   else
  187. #       define S_ISBLK(m) 0
  188. #   endif
  189. # endif
  190. #ifndef S_ISFIFO
  191. #   ifdef S_IFIFO
  192. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  193. #   else
  194. #       define S_ISFIFO(m) 0
  195. #   endif
  196. # endif
  197. #ifndef S_ISLNK
  198. #   ifdef S_IFLNK
  199. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  200. #   else
  201. #       define S_ISLNK(m) 0
  202. #   endif
  203. # endif
  204. #ifndef S_ISSOCK
  205. #   ifdef S_IFSOCK
  206. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  207. #   else
  208. #       define S_ISSOCK(m) 0
  209. #   endif
  210. # endif
  211.  
  212. /*
  213.  * Define pid_t and uid_t if they're not already defined.
  214.  */
  215.  
  216. #if ! TCL_PID_T
  217. #   define pid_t int
  218. #endif
  219. #if ! TCL_UID_T
  220. #   define uid_t int
  221. #endif
  222.  
  223. /*
  224.  * Provide an implementation of TclSetSystemEnv in terms of the equivalent
  225.  * Win32 call.
  226.  */
  227.  
  228. #define TclSetSystemEnv(a,b) SetEnvironmentVariable(a,b)
  229.  
  230. /*
  231.  * Provide a stub definition for TclGetUserHome().
  232.  */
  233.  
  234. #define TclGetUserHome(name,bufferPtr) (NULL)
  235.  
  236. /*
  237.  * Visual C++ has some odd names for common functions, so we need to
  238.  * define a few macros to handle them.  Also, it defines EDEADLOCK and
  239.  * EDEADLK as the same value, which confuses Tcl_ErrnoId().
  240.  */
  241.  
  242. #ifdef _MSC_VER
  243. #    define environ _environ
  244. #    define hypot _hypot
  245. #    define exception _exception
  246. #    undef EDEADLOCK
  247. #endif /* _MSC_VER */
  248.  
  249. /*
  250.  * The following defines redefine the Windows Socket errors as
  251.  * BSD errors so Tcl_PosixError can do the right thing.
  252.  */
  253.  
  254. #ifndef EWOULDBLOCK
  255. #define EWOULDBLOCK             EAGAIN
  256. #endif
  257. #ifndef EALREADY
  258. #define EALREADY    149    /* operation already in progress */
  259. #endif
  260. #ifndef ENOTSOCK
  261. #define ENOTSOCK    95    /* Socket operation on non-socket */
  262. #endif
  263. #ifndef EDESTADDRREQ
  264. #define EDESTADDRREQ    96    /* Destination address required */
  265. #endif
  266. #ifndef EMSGSIZE
  267. #define EMSGSIZE    97    /* Message too long */
  268. #endif
  269. #ifndef EPROTOTYPE
  270. #define EPROTOTYPE    98    /* Protocol wrong type for socket */
  271. #endif
  272. #ifndef ENOPROTOOPT
  273. #define ENOPROTOOPT    99    /* Protocol not available */
  274. #endif
  275. #ifndef EPROTONOSUPPORT
  276. #define EPROTONOSUPPORT    120    /* Protocol not supported */
  277. #endif
  278. #ifndef ESOCKTNOSUPPORT
  279. #define ESOCKTNOSUPPORT    121    /* Socket type not supported */
  280. #endif
  281. #ifndef EOPNOTSUPP
  282. #define EOPNOTSUPP    122    /* Operation not supported on socket */
  283. #endif
  284. #ifndef EPFNOSUPPORT
  285. #define EPFNOSUPPORT    123    /* Protocol family not supported */
  286. #endif
  287. #ifndef EAFNOSUPPORT
  288. #define EAFNOSUPPORT    124    /* Address family not supported */
  289. #endif
  290. #ifndef EADDRINUSE
  291. #define EADDRINUSE    125    /* Address already in use */
  292. #endif
  293. #ifndef EADDRNOTAVAIL
  294. #define EADDRNOTAVAIL    126    /* Can't assign requested address */
  295. #endif
  296. #ifndef ENETDOWN
  297. #define ENETDOWN    127    /* Network is down */
  298. #endif
  299. #ifndef ENETUNREACH
  300. #define ENETUNREACH    128    /* Network is unreachable */
  301. #endif
  302. #ifndef ENETRESET
  303. #define ENETRESET    129    /* Network dropped connection on reset */
  304. #endif
  305. #ifndef ECONNABORTED
  306. #define ECONNABORTED    130    /* Software caused connection abort */
  307. #endif
  308. #ifndef ECONNRESET
  309. #define ECONNRESET    131    /* Connection reset by peer */
  310. #endif
  311. #ifndef ENOBUFS
  312. #define ENOBUFS        132    /* No buffer space available */
  313. #endif
  314. #ifndef EISCONN
  315. #define EISCONN        133    /* Socket is already connected */
  316. #endif
  317. #ifndef ENOTCONN
  318. #define ENOTCONN    134    /* Socket is not connected */
  319. #endif
  320. #ifndef ESHUTDOWN
  321. #define ESHUTDOWN    143    /* Can't send after socket shutdown */
  322. #endif
  323. #ifndef ETOOMANYREFS
  324. #define ETOOMANYREFS    144    /* Too many references: can't splice */
  325. #endif
  326. #ifndef ETIMEDOUT
  327. #define ETIMEDOUT    145    /* Connection timed out */
  328. #endif
  329. #ifndef ECONNREFUSED
  330. #define ECONNREFUSED    146    /* Connection refused */
  331. #endif
  332. #ifndef ELOOP
  333. #define ELOOP        90    /* Symbolic link loop */
  334. #endif
  335. #ifndef EHOSTDOWN
  336. #define EHOSTDOWN    147    /* Host is down */
  337. #endif
  338. #ifndef EHOSTUNREACH
  339. #define EHOSTUNREACH    148    /* No route to host */
  340. #endif
  341. #ifndef ENOTEMPTY
  342. #define ENOTEMPTY     93    /* directory not empty */
  343. #endif
  344. #ifndef EUSERS
  345. #define EUSERS        94    /* Too many users (for UFS) */
  346. #endif
  347. #ifndef EDQUOT
  348. #define EDQUOT        49    /* Disc quota exceeded */
  349. #endif
  350. #ifndef ESTALE
  351. #define ESTALE        151    /* Stale NFS file handle */
  352. #endif
  353. #ifndef EREMOTE
  354. #define EREMOTE        66    /* The object is remote */
  355. #endif
  356.  
  357. /*
  358.  * The following defines map from standard socket names to our internal
  359.  * wrappers that redirect through the winSock function table (see the
  360.  * file tclWinSock.c).
  361.  */
  362.  
  363. #define getservbyname    TclWinGetServByName
  364. #define getsockopt    TclWinGetSockOpt
  365. #define ntohs        TclWinNToHS
  366. #define setsockopt    TclWinSetSockOpt
  367.  
  368. /*
  369.  * The following implements the Windows method for exiting the process.
  370.  */
  371. #define TclPlatformExit(status) LangExit(status)
  372.  
  373.  
  374. /*
  375.  * The following declarations belong in tclInt.h, but depend on platform
  376.  * specific types (e.g. struct tm).
  377.  */
  378.  
  379. EXTERN struct tm *    TclpGetDate _ANSI_ARGS_((const time_t *tp,
  380.                 int useGMT));
  381. EXTERN size_t        TclStrftime _ANSI_ARGS_((char *s, size_t maxsize,
  382.                 const char *format, const struct tm *t));
  383.  
  384. /*
  385.  * Declarations for Windows specific functions.
  386.  */
  387.  
  388. EXTERN void        TclWinConvertError _ANSI_ARGS_((DWORD errCode));
  389. EXTERN void        TclWinConvertWSAError _ANSI_ARGS_((DWORD errCode));
  390. EXTERN struct servent * PASCAL FAR
  391.             TclWinGetServByName _ANSI_ARGS_((const char FAR *nm,
  392.                     const char FAR *proto));
  393. EXTERN int PASCAL FAR    TclWinGetSockOpt _ANSI_ARGS_((SOCKET s, int level,
  394.                     int optname, char FAR * optval, int FAR *optlen));
  395. EXTERN HINSTANCE    TclWinGetTclInstance _ANSI_ARGS_((void));
  396. EXTERN HINSTANCE    TclWinLoadLibrary _ANSI_ARGS_((char *name));
  397. EXTERN void        TclWinNotifySocket _ANSI_ARGS_((void));
  398. EXTERN u_short PASCAL FAR
  399.             TclWinNToHS _ANSI_ARGS_((u_short ns));
  400. EXTERN int PASCAL FAR    TclWinSetSockOpt _ANSI_ARGS_((SOCKET s, int level,
  401.                     int optname, const char FAR * optval, int optlen));
  402. EXTERN int        TclWinSocketReady _ANSI_ARGS_((Tcl_File file,
  403.                 int mask));
  404. EXTERN void        TclWinWatchSocket _ANSI_ARGS_((Tcl_File file,
  405.                 int mask));
  406. #endif /* _TCLWINPORT */
  407.