/*
* cslibint.c -- low level I/O
*
* (c) Copyright 1993-1994 Adobe Systems Incorporated.
* All rights reserved.
*
* Permission to use, copy, modify, distribute, and sublicense this software
* and its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notices appear in all copies and that
* both those copyright notices and this permission notice appear in
* supporting documentation and that the name of Adobe Systems Incorporated
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. No trademark license
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
* "Display PostScript"(tm) is used to describe this software, its
* functionality or for any other purpose, such use shall be limited to a
* statement that this software works in conjunction with the Display
* PostScript system. Proper trademark attribution to reflect Adobe's
* ownership of the trademark shall be given whenever any such reference to
* the Display PostScript system is made.
*
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
*
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
* Incorporated which may be registered in certain jurisdictions
*
* Portions Copyright 1985, 1986, 1987 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* Author: Adobe Systems Incorporated and MIT X Consortium
*/
/* $XFree86: xc/lib/dps/cslibint.c,v 1.4tsi Exp $ */
/*
* XlibInternal.c - Internal support routines for the C subroutine
* interface library (Xlib) to the X Window System Protocol V11.0.
*/
#define NEED_EVENTS
#define NEED_REPLIES
#include "Xlibnet.h"
#include <stdio.h>
#include "dpsassert.h"
#include "cslibint.h"
/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
* systems are broken and return EWOULDBLOCK when they should return EAGAIN
*/
#if defined(EAGAIN) && defined(EWOULDBLOCK)
#else
#ifdef EAGAIN
#else
#endif
#endif
#ifdef LACHMAN
#ifdef EMSGSIZE
#endif
#endif
#endif
/*
* The following routines are internal routines used by Xlib for protocol
* packet transmission and reception.
*
* XIOError(Display *) will be called if any sort of system call error occurs.
* This is assumed to be a fatal condition, i.e., XIOError should not return.
*
* XError(Display *, XErrorEvent *) will be called whenever an X_Error event is
* received. This is not assumed to be a fatal condition, i.e., it is
* acceptable for this procedure to return. However, XError should NOT
* perform any operations (directly or indirectly) on the DISPLAY.
*
* Routines declared with a return type of 'Status' return 0 on failure,
* and non 0 on success. Routines with no declared return type don't
* return anything. Whenever possible routines that create objects return
* the object they have created.
*/
/* lookup table for adding padding bytes to data that is read from
or written to the X socket. */
0, 0, 0
};
/*
* N_XFlush - Flush the X request buffer. If the buffer is empty, no
* action is taken. This routine correctly handles incremental writes.
* This routine may have to be reworked if int < long.
*/
{
register int write_stat;
register char *bufindex;
if (!dpy) return;
/*
* While write has not written the entire buffer, keep looping
* until the entire buffer is written. bufindex will be incremented
* and size decremented as buffer is written out.
*/
while (size) {
errno = 0;
if (write_stat >= 0) {
size -= write_stat;
bufindex += write_stat;
#ifdef SUNSYSV
} else if (errno == 0) {
#endif
#ifdef EMSGSIZE
if (todo > 1)
todo >>= 1;
else
#endif
/* Write failed! */
/* errno set by write system call. */
}
}
}
#ifdef NEEDFORNX
int
{
register int len;
int pend;
if (mode == QueuedAfterFlush)
{
}
#ifdef XCONN_CHECK_FREQ
/* This is a crock, required because FIONREAD or equivalent is
* not guaranteed to detect a broken connection.
*/
{
dpy->conn_checker = 0;
&zero_time))
{
if (pend > 0)
{
/* we should not get zero, if we do, force a read */
if (!pend)
}
}
}
#endif /* XCONN_CHECK_FREQ */
/* Force a read if there is not enough data. Otherwise,
* a select() loop at a higher-level will spin undesirably,
* and we've seen at least one OS that appears to not update
* the result from FIONREAD once it has returned nonzero.
*/
#ifdef XCONN_CHECK_FREQ
dpy->conn_checker = 0;
#endif
/* no space between comma and type or else macro will die */
else /* must be an event packet */
}
}
/* _XReadEvents - Flush the output queue,
* then read as many events as possible (but at least 1) and enqueue them
*/
{
register long pend;
do {
/* find out how much data can be read */
/* must read at least one xEvent; if none is pending, then
we'll just flush and block waiting for it */
/* don't flush until we block the first time */
if (not_yet_flushed) {
}
}
/* but we won't read more than the max buffer size */
/* round down to an integral number of XReps */
/* no space between comma and type or else macro will die */
else /* it's an event packet; enqueue it */
}
}
#endif /* NEEDFORNX */
/*
* N_XRead - Read bytes from the socket taking into account incomplete
* reads. This routine may have to be reworked if int < long.
*/
{
register long bytes_read;
if (!dpy) return 0;
errno = 0;
!= size) {
if (bytes_read > 0) {
size -= bytes_read;
data += bytes_read;
}
errno = 0;
}
#ifdef SUNSYSV
else if (errno == 0) {
}
#endif
else if (bytes_read == 0) {
/* Read failed because of end of file! */
}
else /* bytes_read is less than 0; presumably -1 */ {
/* If it's a system call interrupt, it's not an error. */
}
}
return 0;
}
#ifdef WORD64
/*
* XXX This is a *really* stupid way of doing this....
* PACKBUFFERSIZE must be a multiple of 4.
*/
/*
* _XRead32 - Read bytes from the socket unpacking each 32 bits
* into a long (64 bits on a CRAY computer).
*
*/
{
lpack = (long *) packbuffer;
bits = 32;
for(i=0;i<nwords;i++){
if(bits){
lpack++;
}
}
}
{
}
}
/*
* _XRead16 - Read bytes from the socket unpacking each 16 bits
* into a long (64 bits on a CRAY computer).
*
*/
{
lpack = (long *) packbuffer;
bits = 48;
for(i=0;i<nwords;i++){
bits -= 16;
if(bits < 0){
lpack++;
bits = 48;
}
}
}
{
}
}
{
if (slop > 0) {
}
}
#endif /* WORD64 */
/*
* N_XReadPad - Read bytes from the socket taking into account incomplete
* reads. If the number of bytes is not 0 mod 32, read additional pad
* bytes. This routine may have to be reworked if int < long.
*/
{
register long bytes_read;
if (!dpy) return;
/*
* The following hack is used to provide 32 bit long-word
* aligned padding. The [1] vector is of length 0, 1, 2, or 3,
* whatever is needed.
*/
errno = 0;
if (bytes_read > 0) {
size -= bytes_read;
}
else {
}
}
errno = 0;
}
#ifdef SUNSYSV
else if (errno == 0) {
}
#endif
else if (bytes_read == 0) {
/* Read failed because of end of file! */
}
else /* bytes_read is less than 0; presumably -1 */ {
/* If it's a system call interrupt, it's not an error. */
}
}
}
/*
* N_XSend - Flush the buffer and send the client data. 32 bit word aligned
* transmission is used, if size is not 0 mod 4, extra bytes are transmitted.
* This routine may have to be reworked if int < long;
*/
{
/* XText8 and XText16 require that the padding bytes be zero! */
long skip = 0;
/*
* There are 3 pieces that may need to be written out:
*
* o whatever is in the display buffer
* o the data passed in by the user
* o any padding needed to 32bit align the whole mess
*
* This loop looks at all 3 pieces each time through. It uses skip
* to figure out whether or not a given piece is needed.
*/
while (total) {
int i = 0;
long len;
/* You could be very general here and have "in" and "out" iovecs
* and write a loop without using a macro, but what the heck. This
* translates to:
*
* how much of this piece is new?
* if more new then we are trying this time, clamp
* if nothing new
* then bump down amount already written, for next piece
* else put new stuff in iovec, will need all of next piece
*
* Note that todo had better be at least 1 or else we'll end up
* writing 0 iovecs.
*/
if (len <= 0) { \
} else { \
i++; \
before = 0; \
}
errno = 0;
#ifdef SUNSYSV
} else if (errno == 0) {
#endif
#ifdef EMSGSIZE
if (todo > 1)
todo >>= 1;
else
#endif
}
}
return;
}
#ifdef NEEDFORNX
/*
* _XAllocID - normal resource ID allocation routine. A client
* can roll his own and instatantiate it if he wants, but must
* follow the rules.
*/
{
dpy->resource_id++;
}
if (id != 0x10000000) {
"Xlib: resource ID allocation space exhausted!\n");
id = 0x10000000;
}
return id;
}
/*
* The hard part about this is that we only get 16 bits from a reply. Well,
* then, we have three values that will march along, with the following
* invariant:
* dpy->last_request_read <= rep->sequenceNumber <= dpy->request
* The right choice for rep->sequenceNumber is the largest that
* still meets these constraints.
*/
unsigned long
{
/*
* KeymapNotify has no sequence number, but is always guaranteed
* to immediately follow another event, except when generated via
* SendEvent (hmmm).
*/
return(dpy->last_request_read);
newseq += 0x10000;
"Xlib: sequence lost (0x%lx > 0x%lx) in reply type 0x%x!\n",
newseq -= 0x10000;
break;
}
}
return(newseq);
}
#endif /* NEEDFORNX */
/*
* N_XReply - Wait for a reply packet and copy its contents into the
* specified rep. Mean while we must handle error and event packets that
* we may encounter.
*/
int extra, /* number of 32-bit words expected after the reply */
{
/* Pull out the serial number now, so that (currently illegal) requests
* generated by an error handler don't confuse us.
*/
while (1) {
case X_Reply:
/* Reply received. Fast update for synchronous replies,
* but deal with multiple outstanding replies.
*/
else
if (extra == 0) {
/* unexpectedly long reply! */
return (1);
}
/*
* Read the extra data into storage immediately following
* the GenericReply structure.
*/
((long)extra) << 2);
return (1);
}
/* Actual reply is longer than "extra" */
((long)extra) << 2);
if (discard)
return (1);
}
/*
*if we get here, then extra > rep->generic.length--meaning we
* read a reply that's shorter than we expected. This is an
* error, but we still need to figure out how to handle it...
*/
return (0);
case X_Error:
{
int ret_code;
unsigned long serial;
/*
* we better see if there is an extension who may
* want to suppress the error.
*/
}
if (!ret) {
ret_code = 0;
}
if (serial == cur_request)
return(ret_code);
}
break;
default:
/* There should never be any events on this connection! */
break;
}
}
}
/* Read and discard "n" 8-bit bytes of data */
static void
{
while (n > 0) {
n -= bytes_read;
}
}
/* Read and discard "n" 32-bit words. */
{
}
#ifdef NEEDFORNX
/*
* _XEnq - Place event packets on the display's queue.
* note that no squishing of move events in V11, since there
* is pointer motion hints....
*/
{
/*NOSTRICT*/
/* If _qfree is non-NULL do this, else malloc a new one. */
}
else if ((qelt =
/* Malloc call failed! */
}
/* go call through display to find proper event reformatter */
} else {
/* ignored, or stashed away for many-to-one compression */
}
}
/*
* EventToWire in separate file in that often not needed.
*/
#endif /* NEEDFORNX */
/*ARGSUSED*/
{
return(False);
}
/*ARGSUSED*/
{
return(0);
}
#ifdef NEEDFORNX
/*
* reformat a wire event into an XEvent structure of the right type.
*/
{
(xGenericReply *)event);
/* Ignore the leading bit of the event type since it is set when a
client sends an event rather than the server. */
case KeyPress:
case KeyRelease:
{
}
break;
case ButtonPress:
case ButtonRelease:
{
}
break;
case MotionNotify:
{
}
break;
case EnterNotify:
case LeaveNotify:
{
ELFlagSameScreen) && True;
ELFlagFocus) && True;
}
break;
case FocusIn:
case FocusOut:
{
}
break;
case KeymapNotify:
{
}
break;
case Expose:
{
}
break;
case GraphicsExpose:
{
(XGraphicsExposeEvent *) re;
}
break;
case NoExpose:
{
}
break;
case VisibilityNotify:
{
}
break;
case CreateNotify:
{
(XCreateWindowEvent *) re;
}
break;
case DestroyNotify:
{
(XDestroyWindowEvent *) re;
}
break;
case UnmapNotify:
{
}
break;
case MapNotify:
{
}
break;
case MapRequest:
{
}
break;
case ReparentNotify:
{
}
break;
case ConfigureNotify:
{
}
break;
case ConfigureRequest:
{
(XConfigureRequestEvent *) re;
}
break;
case GravityNotify:
{
}
break;
case ResizeRequest:
{
(XResizeRequestEvent *) re;
}
break;
case CirculateNotify:
{
}
break;
case CirculateRequest:
{
(XCirculateRequestEvent *) re;
}
break;
case PropertyNotify:
{
}
break;
case SelectionClear:
{
(XSelectionClearEvent *) re;
}
break;
case SelectionRequest:
{
(XSelectionRequestEvent *) re;
}
break;
case SelectionNotify:
{
}
break;
case ColormapNotify:
{
}
break;
case ClientMessage:
{
register int i;
= (XClientMessageEvent *) re;
case 8:
for (i = 0; i < 20; i++)
break;
case 16:
break;
case 32:
break;
default: /* XXX should never occur */
break;
}
}
break;
case MappingNotify:
{
}
break;
default:
}
return(True);
}
#ifndef USL_SHARELIB
static char *_SysErrorMsg (int n)
{
extern char *sys_errlist[];
extern int sys_nerr;
return (s ? s : "no such error");
}
#endif /* USL sharedlibs in don't define for SVR3.2 */
/*
* _XDefaultIOError - Default fatal system error reporting routine. Called
* when an X internal system error is encountered.
*/
{
"XIO: fatal IO error %d (%s) on X server \"%s\"\r\n",
" after %lu requests (%lu known processed) with %d events remaining.\r\n",
" The connection was probably broken by a server shutdown or KillClient.\r\n");
}
exit(1);
}
{
} else {
;
if (ext)
else
buffer[0] = '\0';
}
if (ext) {
}
}
/* kludge, try to find the extension that caused it */
buffer[0] = '\0';
if (ext->error_string)
if (buffer[0]) {
break;
}
}
if (bext)
else
if (mesg[0]) {
}
/* let extensions try to print the values */
if (ext->error_values)
}
else
}
return 1;
}
{
exit(1);
/*NOTREACHED*/
}
/*ARGSUSED*/
{
return True;
}
/*
* _XError - prepare to upcall user protocol error handler
*/
{
/*
* X_Error packet encountered! We need to unpack the error before
* giving it to the user.
*/
return 0;
if (_XErrorFunction != NULL) {
} else {
}
}
/*
* _XIOError - call user connection error handler and exit
*/
{
if (_XIOErrorFunction != NULL)
(*_XIOErrorFunction)(dpy);
else
exit (1);
}
/*
* This routine can be used to (cheaply) get some memory within a single
* Xlib routine for scratch space. It is reallocated from the same place
* each time, unless the library needs a large scratch space.
*/
{
else dpy->scratch_length = 0;
}
return (dpy->scratch_buffer);
}
/*
* Given a visual id, find the visual structure for this id on this display.
*/
{
register int i, j, k;
/* if nvisuals == 0 then visuals will be NULL */
}
}
}
return (NULL);
}
{
}
#ifdef _XNEEDBCOPYFUNC
{
while (length--)
} else {
while (length--)
}
}
#endif
#endif /* NEEDFORNX */
{
} else {
}
}
#ifdef WORD64
/*
* XXX This is a *really* stupid way of doing this. It should just use
* dpy->bufptr directly, taking into account where in the word it is.
*/
/*
* Data16 - Place 16 bit data in the buffer.
*
* "dpy" is a pointer to a Display.
* "data" is a pointer to the data.
* "len" is the length in bytes of the data.
*/
static void
{
lpack = (long *)packbuffer;
/* nwords is the number of 16 bit values to be packed,
* the low order 16 bits of each word will be packed
* into 64 bit words
*/
bits = 48;
for(i=0;i<nwords;i++){
bits -= 16 ;
lp++;
if(bits < 0){
lpack++;
bits = 48;
}
}
}
void
{
}
}
/*
* Data32 - Place 32 bit data in the buffer.
*
* "dpy" is a pointer to a Display.
* "data" is a pointer to the data.
* "len" is the length in bytes of the data.
*/
{
lpack = (long *) packbuffer;
/* nwords is the number of 32 bit values to be packed
* the low order 32 bits of each word will be packed
* into 64 bit words
*/
bits = 32;
for(i=0;i<nwords;i++){
lp++;
if(bits)
lpack++;
}
}
{
}
}
#endif /* WORD64 */
#ifdef NEEDFORNX
/*
* _XFreeQ - free the queue of events, called by XCloseDisplay
*/
void _XFreeQ (void)
{
while (qelt) {
}
return;
}
#endif /* NEEDFORNX */
/* Make sure this produces the same string as DefineLocal/DefineSelf in xdm.
* Otherwise, Xau will not be able to find your cookies in the Xauthority file.
*
* Note: POSIX says that the ``nodename'' member of utsname does _not_ have
* to have sufficient information for interfacing to the network,
* and so, you may be better off using gethostname (if it exists).
*/
#define NEED_UTSNAME
#endif
/*
* N_XGetHostname - similar to gethostname but allows special processing.
*/
{
int len;
#ifdef NEED_UTSNAME
#else
buf[0] = '\0';
#endif /* NEED_UTSNAME */
return len;
}
#ifdef NEEDFORNX
/*
* _XScreenOfWindow - get the Screen of a given window
*/
{
register int i;
int x, y; /* dummy variables */
return None;
}
return ScreenOfDisplay (dpy, i);
}
}
return NULL;
}
#endif /* NEEDFORNX */
#if (MSKCNT > 4)
/*
* This is a macro if MSKCNT <= 4
*/
int
{
int i;
for (i=0; i<MSKCNT; i++)
if (src[ i ])
return (1);
return (0);
}
#endif
#ifdef NEEDFORNX
#ifdef CRAY
/*
* Cray UniCOS does not have readv and writev so we emulate
*/
{
hdr.msg_accrights = 0;
hdr.msg_accrightslen = 0;
hdr.msg_namelen = 0;
}
{
hdr.msg_accrights = 0;
hdr.msg_accrightslen = 0;
hdr.msg_namelen = 0;
}
#endif /* CRAY */
/*
* SYSV/386 does not have readv so we emulate
*/
{
char *base;
errno = 0;
while (len > 0) {
register int nbytes;
errno = 0;
}
}
return total;
}
#endif /* SYSV && i386 && !STREAMSCONN */
#ifdef STREAMSCONN
/*
* Copyright 1988, 1989 AT&T, Inc.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of AT&T not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission. AT&T makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* AT&T DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL AT&T
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/*
iovec.c (C source file)
Acc: 575557389 Mon Mar 28 08:03:09 1988
Mod: 575557397 Mon Mar 28 08:03:17 1988
Sta: 575557397 Mon Mar 28 08:03:17 1988
Owner: 2011
Group: 1985
Permissions: 664
*/
/*
START USER STAMP AREA
*/
/*
END USER STAMP AREA
*/
extern char _XsTypeofStream[];
int
{
char * p;
if (n <= 0 || n > 16)
{
return (-1);
}
for (i = 0; i < n; ++i)
{
{
return (-1);
}
}
{
return (-1);
}
BUFFERING))> 0)
{
for (i = 0, p = buf; i < n; ++i)
{
p += len;
}
}
if (size > MAX_WORKAREA)
return (rc);
}
int
{
char * p;
if (n <= 0 || n > 16)
{
return (-1);
}
for (i = 0; i < n; ++i)
{
{
return (-1);
}
}
{
return (-1);
}
for (i = 0, p = buf; i < n; ++i)
{
p += len;
}
if (size > MAX_WORKAREA)
return (rc);
}
#endif /* STREAMSCONN */
#endif /* NEEDFORNX */