|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XGetProp.c,v 11.10 87/09/11 08:04:23 toddb Exp $ */
4: /* Copyright Massachusetts Institute of Technology 1986 */
5:
6: #define NEED_REPLIES
7: #include "Xlibint.h"
8:
9: int
10: XGetWindowProperty(dpy, w, property, offset, length, delete,
11: req_type, actual_type, actual_format, nitems, bytesafter, prop)
12: register Display *dpy;
13: Window w;
14: Atom property;
15: Bool delete;
16: Atom req_type;
17: Atom *actual_type;
18: int *actual_format; /* 8, 16, or 32 */
19: long offset, length;
20: unsigned long *nitems; /* # of 8-, 16-, or 32-bit entities */
21: long *bytesafter;
22: unsigned char **prop;
23: {
24: int errorstatus;
25: xGetPropertyReply reply;
26: register xGetPropertyReq *req;
27: LockDisplay(dpy);
28: GetReq (GetProperty, req);
29: req->window = w;
30: req->property = property;
31: req->type = req_type;
32: req->delete = delete;
33: req->longOffset = offset;
34: req->longLength = length;
35:
36: if (!(errorstatus = _XReply (dpy, (xReply *) &reply, 0, xFalse))) {
37: UnlockDisplay(dpy);
38: return (errorstatus);
39: }
40: *actual_type = reply.propertyType;
41: *actual_format = reply.format;
42: *nitems = reply.nItems;
43: *bytesafter = reply.bytesAfter;
44:
45: *prop = NULL;
46: if (*nitems) switch (reply.format) {
47: long nbytes;
48: /*
49: * One extra byte is malloced than is needed to contain the property
50: * data, but this last byte is null terminated and convenient for
51: * returing string properties, so the client doesn't then have to
52: * recopy the string to make it null terminated.
53: */
54: case 8:
55: *prop = (unsigned char *) Xmalloc ((unsigned)reply.nItems + (unsigned)1);
56: _XReadPad (dpy, (char *) *prop, (long) reply.nItems);
57: (*prop)[reply.nItems] = '\0';
58: break;
59:
60: case 16:
61: /* XXX needs rethinking for BIGSHORTS */
62: nbytes = (long)reply.nItems << 1;
63: *prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1);
64: _XReadPad (dpy, (char *) *prop, nbytes);
65: (*prop)[nbytes] = '\0';
66: break;
67:
68: case 32:
69: nbytes = (long)reply.nItems << 2;
70: *prop = (unsigned char *) Xmalloc ((unsigned)nbytes + 1);
71: _XRead (dpy, (char *) *prop, (long)nbytes);
72: (*prop)[nbytes] = '\0';
73: break;
74:
75: default:
76: /*
77: * This part of the code should never be reached. If it is, the server
78: * send back a property with an invalid format. This is a
79: * BadImplementation error.
80: */
81:
82: {
83: xError error;
84:
85: error.sequenceNumber = dpy->request;
86: error.type = X_Error;
87: error.majorCode = X_GetProperty;
88: error.minorCode = 0;
89: error.errorCode = BadImplementation;
90:
91: _XError(dpy, &error);
92: }
93: break;
94: }
95: UnlockDisplay(dpy);
96: SyncHandle();
97: return(Success);
98:
99: }
100:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.