home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / fs / FSlibos.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-23  |  9.4 KB  |  343 lines

  1. /* $XConsortium: FSlibos.h,v 1.11 91/07/23 18:59:49 rws Exp $ */
  2.  
  3. /* @(#)FSlibos.h    4.1    91/05/02
  4.  * Copyright 1990 Network Computing Devices;
  5.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  6.  * Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this protoype software
  9.  * and its documentation to Members and Affiliates of the MIT X Consortium
  10.  * any purpose and without fee is hereby granted, provided
  11.  * that the above copyright notice appear in all copies and that both that
  12.  * copyright notice and this permission notice appear in supporting
  13.  * documentation, and that the names of Network Computing Devices, Digital or
  14.  * MIT not be used in advertising or publicity pertaining to distribution of
  15.  * the software without specific, written prior permission.
  16.  *
  17.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  18.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  19.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  20.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  22.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  23.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25.  
  26. /*
  27.  * FSlib networking & os include file
  28.  */
  29.  
  30. #include <X11/Xfuncs.h>
  31. #include <X11/Xosdefs.h>
  32.  
  33. /* Sorry, we do not really support streams yet */
  34. #ifdef STREAMSCONN
  35. #undef STREAMSCONN
  36. #endif
  37.  
  38. #ifdef STREAMSCONN
  39. #ifdef SYSV
  40. /*
  41.  * UNIX System V Release 3.2
  42.  */
  43. #include <sys/stropts.h>
  44. #define BytesReadable(fd,ptr) (_FSBytesReadable ((fd), (ptr)))
  45. #define MALLOC_0_RETURNS_NULL
  46. #include <sys/ioctl.h>
  47. #endif /* SYSV */
  48. #ifdef SVR4
  49. /*
  50.  * TLI (Streams-based) networking
  51.  */
  52. #define BytesReadable(fd,ptr) (_FSBytesReadable ((fd), (ptr)))
  53. #include <sys/uio.h>        /* define struct iovec */
  54.  
  55. #endif /* SVR4 */
  56. #else /* not STREAMSCONN */
  57. /*
  58.  * 4.2BSD-based systems
  59.  */
  60. #include <netinet/in.h>
  61. #include <sys/ioctl.h>
  62. #include <netdb.h>
  63. #include <sys/uio.h>        /* needed for FSlibInt.c */
  64. #ifdef SVR4
  65. #include <sys/filio.h>
  66. #endif
  67.  
  68. #if defined(SYSV386) && defined(SYSV)
  69. #include <net/errno.h>
  70. #include <sys/stropts.h>
  71. #define BytesReadable(fd,ptr) ioctl((fd), I_NREAD, (ptr))
  72. #else
  73. #define BytesReadable(fd, ptr) ioctl ((fd), FIONREAD, (ptr))
  74. #endif
  75. #endif /* STREAMSCONN else */
  76.  
  77. #ifndef X_NOT_POSIX
  78. #ifdef _POSIX_SOURCE
  79. #include <limits.h>
  80. #else
  81. #define _POSIX_SOURCE
  82. #include <limits.h>
  83. #undef _POSIX_SOURCE
  84. #endif
  85. #endif
  86. #ifndef OPEN_MAX
  87. #ifdef SVR4
  88. #define OPEN_MAX 256
  89. #else
  90. #include <sys/param.h>
  91. #ifndef OPEN_MAX
  92. #ifdef NOFILE
  93. #define OPEN_MAX NOFILE
  94. #else
  95. #define OPEN_MAX NOFILES_MAX
  96. #endif
  97. #endif
  98. #endif
  99. #endif
  100.  
  101. /* Utek leaves kernel macros around in include files (bleah) */
  102.  
  103. #ifdef dirty
  104. #undef dirty
  105. #endif
  106.  
  107. #ifdef CRAY
  108. #define WORD64
  109. #endif
  110.  
  111. #if OPEN_MAX > 256
  112. #undef OPEN_MAX
  113. #define OPEN_MAX 256
  114. #endif
  115.  
  116. #define MSKCNT ((OPEN_MAX + 31) / 32)
  117.  
  118. #if (MSKCNT==1)
  119. #define BITMASK(i) (1 << (i))
  120. #define MASKIDX(i) 0
  121. #endif
  122.  
  123. #if (MSKCNT>1)
  124. #define BITMASK(i) (1 << ((i) & 31))
  125. #define MASKIDX(i) ((i) >> 5)
  126. #endif
  127.  
  128. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  129. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  130. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  131. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  132.  
  133. #if (MSKCNT==1)
  134. #define COPYBITS(src, dst) dst[0] = src[0]
  135. #define CLEARBITS(buf) buf[0] = 0
  136. #define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
  137. #define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
  138. #define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
  139. #define _FSANYSET(src) (src[0])
  140. #endif
  141.  
  142. #if (MSKCNT==2)
  143. #define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; }
  144. #define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; }
  145. #define MASKANDSETBITS(dst, b1, b2)  {\
  146.               dst[0] = (b1[0] & b2[0]);\
  147.               dst[1] = (b1[1] & b2[1]); }
  148. #define ORBITS(dst, b1, b2)  {\
  149.               dst[0] = (b1[0] | b2[0]);\
  150.               dst[1] = (b1[1] | b2[1]); }
  151. #define UNSETBITS(dst, b1) {\
  152.                       dst[0] &= ~b1[0]; \
  153.                       dst[1] &= ~b1[1]; }
  154. #define _FSANYSET(src) (src[0] || src[1])
  155. #endif
  156.  
  157. #if (MSKCNT==3)
  158. #define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \
  159.                  dst[2] = src[2]; }
  160. #define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; }
  161. #define MASKANDSETBITS(dst, b1, b2)  {\
  162.               dst[0] = (b1[0] & b2[0]);\
  163.               dst[1] = (b1[1] & b2[1]);\
  164.               dst[2] = (b1[2] & b2[2]); }
  165. #define ORBITS(dst, b1, b2)  {\
  166.               dst[0] = (b1[0] | b2[0]);\
  167.               dst[1] = (b1[1] | b2[1]);\
  168.               dst[2] = (b1[2] | b2[2]); }
  169. #define UNSETBITS(dst, b1) {\
  170.                       dst[0] &= ~b1[0]; \
  171.                       dst[1] &= ~b1[1]; \
  172.                       dst[2] &= ~b1[2]; }
  173. #define _FSANYSET(src) (src[0] || src[1] || src[2])
  174. #endif
  175.  
  176. #if (MSKCNT==4)
  177. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \
  178.                dst[2] = src[2]; dst[3] = src[3]
  179. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
  180. #define MASKANDSETBITS(dst, b1, b2)  \
  181.                       dst[0] = (b1[0] & b2[0]);\
  182.                       dst[1] = (b1[1] & b2[1]);\
  183.                       dst[2] = (b1[2] & b2[2]);\
  184.                       dst[3] = (b1[3] & b2[3])
  185. #define ORBITS(dst, b1, b2)  \
  186.                       dst[0] = (b1[0] | b2[0]);\
  187.                       dst[1] = (b1[1] | b2[1]);\
  188.                       dst[2] = (b1[2] | b2[2]);\
  189.                       dst[3] = (b1[3] | b2[3])
  190. #define UNSETBITS(dst, b1) \
  191.                       dst[0] &= ~b1[0]; \
  192.                       dst[1] &= ~b1[1]; \
  193.                       dst[2] &= ~b1[2]; \
  194.                       dst[3] &= ~b1[3]
  195. #define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3])
  196. #endif
  197.  
  198. #if (MSKCNT>4)
  199. #define COPYBITS(src, dst) bcopy((caddr_t) src, (caddr_t) dst,\
  200.                  MSKCNT*sizeof(long))
  201. #define CLEARBITS(buf) bzero((caddr_t) buf, MSKCNT*sizeof(long))
  202. #define MASKANDSETBITS(dst, b1, b2)  \
  203.               { int cri;            \
  204.             for (cri=0; cri<MSKCNT; cri++)    \
  205.                   dst[cri] = (b1[cri] & b2[cri]) }
  206. #define ORBITS(dst, b1, b2)  \
  207.               { int cri;            \
  208.               for (cri=0; cri<MSKCNT; cri++)    \
  209.                   dst[cri] = (b1[cri] | b2[cri]) }
  210. #define UNSETBITS(dst, b1) \
  211.               { int cri;            \
  212.               for (cri=0; cri<MSKCNT; cri++)    \
  213.                   dst[cri] &= ~b1[cri];  }
  214. #if (MSKCNT==8)
  215. #define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || \
  216.             src[4] || src[5] || src[6] || src[7])
  217. #endif
  218. /*
  219.  * If MSKCNT>4 and not 8, then _FSANYSET is a routine defined in FSlibInt.c.
  220.  *
  221.  * #define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
  222.  */
  223. #endif
  224.  
  225. #ifndef X_NOT_STDC_ENV
  226. #include <stdlib.h>
  227. #include <string.h>
  228. #else
  229. char *malloc(), *realloc(), *calloc();
  230. void exit();
  231. #ifdef SYSV
  232. #include <string.h>
  233. #else
  234. #include <strings.h>
  235. #endif
  236. #endif
  237. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  238. char *malloc(), *realloc(), *calloc();
  239. #endif /* macII */
  240.  
  241. /*
  242.  * The following definitions can be used for locking requests in multi-threaded
  243.  * address spaces.
  244.  */
  245. #define LockDisplay(dis)
  246. #define LockMutex(mutex)
  247. #define UnlockMutex(mutex)
  248. #define UnlockDisplay(dis)
  249. #define FSfree(ptr) free((ptr))
  250.  
  251.  
  252. /*
  253.  * Note that some machines do not return a valid pointer for malloc(0), in
  254.  * which case we provide an alternate under the control of the
  255.  * define MALLOC_0_RETURNS_NULL.  This is necessary because some
  256.  * FSlib code expects malloc(0) to return a valid pointer to storage.
  257.  */
  258.  
  259. #ifdef MALLOC_0_RETURNS_NULL
  260. #define FSmalloc(size) malloc(((size) > 0 ? (size) : 1))
  261. #define FSrealloc(ptr, size) realloc((ptr), ((size) > 0 ? (size) : 1))
  262. #define FScalloc(nelem, elsize) calloc(((nelem) > 0 ? (nelem) : 1), (elsize))
  263.  
  264. #else
  265.  
  266. #define FSmalloc(size) malloc((size))
  267. #define FSrealloc(ptr, size) realloc((ptr), (size))
  268. #define FScalloc(nelem, elsize) calloc((nelem), (elsize))
  269. #endif
  270.  
  271. /*
  272.  *    ReadvFromServer and WritevToSever use struct iovec, normally found
  273.  *    in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
  274.  *    manual pages for details.
  275.  *
  276.  *    struct iovec {
  277.  *        caddr_t iov_base;
  278.  *        int iov_len;
  279.  *    };
  280.  */
  281.  
  282. #ifdef USG
  283.  
  284. #if defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA)
  285. struct iovec {
  286.     caddr_t     iov_base;
  287.     int         iov_len;
  288. };
  289.  
  290. #ifndef __TIMEVAL__
  291. #define __TIMEVAL__
  292. struct timeval {        /* BSD has in <sys/time.h> */
  293.     long        tv_sec;
  294.     long        tv_usec;
  295. };
  296.  
  297. #endif                /* __TIMEVAL__ */
  298.  
  299. #endif                /* not CRAY or umips */
  300.  
  301. #endif                /* USG */
  302.  
  303.  
  304. #ifdef STREAMSCONN
  305. #include "FSstreams.h"
  306.  
  307. #if (!defined(EWOULDBLOCK)) && defined(EAGAIN)
  308. #define EWOULDBLOCK EAGAIN
  309. #endif
  310.  
  311. extern char _FSsTypeOfStream[];
  312. extern FSstream _FSsStream[];
  313.  
  314. #define ReadFromServer(svr, data, size) \
  315.     (*_FSsStream[_FSsTypeOfStream[svr]].ReadFromStream)((svr), (data), (size), \
  316.                              BUFFERING)
  317. #define WriteToServer(svr, bufind, size) \
  318.     (*_FSsStream[_FSsTypeOfStream[svr]].WriteToStream)((svr), (bufind), (size))
  319.  
  320. #else                /* else not STREAMSCONN */
  321.  
  322. /*
  323.  * bsd can read from sockets directly
  324.  */
  325. #define ReadFromServer(svr, data, size) read((svr), (data), (size))
  326. #define WriteToServer(svr, bufind, size) write((svr), (bufind), (size))
  327. #endif                /* STREAMSCONN */
  328.  
  329.  
  330. #ifndef USL_COMPAT
  331. #if !defined(USG) || defined(MOTOROLA)
  332. #if !(defined(SYSV) && defined(SYSV386))
  333. #define _FSReadV readv
  334. #endif
  335. #define _FSWriteV writev
  336. #endif
  337. #endif /* !USL_COMPAT */
  338.  
  339. #define ReadvFromServer(svr, iov, iovcnt) _FSReadV((svr), (iov), (iovcnt))
  340. #define WritevToServer(svr, iov, iovcnt) _FSWriteV((svr), (iov), (iovcnt))
  341.  
  342. #define SearchString(string, char) index((string), (char))
  343.