2 * Copyright (c) 2016, 2017
3 * mirabilos <m@mirbsd.org>
5 * Provided that these terms and disclaimer and all copyright notices
6 * are retained or reproduced in an accompanying document, permission
7 * is granted to deal in this work without restriction, including un-
8 * limited rights to use, publicly perform, distribute, sell, modify,
9 * merge, give away, or sublicence.
11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12 * the utmost extent permitted by applicable law, neither express nor
13 * implied; without malicious intent or gross negligence. In no event
14 * may a licensor, author or contributor be held liable for indirect,
15 * direct, other damage, loss, or other issues arising in any way out
16 * of dealing in the work, even if advised of the possibility of such
17 * damage or existence of a defect, except proven that it results out
18 * of said person's immediate fault when using the work as intended.
23 __RCSID("$MirOS: contrib/code/jupp/win32.c,v 1.4 2017/12/02 02:07:39 tg Exp $");
27 #include <cygwin/version.h>
32 * Retrieve the realpath of the program (what could be argv[0] if the
33 * Unix designers had wanted it).
39 /* plus one to detect truncation */
40 char buf[MAX_PATH + 1];
42 if (!(res = GetModuleFileName(NULL, buf, sizeof(buf))) ||
43 ((size_t)res > (size_t)(MAX_PATH)))
50 /* return command line as passed to the .EXE (just like cygwin32’s dcrt0.cc) */
52 cygwin32_cmdline(void)
56 cp = strdup(GetCommandLineA());
57 if (!AreFileApisANSI())
59 return ((unsigned char *)cp);
62 /* Cygwin before 1.7.2 did not have locale support */
63 #if defined(CYGWIN_VERSION_API_MAJOR) && (CYGWIN_VERSION_API_MAJOR < 1) && \
64 defined(CYGWIN_VERSION_API_MINOR) && (CYGWIN_VERSION_API_MINOR < 222)
66 * Mirror get_cp() in winsup/cygwin/miscfuncs.cc as used by
67 * dev_console::str_to_con() in winsup/cygwin/fhandler_console.cc
72 return (AreFileApisANSI() ? GetACP() : GetOEMCP());
76 #endif /* __CYGWIN__ */