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

  1. /*
  2.  * Xau - X Authorization Database Library
  3.  *
  4.  * $XConsortium: AuFileName.c,v 1.2 91/01/08 15:09:00 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. char *
  24. XauFileName ()
  25. {
  26.     char    *name, *malloc (), *getenv ();
  27.     char    *strcat (), *strcpy ();
  28.     static char    *buf;
  29.     static int    bsize;
  30.     int        size;
  31.  
  32.     if (name = getenv ("XAUTHORITY")) {
  33.     return name;
  34.     } else if (name = getenv ("HOME")) {
  35.     size = strlen (name) + strlen(".Xauthority") + 2;
  36.     if (size > bsize) {
  37.         if (buf)
  38.         free (buf);
  39.         buf = malloc ((unsigned) size);
  40.         if (!buf)
  41.         return 0;
  42.         bsize = size;
  43.     }
  44.     strcpy (buf, name);
  45.     strcat (buf, "/.Xauthority" + (name[1] == '\0' ? 1 : 0));
  46.     return buf;
  47.     }
  48.     return 0;
  49. }
  50.