home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xau / AuWrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-30  |  1.9 KB  |  69 lines

  1. /*
  2.  * Xau - X Authorization Database Library
  3.  *
  4.  * $XConsortium: AuWrite.c,v 1.5 91/01/30 12:28:19 gildea Exp $
  5.  *
  6.  * Copyright 1988 Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of M.I.T. not be used in advertising or
  13.  * publicity pertaining to distribution of the software without specific,
  14.  * written prior permission.  M.I.T. makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * Author:  Keith Packard, MIT X Consortium
  19.  */
  20.  
  21. #include <X11/Xauth.h>
  22.  
  23. static
  24. write_short (s, file)
  25. unsigned short    s;
  26. FILE        *file;
  27. {
  28.     unsigned char   file_short[2];
  29.  
  30.     file_short[0] = (s & (unsigned)0xff00) >> 8;
  31.     file_short[1] = s & 0xff;
  32.     if (fwrite ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
  33.     return 0;
  34.     return 1;
  35. }
  36.  
  37. static
  38. write_counted_string (count, string, file)
  39. unsigned short    count;
  40. char    *string;
  41. FILE    *file;
  42. {
  43.     if (write_short (count, file) == 0)
  44.     return 0;
  45.     if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
  46.     return 0;
  47.     return 1;
  48. }
  49.  
  50. int
  51. XauWriteAuth (auth_file, auth)
  52. FILE    *auth_file;
  53. Xauth    *auth;
  54. {
  55.     char    *malloc ();
  56.  
  57.     if (write_short (auth->family, auth_file) == 0)
  58.     return 0;
  59.     if (write_counted_string (auth->address_length, auth->address, auth_file) == 0)
  60.     return 0;
  61.     if (write_counted_string (auth->number_length, auth->number, auth_file) == 0)
  62.     return 0;
  63.     if (write_counted_string (auth->name_length, auth->name, auth_file) == 0)
  64.     return 0;
  65.     if (write_counted_string (auth->data_length, auth->data, auth_file) == 0)
  66.     return 0;
  67.     return 1;
  68. }
  69.