| 1 | /* $XConsortium: AuWrite.c,v 1.6 94/04/17 20:15:45 gildea Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 |
|
|---|
| 5 | Copyright (c) 1988 X Consortium
|
|---|
| 6 |
|
|---|
| 7 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
|---|
| 8 | of this software and associated documentation files (the "Software"), to deal
|
|---|
| 9 | in the Software without restriction, including without limitation the rights
|
|---|
| 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|---|
| 11 | copies of the Software, and to permit persons to whom the Software is
|
|---|
| 12 | furnished to do so, subject to the following conditions:
|
|---|
| 13 |
|
|---|
| 14 | The above copyright notice and this permission notice shall be included in
|
|---|
| 15 | all copies or substantial portions of the Software.
|
|---|
| 16 |
|
|---|
| 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|---|
| 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|---|
| 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|---|
| 20 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|---|
| 21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|---|
| 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|---|
| 23 |
|
|---|
| 24 | Except as contained in this notice, the name of the X Consortium shall not be
|
|---|
| 25 | used in advertising or otherwise to promote the sale, use or other dealings
|
|---|
| 26 | in this Software without prior written authorization from the X Consortium.
|
|---|
| 27 |
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_CONFIG_H
|
|---|
| 31 | #include <config.h>
|
|---|
| 32 | RCSID("$Id$");
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | #include <X11/Xauth.h>
|
|---|
| 36 |
|
|---|
| 37 | static int
|
|---|
| 38 | write_short (unsigned short s, FILE *file)
|
|---|
| 39 | {
|
|---|
| 40 | unsigned char file_short[2];
|
|---|
| 41 |
|
|---|
| 42 | file_short[0] = (s & (unsigned)0xff00) >> 8;
|
|---|
| 43 | file_short[1] = s & 0xff;
|
|---|
| 44 | if (fwrite (file_short, sizeof (file_short), 1, file) != 1)
|
|---|
| 45 | return 0;
|
|---|
| 46 | return 1;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | static int
|
|---|
| 50 | write_counted_string (unsigned short count, char *string, FILE *file)
|
|---|
| 51 | {
|
|---|
| 52 | if (write_short (count, file) == 0)
|
|---|
| 53 | return 0;
|
|---|
| 54 | if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
|
|---|
| 55 | return 0;
|
|---|
| 56 | return 1;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | int
|
|---|
| 60 | XauWriteAuth (FILE *auth_file, Xauth *auth)
|
|---|
| 61 | {
|
|---|
| 62 | if (write_short (auth->family, auth_file) == 0)
|
|---|
| 63 | return 0;
|
|---|
| 64 | if (write_counted_string (auth->address_length, auth->address, auth_file) == 0)
|
|---|
| 65 | return 0;
|
|---|
| 66 | if (write_counted_string (auth->number_length, auth->number, auth_file) == 0)
|
|---|
| 67 | return 0;
|
|---|
| 68 | if (write_counted_string (auth->name_length, auth->name, auth_file) == 0)
|
|---|
| 69 | return 0;
|
|---|
| 70 | if (write_counted_string (auth->data_length, auth->data, auth_file) == 0)
|
|---|
| 71 | return 0;
|
|---|
| 72 | return 1;
|
|---|
| 73 | }
|
|---|