DisName.c revision 61b2299d
1/* $Xorg: DisName.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */
2
3/*
4
5Copyright 1994, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included
14in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the name of The Open Group shall
25not be used in advertising or otherwise to promote the sale, use or
26other dealings in this Software without prior written authorization
27from The Open Group.
28
29*/
30/* $XFree86$ */
31
32/* XDisplayName.c */
33/*
34 * Returns the name of the display XOpenDisplay would use.  This is better
35 * than just printing the "display" variable in a program because that
36 * could be NULL and/or there could be an environment variable set.
37 * This makes it easier for programmers to provide meaningful error
38 * messages.
39 *
40 *
41 * For example, this is used in XOpenDisplay() as
42 *	strncpy( displaybuf, XDisplayName( display ), sizeof(displaybuf) );
43 *      if ( *displaybuf == '\0' ) return( NULL );
44 *  This check is actually unnecessary because the next thing is an index()
45 *  call looking for a ':' which will fail and we'll return(NULL).
46 */
47/* Written at Waterloo - JMSellens */
48
49#ifdef HAVE_CONFIG_H
50#include <config.h>
51#endif
52#include <stdio.h>
53#include <stdlib.h>
54#include "Xlib.h"
55
56char *
57XDisplayName(
58    _Xconst char *display)
59{
60    char *d;
61    if ( display != (char *)NULL && *display != '\0' )
62	return( (char *)display );
63    if ( (d = getenv( "DISPLAY" )) != (char *)NULL )
64	return( d );
65    return( "" );
66}
67