]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xau/AuFileName.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xau / AuFileName.c
1 /* $XConsortium: AuFileName.c /main/8 1996/09/28 16:43:20 rws $ */
2 /* $XFree86: xc/lib/Xau/AuFileName.c,v 3.2 1996/12/24 08:46:53 dawes Exp $ */
3
4 /*
5
6 Copyright (c) 1988  X Consortium
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
28
29 */
30
31 #include <X11/Xauth.h>
32 #include <X11/Xos.h>
33
34 #ifdef X_NOT_STDC_ENV
35 char *malloc (), *getenv ();
36 #else
37 #include <stdlib.h>
38 #endif
39
40 char *
41 XauFileName ()
42 {
43     char *slashDotXauthority = "/.Xauthority";
44     char    *name;
45     static char *buf;
46     static int  bsize;
47 #ifdef WIN32
48     char    dir[128];
49 #endif
50     int     size;
51
52     if (name = getenv ("XAUTHORITY"))
53         return name;
54     name = getenv ("HOME");
55     if (!name) {
56 #ifdef WIN32
57         (void) strcpy (dir, "/users/");
58         if (name = getenv("USERNAME")) {
59             (void) strcat (dir, name);
60             name = dir;
61         }
62         if (!name)
63 #endif
64         return 0;
65     }
66     size = strlen (name) + strlen(&slashDotXauthority[1]) + 2;
67     if (size > bsize) {
68         if (buf)
69             free (buf);
70         buf = malloc ((unsigned) size);
71         if (!buf)
72             return 0;
73         bsize = size;
74     }
75     strcpy (buf, name);
76     strcat (buf, slashDotXauthority + (name[1] == '\0' ? 1 : 0));
77     return buf;
78 }