home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tkisrc04.zip / tcl / os2 / tclOS2Port.h < prev    next >
C/C++ Source or Header  |  1998-08-07  |  7KB  |  329 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-1997 Illya Vaes
  9.  * Copyright (c) 1994-1995 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. #define INCL_DOSPROCESS /*MM*/
  22. #include <os2.h>
  23. #undef INCL_DOSPROCESS /*MM*/
  24. #undef INCL_PM
  25. #undef INCL_BASE
  26.  
  27. #ifndef OS2
  28. #define OS2
  29. #endif
  30.  
  31. /* Global variables */
  32. extern HAB hab;    /* Anchor block */
  33. extern HMQ hmq;    /* Message queue */
  34. extern ULONG maxPath;    /* Maximum path length */
  35.  
  36. /* Definitions */
  37. #define FS_CASE_SENSITIVE    1
  38. #define FS_CASE_IS_PRESERVED 2
  39.  
  40. #include <sys/types.h>
  41.  
  42. /* *MM* added this to get fd_set */
  43. #ifdef __IBMC__
  44. #include <sys/select.h>
  45. #endif
  46.  
  47. /* BSD sockets from EMX are int */
  48. #define SOCKET int
  49. #include <sys/socket.h>
  50. #include <netinet/in.h>
  51. #include <sys/ioctl.h>
  52. #include <netdb.h>
  53. //#include <arpa/inet.h> *MM*
  54. //#include <sys/utsname.h> *MM*
  55.  
  56. #include <malloc.h>
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60. /* *MM* replaced first include with this fancy wrapper */
  61. #ifdef EMX
  62. #include <sys/errno.h>
  63. #else
  64. // use TCP/IP's errno as well as libC errno
  65. #include <errno.h>
  66. #include <nerrno.h>
  67. #define EPIPE SOCEPIPE
  68. #define EFAULT SOCEFAULT
  69. #define EPERM SOCEPERM
  70. #define ESRCH SOCESRCH
  71. #define EROFS 666
  72. #define EIO 667
  73. #define ESPIPE 668
  74. #endif
  75. #include <process.h>
  76. #include <signal.h>
  77. #include <time.h>
  78. /* *MM* - for vacpp, map timezone variable. */
  79. #ifdef __IBMC__
  80. #define timezone _timezone
  81. #endif
  82. #include <sys/time.h>
  83. #include <sys/timeb.h>
  84. #include <sys/stat.h>
  85. #include <io.h>
  86. #include <fcntl.h>
  87.  
  88. /*
  89.  * If ENOTSUP is not defined, define it to a value that will never occur.
  90.  */
  91.  
  92. #ifndef ENOTSUP
  93. #define ENOTSUP         -1030507
  94. #endif
  95.  
  96. /*
  97.  * The default platform eol translation on OS/2 is TCL_TRANSLATE_CRLF:
  98.  */
  99.  
  100. #define TCL_PLATFORM_TRANSLATION        TCL_TRANSLATE_CRLF
  101.  
  102. /*
  103.  * Declare dynamic loading extension macro.
  104.  */
  105.  
  106. #define TCL_SHLIB_EXT ".dll"
  107.  
  108. /*
  109.  * Declare directory manipulation routines.
  110.  */
  111.  
  112. #ifdef HAS_DIRENT
  113. #    include <dirent.h>
  114. #else /* HAS_DIRENT */
  115.  
  116. #include <direct.h>
  117. #define MAXNAMLEN 255
  118.  
  119. struct dirent {
  120.     long d_ino;            /* Inode number of entry */
  121.     short d_reclen;        /* Length of this record */
  122.     short d_namlen;        /* Length of string in d_name */
  123.     char d_name[MAXNAMLEN + 1];
  124.                 /* Name must be no longer than this */
  125. };
  126.  
  127. typedef struct _dirdesc DIR;
  128.  
  129. EXTERN void            closedir _ANSI_ARGS_((DIR *dirp));
  130. EXTERN DIR *            opendir _ANSI_ARGS_((char *name));
  131. EXTERN struct dirent *        readdir _ANSI_ARGS_((DIR *dirp));
  132. #endif /* HAS_DIRENT */
  133.  
  134. /*
  135.  * Supply definitions for macros to query wait status, if not already
  136.  * defined in header files above.
  137.  */
  138.  
  139. #if TCL_UNION_WAIT
  140. #   define WAIT_STATUS_TYPE union wait
  141. #else
  142. #   define WAIT_STATUS_TYPE int
  143. #endif
  144.  
  145. #ifndef WIFEXITED
  146. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  147. #endif
  148.  
  149. #ifndef WEXITSTATUS
  150. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  151. #endif
  152.  
  153. #ifndef WIFSIGNALED
  154. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  155. #endif
  156.  
  157. #ifndef WTERMSIG
  158. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  159. #endif
  160.  
  161. #ifndef WIFSTOPPED
  162. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  163. #endif
  164.  
  165. #ifndef WSTOPSIG
  166. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  167. #endif
  168.  
  169. /*
  170.  * Define constants for waitpid() system call if they aren't defined
  171.  * by a system header file.
  172.  */
  173.  
  174. #ifndef WNOHANG
  175. #   define WNOHANG 1
  176. #endif
  177. #ifndef WUNTRACED
  178. #   define WUNTRACED 2
  179. #endif
  180.  
  181. /*
  182.  * Define MAXPATHLEN in terms of MAXPATH if available
  183.  */
  184.  
  185. #ifndef MAX_PATH
  186. #define MAX_PATH CCHMAXPATH
  187. #endif
  188.  
  189. #ifndef MAXPATH
  190. #define MAXPATH MAX_PATH
  191. #endif /* MAXPATH */
  192.  
  193. #ifndef MAXPATHLEN
  194. #define MAXPATHLEN MAXPATH
  195. #endif /* MAXPATHLEN */
  196.  
  197. #ifndef F_OK
  198. #    define F_OK 00
  199. #endif
  200. #ifndef X_OK
  201. #    define X_OK 01
  202. #endif
  203. #ifndef W_OK
  204. #    define W_OK 02
  205. #endif
  206. #ifndef R_OK
  207. #    define R_OK 04
  208. #endif
  209.  
  210. /*
  211.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  212.  * define "lstat" to use "stat" instead.
  213.  */
  214.  
  215. #ifndef S_IFLNK
  216. #   define lstat stat
  217. #endif
  218.  
  219. /*
  220.  * Define macros to query file type bits, if they're not already
  221.  * defined.
  222.  */
  223.  
  224. /* *MM* added this ifndef clause */
  225. #ifndef S_IFMT
  226. #define S_IFMT 0xFFFF
  227. #endif
  228.  
  229. #ifndef S_ISREG
  230. #   ifdef S_IFREG
  231. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  232. #   else
  233. #       define S_ISREG(m) 0
  234. #   endif
  235. # endif
  236. #ifndef S_ISDIR
  237. #   ifdef S_IFDIR
  238. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  239. #   else
  240. #       define S_ISDIR(m) 0
  241. #   endif
  242. # endif
  243. #ifndef S_ISCHR
  244. #   ifdef S_IFCHR
  245. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  246. #   else
  247. #       define S_ISCHR(m) 0
  248. #   endif
  249. # endif
  250. #ifndef S_ISBLK
  251. #   ifdef S_IFBLK
  252. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  253. #   else
  254. #       define S_ISBLK(m) 0
  255. #   endif
  256. # endif
  257. #ifndef S_ISFIFO
  258. #   ifdef S_IFIFO
  259. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  260. #   else
  261. #       define S_ISFIFO(m) 0
  262. #   endif
  263. # endif
  264. #ifndef S_ISLNK
  265. #   ifdef S_IFLNK
  266. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  267. #   else
  268. #       define S_ISLNK(m) 0
  269. #   endif
  270. # endif
  271. #ifndef S_ISSOCK
  272. #   ifdef S_IFSOCK
  273. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  274. #   else
  275. #       define S_ISSOCK(m) 0
  276. #   endif
  277. # endif
  278.  
  279. /*
  280.  * Define pid_t and uid_t if they're not already defined.
  281.  */
  282.  
  283. #if ! TCL_PID_T
  284. #   define pid_t int
  285. #endif
  286. #if ! TCL_UID_T
  287. #   define uid_t int
  288. #endif
  289.  
  290. /*
  291.  * Substitute Tcl's own versions for several system calls.
  292.  */
  293.  
  294. #define matherr        _matherr
  295.  
  296. /*
  297.  * Provide a stub definition for TclGetUserHome().
  298.  */
  299.  
  300. #define TclGetUserHome(name,bufferPtr) (NULL)
  301.  
  302. /*
  303.  * Declarations for OS/2 specific functions.
  304.  */
  305.  
  306. EXTERN int        TclSetSystemEnv _ANSI_ARGS_((const char *variable,
  307.                                                      const char *value));
  308. EXTERN void        TclOS2WatchSocket _ANSI_ARGS_((Tcl_File file,
  309.                                                        int mask));
  310. EXTERN int        TclOS2SocketReady _ANSI_ARGS_((Tcl_File file,
  311.                                                        int mask));
  312. EXTERN void        TclOS2NotifySocket _ANSI_ARGS_((void));
  313. EXTERN void        TclOS2ConvertError _ANSI_ARGS_((ULONG errCode));
  314. EXTERN HMODULE        TclOS2LoadLibrary _ANSI_ARGS_((char *name));
  315. EXTERN HMODULE        TclOS2GetTclInstance _ANSI_ARGS_((void));
  316. EXTERN HAB        TclOS2GetHAB _ANSI_ARGS_((void));
  317. EXTERN BOOL        PMInitialize _ANSI_ARGS_((void));
  318. EXTERN void        PMShutdown _ANSI_ARGS_((void));
  319.  
  320.  
  321. /*
  322.  * The following macro defines the character that marks the end of
  323.  * a line.
  324.  */
  325.  
  326. #define NEWLINE_CHAR '\n'
  327.  
  328. #endif /* _TCLOS2PORT */
  329.