1#ifndef MEMCHAN_H 2/* 3 * memchanInt.h -- 4 * 5 * Internal definitions. 6 * 7 * Copyright (C) 1996-1999 Andreas Kupries (a.kupries@westend.com) 8 * All rights reserved. 9 * 10 * Permission is hereby granted, without written agreement and without 11 * license or royalty fees, to use, copy, modify, and distribute this 12 * software and its documentation for any purpose, provided that the 13 * above copyright notice and the following two paragraphs appear in 14 * all copies of this software. 15 * 16 * IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, 17 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS 18 * SOFTWARE AND ITS DOCUMENTATION, EVEN IF I HAVE BEEN ADVISED OF THE 19 * POSSIBILITY OF SUCH DAMAGE. 20 * 21 * I SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND 24 * I HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 25 * ENHANCEMENTS, OR MODIFICATIONS. 26 * 27 * CVS: $Id: memchanInt.h,v 1.20 2008/10/03 21:46:30 andreas_kupries Exp $ 28 */ 29 30 31#include <errno.h> 32#include <string.h> 33#define USE_NON_CONST 34#include <tcl.h> 35 36/* 37 * Make sure that both EAGAIN and EWOULDBLOCK are defined. This does not 38 * compile on systems where neither is defined. We want both defined so 39 * that we can test safely for both. In the code we still have to test for 40 * both because there may be systems on which both are defined and have 41 * different values. 42 * 43 * Taken from tcl/generic/tclIO.h 44 * Might be better if the 'tclPort' headers were public. 45 */ 46 47#if ((!defined(EWOULDBLOCK)) && (defined(EAGAIN))) 48# define EWOULDBLOCK EAGAIN 49#endif 50#if ((!defined(EAGAIN)) && (defined(EWOULDBLOCK))) 51# define EAGAIN EWOULDBLOCK 52#endif 53#if ((!defined(EAGAIN)) && (!defined(EWOULDBLOCK))) 54error one of EWOULDBLOCK or EAGAIN must be defined 55#endif 56 57#ifdef __cplusplus 58extern "C" { 59#endif 60 61/* 62 * Number of bytes used to extend a storage area found to small. 63 */ 64 65#define INCREMENT (512) 66 67/* 68 * Number of milliseconds to wait between polls of channel state, 69 * e.g. generation of readable/writable events. 70 * 71 * Relevant for only Tcl 8.0 and beyond. 72 */ 73 74#define DELAY (5) 75 76/* Detect Tcl 8.1 and beyond => Stubs, panic <-> Tcl_Panic 77 */ 78 79#define GT81 ((TCL_MAJOR_VERSION > 8) || \ 80((TCL_MAJOR_VERSION == 8) && \ 81 (TCL_MINOR_VERSION >= 1))) 82 83/* Detect Tcl 8.4 and beyond => API CONSTification 84 */ 85 86#define GT84 ((TCL_MAJOR_VERSION > 8) || \ 87((TCL_MAJOR_VERSION == 8) && \ 88 (TCL_MINOR_VERSION >= 4))) 89 90/* There are currently two cases to consider 91 * 92 * 1. An API function called with a const string, which was non-const 93 * in the relevant argument before 8.4 and is now const in that 94 * argument. This meanst that before 8.4 the actual parameter 95 * required a cast to unconst the value and doesn't require the 96 * cast for 8.4 and beyond. 97 * 98 * This is solved by the macro MC_UNCONSTB84 99 * = MemChan unCONST Before 8.4 100 * 101 * 2. The result of an API function was non-const before 8.4 and is 102 * now const, and is assinged to a non-const string pointer. 103 */ 104 105#if GT84 106#define MC_UNCONSTB84 107#else 108#define MC_UNCONSTB84 (char*) 109#endif /* GT84 */ 110 111#ifndef CONST84 112#define CONST84 113#endif 114 115/* 116 * Pre-8.3 the Tcl_ChannelTypeVersion was not defined. 117 */ 118#if ((TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION < 3)) 119typedef Tcl_DriverBlockModeProc* Tcl_ChannelTypeVersion; 120#endif 121 122#if ! (GT81) 123/* Enable use of procedure internal to tcl. Necessary only 124 * for versions of tcl below 8.1. 125 */ 126 127EXTERN void 128panic _ANSI_ARGS_ (TCL_VARARGS(char*, format)); 129 130#undef Tcl_Panic 131#define Tcl_Panic panic 132#endif 133 134#undef HAVE_LTOA /* Forcing 'sprintf'. HP ltoa function signature may diverge */ 135#ifdef HAVE_LTOA 136#define LTOA(x,str) ltoa (x, str, 10) 137#else 138#define LTOA(x,str) sprintf (str, "%lu", (unsigned long) (x)) 139#endif 140 141 142/* Internal command visible to other parts of the package. 143 */ 144 145extern int 146MemchanCmd _ANSI_ARGS_ ((ClientData notUsed, 147 Tcl_Interp* interp, 148 int objc, Tcl_Obj*CONST objv[])); 149 150extern int 151MemchanFifoCmd _ANSI_ARGS_ ((ClientData notUsed, 152 Tcl_Interp* interp, 153 int objc, Tcl_Obj*CONST objv[])); 154 155extern int 156MemchanFifo2Cmd _ANSI_ARGS_ ((ClientData notUsed, 157 Tcl_Interp* interp, 158 int objc, Tcl_Obj*CONST objv[])); 159 160extern int 161MemchanNullCmd _ANSI_ARGS_ ((ClientData notUsed, 162 Tcl_Interp* interp, 163 int objc, Tcl_Obj*CONST objv[])); 164 165extern int 166MemchanRandomCmd _ANSI_ARGS_ ((ClientData notUsed, 167 Tcl_Interp* interp, 168 int objc, Tcl_Obj*CONST objv[])); 169 170extern int 171MemchanZeroCmd _ANSI_ARGS_ ((ClientData notUsed, 172 Tcl_Interp* interp, 173 int objc, Tcl_Obj*CONST objv[])); 174 175/* Generator procedure for handles. Handles mutex issues for a thread 176 * enabled version of tcl. 177 */ 178 179extern Tcl_Obj* 180MemchanGenHandle _ANSI_ARGS_ ((CONST char* prefix)); 181 182#ifdef __cplusplus 183} 184#endif /* C++ */ 185 186/* 187 * Exported functionality. 188 */ 189 190#include "memchan.h" 191 192#endif /* MEMCHAN_H */ 193