AuWrite.c revision 313a12fd
127702724Smrg/* 227702724Smrg 327702724SmrgCopyright 1988, 1998 The Open Group 427702724Smrg 527702724SmrgPermission to use, copy, modify, distribute, and sell this software and its 627702724Smrgdocumentation for any purpose is hereby granted without fee, provided that 727702724Smrgthe above copyright notice appear in all copies and that both that 827702724Smrgcopyright notice and this permission notice appear in supporting 927702724Smrgdocumentation. 1027702724Smrg 1127702724SmrgThe above copyright notice and this permission notice shall be included in 1227702724Smrgall copies or substantial portions of the Software. 1327702724Smrg 1427702724SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1527702724SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1627702724SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1727702724SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1827702724SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1927702724SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2027702724Smrg 2127702724SmrgExcept as contained in this notice, the name of The Open Group shall not be 2227702724Smrgused in advertising or otherwise to promote the sale, use or other dealings 2327702724Smrgin this Software without prior written authorization from The Open Group. 2427702724Smrg 2527702724Smrg*/ 2627702724Smrg 2727702724Smrg#ifdef HAVE_CONFIG_H 2827702724Smrg#include <config.h> 2927702724Smrg#endif 3027702724Smrg#include <X11/Xauth.h> 3127702724Smrg 3227702724Smrgstatic int 3327702724Smrgwrite_short (unsigned short s, FILE *file) 3427702724Smrg{ 3527702724Smrg unsigned char file_short[2]; 3627702724Smrg 3727702724Smrg file_short[0] = (s & (unsigned)0xff00) >> 8; 3827702724Smrg file_short[1] = s & 0xff; 39313a12fdSmrg if (fwrite ((char *) file_short, sizeof (file_short), 1, file) != 1) 4027702724Smrg return 0; 4127702724Smrg return 1; 4227702724Smrg} 4327702724Smrg 4427702724Smrgstatic int 4527702724Smrgwrite_counted_string (unsigned short count, char *string, FILE *file) 4627702724Smrg{ 4727702724Smrg if (write_short (count, file) == 0) 4827702724Smrg return 0; 49313a12fdSmrg if (fwrite (string, sizeof (char), count, file) != count) 5027702724Smrg return 0; 5127702724Smrg return 1; 5227702724Smrg} 5327702724Smrg 5427702724Smrgint 5527702724SmrgXauWriteAuth (FILE *auth_file, Xauth *auth) 5627702724Smrg{ 5727702724Smrg if (write_short (auth->family, auth_file) == 0) 5827702724Smrg return 0; 5927702724Smrg if (write_counted_string (auth->address_length, auth->address, auth_file) == 0) 6027702724Smrg return 0; 6127702724Smrg if (write_counted_string (auth->number_length, auth->number, auth_file) == 0) 6227702724Smrg return 0; 6327702724Smrg if (write_counted_string (auth->name_length, auth->name, auth_file) == 0) 6427702724Smrg return 0; 6527702724Smrg if (write_counted_string (auth->data_length, auth->data, auth_file) == 0) 6627702724Smrg return 0; 6727702724Smrg return 1; 6827702724Smrg} 69