home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / lib / tclOS2Port.h < prev    next >
C/C++ Source or Header  |  1999-07-27  |  7KB  |  317 lines

  1. /*
  2.  * tclOS2Port.h --
  3.  *
  4.  *    This header file handles porting issues that occur because of
  5.  *    differences between OS/2 and Unix. It should be the only file
  6.  *    that contains #ifdefs to handle different flavors of OS.
  7.  *
  8.  * Copyright (c) 1996-1998 Illya Vaes
  9.  * Copyright (c) 1994-1996 Sun Microsystems, Inc.
  10.  *
  11.  * See the file "license.terms" for information on usage and redistribution
  12.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  *
  14.  */
  15.  
  16. #ifndef _TCLOS2PORT
  17. #define _TCLOS2PORT
  18.  
  19. #define INCL_BASE
  20. #define INCL_PM
  21. #include <os2.h>
  22. #undef INCL_PM
  23. #undef INCL_BASE
  24.  
  25. #ifndef OS2
  26. #define OS2
  27. #endif
  28.  
  29. /* Global variables */
  30. extern HAB hab;    /* Anchor block */
  31. extern HMQ hmq;    /* Message queue */
  32.  
  33. #include <sys/types.h>
  34.  
  35. /* BSD sockets from EMX are int */
  36. #define SOCKET int
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <netinet/in.h>
  40. #include <netdb.h>
  41. #include <arpa/inet.h>
  42. #include <sys/utsname.h>
  43. #include <sys/ioctl.h>
  44. #include <sys/select.h>
  45. #include <io.h>
  46.  
  47. #include <malloc.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <sys/errno.h>
  52. #include <process.h>
  53. #include <signal.h>
  54. #include <sys/time.h>
  55. #include <sys/timeb.h>
  56. #include <sys/stat.h>
  57. #include <fcntl.h>
  58. #include <float.h>
  59.  
  60. /*
  61.  * If ENOTSUP is not defined, define it to a value that will never occur.
  62.  */
  63.  
  64. #ifndef ENOTSUP
  65. #define ENOTSUP         -1030507
  66. #endif
  67.  
  68. /*
  69.  * The following defines denote malloc and free as the system calls
  70.  * used to allocate new memory.  These defines are only used in the
  71.  * file tclCkalloc.c.
  72.  */
  73.  
  74. #define TclpAlloc(size)         malloc(size)
  75. #define TclpFree(ptr)           free(ptr)
  76. #define TclpRealloc(ptr, size)  realloc(ptr, size)
  77.  
  78. /*
  79.  * The default platform eol translation on OS/2 is TCL_TRANSLATE_CRLF:
  80.  */
  81.  
  82. #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_CRLF
  83.  
  84. /*
  85.  * Declare dynamic loading extension macro.
  86.  */
  87.  
  88. #define TCL_SHLIB_EXT ".dll"
  89.  
  90. /*
  91.  * Declare directory manipulation routines.
  92.  */
  93.  
  94. #ifdef HAS_DIRENT
  95. #    include <dirent.h>
  96. #else /* HAS_DIRENT */
  97.  
  98. #include <direct.h>
  99. #define MAXNAMLEN 255
  100.  
  101. struct dirent {
  102.     long d_ino;            /* Inode number of entry */
  103.     short d_reclen;        /* Length of this record */
  104.     short d_namlen;        /* Length of string in d_name */
  105.     char d_name[MAXNAMLEN + 1];
  106.                 /* Name must be no longer than this */
  107. };
  108.  
  109. typedef struct _dirdesc DIR;
  110.  
  111. EXTERN void            closedir _ANSI_ARGS_((DIR *dirp));
  112. EXTERN DIR *            opendir _ANSI_ARGS_((char *name));
  113. EXTERN struct dirent *        readdir _ANSI_ARGS_((DIR *dirp));
  114. #endif /* HAS_DIRENT */
  115.  
  116. /*
  117.  * Supply definitions for macros to query wait status, if not already
  118.  * defined in header files above.
  119.  */
  120.  
  121. #if TCL_UNION_WAIT
  122. #   define WAIT_STATUS_TYPE union wait
  123. #else
  124. #   define WAIT_STATUS_TYPE int
  125. #endif
  126.  
  127. #ifndef WIFEXITED
  128. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  129. #endif
  130.  
  131. #ifndef WEXITSTATUS
  132. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  133. #endif
  134.  
  135. #ifndef WIFSIGNALED
  136. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  137. #endif
  138.  
  139. #ifndef WTERMSIG
  140. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  141. #endif
  142.  
  143. #ifndef WIFSTOPPED
  144. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  145. #endif
  146.  
  147. #ifndef WSTOPSIG
  148. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  149. #endif
  150.  
  151. /*
  152.  * Define constants for waitpid() system call if they aren't defined
  153.  * by a system header file.
  154.  */
  155.  
  156. #ifndef WNOHANG
  157. #   define WNOHANG 1
  158. #endif
  159. #ifndef WUNTRACED
  160. #   define WUNTRACED 2
  161. #endif
  162.  
  163. /*
  164.  * Define MAXPATHLEN in terms of MAXPATH if available
  165.  */
  166.  
  167. #ifndef MAX_PATH
  168. #define MAX_PATH CCHMAXPATH
  169. #endif
  170.  
  171. #ifndef MAXPATH
  172. #define MAXPATH MAX_PATH
  173. #endif /* MAXPATH */
  174.  
  175. #ifndef MAXPATHLEN
  176. #define MAXPATHLEN MAXPATH
  177. #endif /* MAXPATHLEN */
  178.  
  179. #ifndef F_OK
  180. #    define F_OK 00
  181. #endif
  182. #ifndef X_OK
  183. #    define X_OK 01
  184. #endif
  185. #ifndef W_OK
  186. #    define W_OK 02
  187. #endif
  188. #ifndef R_OK
  189. #    define R_OK 04
  190. #endif
  191.  
  192. /*
  193.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  194.  * define "lstat" to use "stat" instead.
  195.  */
  196.  
  197. #ifndef S_IFLNK
  198. #   define lstat stat
  199. #endif
  200.  
  201. /*
  202.  * Define macros to query file type bits, if they're not already
  203.  * defined.
  204.  */
  205.  
  206. #ifndef S_ISREG
  207. #   ifdef S_IFREG
  208. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  209. #   else
  210. #       define S_ISREG(m) 0
  211. #   endif
  212. # endif
  213. #ifndef S_ISDIR
  214. #   ifdef S_IFDIR
  215. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  216. #   else
  217. #       define S_ISDIR(m) 0
  218. #   endif
  219. # endif
  220. #ifndef S_ISCHR
  221. #   ifdef S_IFCHR
  222. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  223. #   else
  224. #       define S_ISCHR(m) 0
  225. #   endif
  226. # endif
  227. #ifndef S_ISBLK
  228. #   ifdef S_IFBLK
  229. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  230. #   else
  231. #       define S_ISBLK(m) 0
  232. #   endif
  233. # endif
  234. #ifndef S_ISFIFO
  235. #   ifdef S_IFIFO
  236. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  237. #   else
  238. #       define S_ISFIFO(m) 0
  239. #   endif
  240. # endif
  241. #ifndef S_ISLNK
  242. #   ifdef S_IFLNK
  243. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  244. #   else
  245. #       define S_ISLNK(m) 0
  246. #   endif
  247. # endif
  248. #ifndef S_ISSOCK
  249. #   ifdef S_IFSOCK
  250. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  251. #   else
  252. #       define S_ISSOCK(m) 0
  253. #   endif
  254. # endif
  255.  
  256. /*
  257.  * Define pid_t and uid_t if they're not already defined.
  258.  */
  259.  
  260. #if ! TCL_PID_T
  261. #   define pid_t int
  262. #endif
  263. #if ! TCL_UID_T
  264. #   define uid_t int
  265. #endif
  266.  
  267. /*
  268.  * Substitute Tcl's own versions for several system calls.
  269.  */
  270.  
  271. #define matherr        _matherr
  272.  
  273. /*
  274.  * Provide a stub definition for TclGetUserHome().
  275.  */
  276.  
  277. #define TclGetUserHome(name,bufferPtr) (NULL)
  278.  
  279. /*
  280.  * The following functions always succeed.
  281.  */
  282.  
  283. #define TclHasSockets(interp) (TCL_OK)
  284. #define TclHasPipes() (1)
  285.  
  286. /*
  287.  * The following declarations belong in tclInt.h, but depend on platform
  288.  * specific types (e.g. struct tm).
  289.  */
  290.  
  291. EXTERN struct tm *      TclpGetDate _ANSI_ARGS_((const time_t *tp,
  292.                             int useGMT));
  293. #define TclStrftime(s,m,f,t) (strftime((s),(m),(f),(t)))
  294.  
  295. /*
  296.  * Declarations for OS/2 specific functions.
  297.  */
  298.  
  299. EXTERN void        TclOS2WatchSocket _ANSI_ARGS_((Tcl_File file, int mask));
  300. EXTERN int        TclOS2SocketReady _ANSI_ARGS_((Tcl_File file, int mask));
  301. EXTERN void        TclOS2NotifySocket _ANSI_ARGS_((void));
  302. EXTERN void        TclOS2ConvertError _ANSI_ARGS_((ULONG errCode));
  303. EXTERN HMODULE        TclOS2LoadLibrary _ANSI_ARGS_((char *name));
  304. EXTERN HAB        TclOS2GetHAB _ANSI_ARGS_((void));
  305. EXTERN BOOL        TclOS2PMInitialize _ANSI_ARGS_((void));
  306. EXTERN void        TclOS2PMShutdown _ANSI_ARGS_((void));
  307.  
  308.  
  309. /*
  310.  * The following macro defines the character that marks the end of
  311.  * a line.
  312.  */
  313.  
  314. #define NEWLINE_CHAR '\n'
  315.  
  316. #endif /* _TCLOS2PORT */
  317.