1
/*********************************************************
2
* Copyright (C) 2010 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
22
* vmware-xdg-* script wrapper library.
25
#include <sys/types.h>
41
/* Name of helper script used by Xdg_DetectDesktopEnv. */
42
static const char xdgDetectDEExec[] = "vmware-xdg-detect-de";
51
*-----------------------------------------------------------------------------
53
* Xdg_DetectDesktopEnv --
55
* Captures output from external vmware-xdg-detect-de script to determine
56
* which desktop environment we're running under.
59
* Returns a pointer to a string specifying the desktop environment on
60
* success or NULL on failure.
62
* This function only guarantees that the returned string matches the
66
* Allocates memory for outbuf on first call for duration of program.
67
* Uses popen(), relying on $PATH, to find and execute xdgDetectDeExec.
68
* Caller must not modify returned string.
70
*-----------------------------------------------------------------------------
74
Xdg_DetectDesktopEnv(void)
76
static char *outbuf = NULL;
79
FILE *cmdPipe = popen(xdgDetectDEExec, "r");
82
static const size_t maxSize = sizeof "TEHLONGISTDESKTOPENVEVAR";
83
size_t outLen; // Doesn't include NUL.
86
if (StdIO_ReadNextLine(cmdPipe, &outbuf, maxSize, &outLen)
90
for (i = outbuf; i < &outbuf[outLen]; i++) {
91
/* We expect a string in all capitals. */
92
if (*i < 'A' || *i > 'Z') {
100
status = pclose(cmdPipe);
101
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {