1
/* $Xorg: GetProp.c,v 1.5 2001/02/09 02:03:33 xorgcvs Exp $ */
4
Copyright 1986, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall not be
23
used in advertising or otherwise to promote the sale, use or other dealings
24
in this Software without prior written authorization from The Open Group.
27
/* $XFree86: xc/lib/X11/GetProp.c,v 1.6 2001/12/14 19:54:01 dawes Exp $ */
33
XGetWindowProperty(dpy, w, property, offset, length, delete,
34
req_type, actual_type, actual_format, nitems, bytesafter, prop)
35
register Display *dpy;
40
Atom *actual_type; /* RETURN */
41
int *actual_format; /* RETURN 8, 16, or 32 */
43
unsigned long *nitems; /* RETURN # of 8-, 16-, or 32-bit entities */
44
unsigned long *bytesafter; /* RETURN */
45
unsigned char **prop; /* RETURN */
47
xGetPropertyReply reply;
48
register xGetPropertyReq *req;
52
GetReq (GetProperty, req);
54
req->property = property;
57
req->longOffset = offset;
58
req->longLength = length;
59
error.sequenceNumber = dpy->request;
61
if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) {
64
return (1); /* not Success */
67
*prop = (unsigned char *) NULL;
68
if (reply.propertyType != None) {
69
long nbytes, netbytes;
70
switch (reply.format) {
72
* One extra byte is malloced than is needed to contain the property
73
* data, but this last byte is null terminated and convenient for
74
* returning string properties, so the client doesn't then have to
75
* recopy the string to make it null terminated.
78
nbytes = netbytes = reply.nItems;
80
(*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
81
_XReadPad (dpy, (char *) *prop, netbytes);
85
nbytes = reply.nItems * sizeof (short);
86
netbytes = reply.nItems << 1;
88
(*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
89
_XRead16Pad (dpy, (short *) *prop, netbytes);
93
nbytes = reply.nItems * sizeof (long);
94
netbytes = reply.nItems << 2;
96
(*prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1)))
97
_XRead32 (dpy, (long *) *prop, netbytes);
102
* This part of the code should never be reached. If it is,
103
* the server sent back a property with an invalid format.
104
* This is a BadImplementation error.
107
/* sequence number stored above */
108
error.type = X_Error;
109
error.majorCode = X_GetProperty;
111
error.errorCode = BadImplementation;
112
_XError(dpy, &error);
114
nbytes = netbytes = 0L;
118
_XEatData(dpy, (unsigned long) netbytes);
121
return(BadAlloc); /* not Success */
123
(*prop)[nbytes] = '\0';
125
*actual_type = reply.propertyType;
126
*actual_format = reply.format;
127
*nitems = reply.nItems;
128
*bytesafter = reply.bytesAfter;