home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcltk805.zip / tcl805s.zip / tcl8.0.5 / os2 / tclOS2Port.h < prev    next >
C/C++ Source or Header  |  2001-02-09  |  7KB  |  301 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) 1994-1996 Sun Microsystems, Inc.
  9.  * Copyright (c) 1996-2001 Illya Vaes
  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. /* BSD sockets from EMX are int */
  34. #define SOCKET int
  35. #include <sys/types.h>
  36. #include <sys/socket.h>
  37. #include <netinet/in.h>
  38. #include <netdb.h>
  39. #include <arpa/inet.h>
  40. #include <sys/utsname.h>
  41. #include <sys/ioctl.h>
  42. #include <sys/select.h>
  43. #include <io.h>
  44.  
  45. #include <malloc.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <sys/errno.h>
  50. #include <process.h>
  51. #include <signal.h>
  52. #include <sys/time.h>
  53. #include <sys/timeb.h>
  54. #include <sys/stat.h>
  55. #include <fcntl.h>
  56. #include <float.h>
  57.  
  58. /*
  59.  * If ENOTSUP is not defined, define it to a value that will never occur.
  60.  */
  61.  
  62. #ifndef ENOTSUP
  63. #define ENOTSUP         -1030507
  64. #endif
  65.  
  66. /*
  67.  * The default platform eol translation on OS/2 is TCL_TRANSLATE_CRLF:
  68.  */
  69.  
  70. #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_CRLF
  71.  
  72. /*
  73.  * Declare dynamic loading extension macro.
  74.  */
  75.  
  76. #define TCL_SHLIB_EXT ".dll"
  77.  
  78. /*
  79.  * Declare directory manipulation routines.
  80.  */
  81.  
  82. #ifdef HAS_DIRENT
  83. #    include <dirent.h>
  84. #else /* HAS_DIRENT */
  85.  
  86. #include <direct.h>
  87. #define MAXNAMLEN 255
  88.  
  89. struct dirent {
  90.     long d_ino;            /* Inode number of entry */
  91.     short d_reclen;        /* Length of this record */
  92.     short d_namlen;        /* Length of string in d_name */
  93.     char d_name[MAXNAMLEN + 1];
  94.                 /* Name must be no longer than this */
  95. };
  96.  
  97. typedef struct _dirdesc DIR;
  98.  
  99. EXTERN void            closedir _ANSI_ARGS_((DIR *dirp));
  100. EXTERN DIR *            opendir _ANSI_ARGS_((char *name));
  101. EXTERN struct dirent *        readdir _ANSI_ARGS_((DIR *dirp));
  102. #endif /* HAS_DIRENT */
  103.  
  104. /*
  105.  * Supply definitions for macros to query wait status, if not already
  106.  * defined in header files above.
  107.  */
  108.  
  109. #if TCL_UNION_WAIT
  110. #   define WAIT_STATUS_TYPE union wait
  111. #else
  112. #   define WAIT_STATUS_TYPE int
  113. #endif
  114.  
  115. #ifndef WIFEXITED
  116. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  117. #endif
  118.  
  119. #ifndef WEXITSTATUS
  120. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  121. #endif
  122.  
  123. #ifndef WIFSIGNALED
  124. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  125. #endif
  126.  
  127. #ifndef WTERMSIG
  128. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  129. #endif
  130.  
  131. #ifndef WIFSTOPPED
  132. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  133. #endif
  134.  
  135. #ifndef WSTOPSIG
  136. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  137. #endif
  138.  
  139. /*
  140.  * Define constants for waitpid() system call if they aren't defined
  141.  * by a system header file.
  142.  */
  143.  
  144. #ifndef WNOHANG
  145. #   define WNOHANG 1
  146. #endif
  147. #ifndef WUNTRACED
  148. #   define WUNTRACED 2
  149. #endif
  150.  
  151. /*
  152.  * Define MAXPATHLEN in terms of MAXPATH if available
  153.  */
  154.  
  155. #ifndef MAX_PATH
  156. #define MAX_PATH CCHMAXPATH
  157. #endif
  158.  
  159. #ifndef MAXPATH
  160. #define MAXPATH MAX_PATH
  161. #endif /* MAXPATH */
  162.  
  163. #ifndef MAXPATHLEN
  164. #define MAXPATHLEN MAXPATH
  165. #endif /* MAXPATHLEN */
  166.  
  167. #ifndef F_OK
  168. #    define F_OK 00
  169. #endif
  170. #ifndef X_OK
  171. #    define X_OK 01
  172. #endif
  173. #ifndef W_OK
  174. #    define W_OK 02
  175. #endif
  176. #ifndef R_OK
  177. #    define R_OK 04
  178. #endif
  179.  
  180. /*
  181.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  182.  * define "lstat" to use "stat" instead.
  183.  
  184. #ifndef S_IFLNK
  185. #   define lstat stat
  186. #endif
  187.  */
  188.  
  189. /*
  190.  * Define macros to query file type bits, if they're not already
  191.  * defined.
  192.  */
  193.  
  194. #ifndef S_ISREG
  195. #   ifdef S_IFREG
  196. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  197. #   else
  198. #       define S_ISREG(m) 0
  199. #   endif
  200. # endif
  201. #ifndef S_ISDIR
  202. #   ifdef S_IFDIR
  203. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  204. #   else
  205. #       define S_ISDIR(m) 0
  206. #   endif
  207. # endif
  208. #ifndef S_ISCHR
  209. #   ifdef S_IFCHR
  210. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  211. #   else
  212. #       define S_ISCHR(m) 0
  213. #   endif
  214. # endif
  215. #ifndef S_ISBLK
  216. #   ifdef S_IFBLK
  217. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  218. #   else
  219. #       define S_ISBLK(m) 0
  220. #   endif
  221. # endif
  222. #ifndef S_ISFIFO
  223. #   ifdef S_IFIFO
  224. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  225. #   else
  226. #       define S_ISFIFO(m) 0
  227. #   endif
  228. # endif
  229.  
  230. /*
  231.  * Define pid_t and uid_t if they're not already defined.
  232.  */
  233.  
  234. #if ! TCL_PID_T
  235. #   define pid_t int
  236. #endif
  237. #if ! TCL_UID_T
  238. #   define uid_t int
  239. #endif
  240.  
  241. /*
  242.  * Substitute Tcl's own versions for several system calls.
  243.  */
  244.  
  245. #define matherr        _matherr
  246.  
  247. /*
  248.  * Provide a stub definition for TclGetUserHome().
  249.  */
  250.  
  251. #define TclGetUserHome(name,bufferPtr) (NULL)
  252.  
  253. /*
  254.  * The following functions always succeed.
  255.  */
  256.  
  257. #define TclHasSockets(arg) (TCL_OK)
  258. #define TclpGetPid(pid) (pid)
  259.  
  260. /*
  261.  * The following declarations belong in tclInt.h, but depend on platform
  262.  * specific types (e.g. struct tm).
  263.  */
  264.  
  265. EXTERN struct tm *      TclpGetDate _ANSI_ARGS_((const time_t *tp,
  266.                             int useGMT));
  267. #define TclStrftime(s,m,f,t) (strftime((s),(m),(f),(t)))
  268.  
  269. /*
  270.  * Defines for stuff unimplemented in C runtime.
  271.  */
  272.  
  273.  
  274. /*
  275.  * The following prototypes and defines replace the OS/2 versions
  276.  * of POSIX function that various compilier vendors didn't implement
  277.  * well or consistantly.
  278.  */
  279.  
  280. #define lstat    stat
  281.  
  282. EXTERN int    TclpStat _ANSI_ARGS_((CONST char *path, struct stat *buf));
  283. EXTERN int    TclpAccess _ANSI_ARGS_((CONST char *path, int mode));
  284.  
  285. #define TclpReleaseFile(file)   ckfree((char *) file)
  286.  
  287. /*
  288.  * Declarations for OS/2 specific functions.
  289.  */
  290.  
  291. EXTERN void        TclOS2ConvertError _ANSI_ARGS_((ULONG errCode));
  292. EXTERN HMODULE          TclOS2LoadLibrary _ANSI_ARGS_((char *name));
  293. EXTERN HMODULE        TclOS2GetTclInstance _ANSI_ARGS_((void));
  294. EXTERN HAB        TclOS2GetHAB _ANSI_ARGS_((void));
  295. EXTERN BOOL        TclOS2PMInitialize _ANSI_ARGS_((void));
  296. EXTERN void        TclOS2PMShutdown _ANSI_ARGS_((void));
  297. EXTERN int        TclOS2WaitForFile _ANSI_ARGS_((HFILE handle, int mask,
  298.                 int timeout));
  299.  
  300. #endif /* _TCLOS2PORT */
  301.