xwin: Clean up os wrappers for System, Popen and Pclose on Windows
Popen and Pclose are never used on Windows, so don't bother to even try to define them. System(s) was defined as system(s), but the two users of that function are in xkb, which carefully redefines that as Win32System. Move Win32System and Win32TempDir to os/utils.c, renaming Win32System to be just System, which simplifies the xkb code Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>
This commit is contained in:
parent
357ec54f46
commit
75966a4186
10
include/os.h
10
include/os.h
|
@ -359,9 +359,13 @@ Fopen(const char *, const char *);
|
|||
extern _X_EXPORT int
|
||||
Fclose(pointer);
|
||||
#else
|
||||
#define System(a) system(a)
|
||||
#define Popen(a,b) popen(a,b)
|
||||
#define Pclose(a) pclose(a)
|
||||
|
||||
extern const char *
|
||||
Win32TempDir(void);
|
||||
|
||||
extern int
|
||||
System(const char *cmdline);
|
||||
|
||||
#define Fopen(a,b) fopen(a,b)
|
||||
#define Fclose(a) fclose(a)
|
||||
#endif
|
||||
|
|
73
os/utils.c
73
os/utils.c
|
@ -1561,6 +1561,79 @@ Fclose(pointer iop)
|
|||
|
||||
#endif /* !WIN32 */
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <X11/Xwindows.h>
|
||||
|
||||
const char *
|
||||
Win32TempDir()
|
||||
{
|
||||
static char buffer[PATH_MAX];
|
||||
|
||||
if (GetTempPath(sizeof(buffer), buffer)) {
|
||||
int len;
|
||||
|
||||
buffer[sizeof(buffer) - 1] = 0;
|
||||
len = strlen(buffer);
|
||||
if (len > 0)
|
||||
if (buffer[len - 1] == '\\')
|
||||
buffer[len - 1] = 0;
|
||||
return buffer;
|
||||
}
|
||||
if (getenv("TEMP") != NULL)
|
||||
return getenv("TEMP");
|
||||
else if (getenv("TMP") != NULL)
|
||||
return getenv("TEMP");
|
||||
else
|
||||
return "/tmp";
|
||||
}
|
||||
|
||||
int
|
||||
System(const char *cmdline)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
DWORD dwExitCode;
|
||||
char *cmd = strdup(cmdline);
|
||||
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
|
||||
LPVOID buffer;
|
||||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) & buffer, 0, NULL)) {
|
||||
ErrorF("[xkb] Starting '%s' failed!\n", cmdline);
|
||||
}
|
||||
else {
|
||||
ErrorF("[xkb] Starting '%s' failed: %s", cmdline, (char *) buffer);
|
||||
LocalFree(buffer);
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
return -1;
|
||||
}
|
||||
/* Wait until child process exits. */
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
||||
|
||||
/* Close process and thread handles. */
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
free(cmd);
|
||||
|
||||
return dwExitCode;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CheckUserParameters: check for long command line arguments and long
|
||||
* environment variables. By default, these checks are only done when
|
||||
|
|
|
@ -44,12 +44,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#ifdef WIN32
|
||||
/* from ddxLoad.c */
|
||||
extern const char *Win32TempDir(void);
|
||||
extern int Win32System(const char *cmdline);
|
||||
|
||||
#undef System
|
||||
#define System Win32System
|
||||
|
||||
#define W32_tmparg " '%s'"
|
||||
#define W32_tmpfile ,tmpname
|
||||
#define W32_tmplen strlen(tmpname)+3
|
||||
|
|
|
@ -68,81 +68,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define PATHSEPARATOR "/"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <X11/Xwindows.h>
|
||||
const char *
|
||||
Win32TempDir()
|
||||
{
|
||||
static char buffer[PATH_MAX];
|
||||
|
||||
if (GetTempPath(sizeof(buffer), buffer)) {
|
||||
int len;
|
||||
|
||||
buffer[sizeof(buffer) - 1] = 0;
|
||||
len = strlen(buffer);
|
||||
if (len > 0)
|
||||
if (buffer[len - 1] == '\\')
|
||||
buffer[len - 1] = 0;
|
||||
return buffer;
|
||||
}
|
||||
if (getenv("TEMP") != NULL)
|
||||
return getenv("TEMP");
|
||||
else if (getenv("TMP") != NULL)
|
||||
return getenv("TEMP");
|
||||
else
|
||||
return "/tmp";
|
||||
}
|
||||
|
||||
int
|
||||
Win32System(const char *cmdline)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
DWORD dwExitCode;
|
||||
char *cmd = strdup(cmdline);
|
||||
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory(&pi, sizeof(pi));
|
||||
|
||||
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
|
||||
LPVOID buffer;
|
||||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR) & buffer, 0, NULL)) {
|
||||
ErrorF("[xkb] Starting '%s' failed!\n", cmdline);
|
||||
}
|
||||
else {
|
||||
ErrorF("[xkb] Starting '%s' failed: %s", cmdline, (char *) buffer);
|
||||
LocalFree(buffer);
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
return -1;
|
||||
}
|
||||
/* Wait until child process exits. */
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
GetExitCodeProcess(pi.hProcess, &dwExitCode);
|
||||
|
||||
/* Close process and thread handles. */
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
free(cmd);
|
||||
|
||||
return dwExitCode;
|
||||
}
|
||||
|
||||
#undef System
|
||||
#define System(x) Win32System(x)
|
||||
#endif
|
||||
|
||||
static void
|
||||
OutputDirectory(char *outdir, size_t size)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user