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