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