StBytes.c revision 1ab64890
1/* $Xorg: StBytes.c,v 1.4 2001/02/09 02:03:36 xorgcvs Exp $ */
2/*
3
4Copyright 1986, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25
26*/
27/* $XFree86: xc/lib/X11/StBytes.c,v 1.4 2001/12/14 19:54:07 dawes Exp $ */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include <X11/Xlibint.h>
33#include <X11/Xatom.h>
34
35/* insulate predefined atom numbers from cut routines */
36static const Atom n_to_atom[8] = {
37	XA_CUT_BUFFER0,
38	XA_CUT_BUFFER1,
39	XA_CUT_BUFFER2,
40	XA_CUT_BUFFER3,
41	XA_CUT_BUFFER4,
42	XA_CUT_BUFFER5,
43	XA_CUT_BUFFER6,
44	XA_CUT_BUFFER7};
45
46int
47XRotateBuffers (
48    register Display *dpy,
49    int rotate)
50{
51    /* XRotateWindowProperties wants a non-const Atom*, but it doesn't
52     * modify it, so this is safe.
53     */
54    return XRotateWindowProperties(dpy, RootWindow(dpy, 0), n_to_atom, 8, rotate);
55}
56
57char *XFetchBuffer (
58    register Display *dpy,
59    int *nbytes,
60    register int buffer)
61{
62    Atom actual_type;
63    int actual_format;
64    unsigned long nitems;
65    unsigned long leftover;
66    unsigned char *data;
67    *nbytes = 0;
68    if ((buffer < 0) || (buffer > 7)) return (NULL);
69/* XXX should be (sizeof (maxint) - 1)/4 */
70    if (XGetWindowProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer],
71	0L, 10000000L, False, XA_STRING,
72	&actual_type, &actual_format, &nitems, &leftover, &data) != Success) {
73	return (NULL);
74	}
75    if ( (actual_type == XA_STRING) &&  (actual_format != 32) ) {
76	*nbytes = nitems;
77	return((char *)data);
78	}
79    if ((char *) data != NULL) Xfree ((char *)data);
80    return(NULL);
81}
82
83char *XFetchBytes (
84    register Display *dpy,
85    int *nbytes)
86{
87    return (XFetchBuffer (dpy, nbytes, 0));
88}
89
90int
91XStoreBuffer (
92    register Display *dpy,
93    _Xconst char *bytes,
94    int nbytes,
95    register int buffer)
96{
97    if ((buffer < 0) || (buffer > 7)) return 0;
98    return XChangeProperty(dpy, RootWindow(dpy, 0), n_to_atom[buffer],
99	XA_STRING, 8, PropModeReplace, (unsigned char *) bytes, nbytes);
100}
101
102int
103XStoreBytes (
104    register Display *dpy,
105    _Xconst char *bytes,
106    int nbytes)
107{
108    return XStoreBuffer (dpy, bytes, nbytes, 0);
109}
110