Skip to content

Commit 9bb74d9

Browse files
committed
Provide a Windows-specific getexecname()
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 575e1e3 commit 9bb74d9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

fileline.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,30 @@ POSSIBILITY OF SUCH DAMAGE. */
4242
#include "internal.h"
4343

4444
#ifndef HAVE_GETEXECNAME
45+
#if defined(__WIN32__) && !defined(__MSYS__) && !defined(__CYGWIN__)
46+
/*
47+
* Windows-specific implementation of getexecname();
48+
* MSYS/Cygwin want to fall back to /proc/self/exe instead.
49+
*/
50+
#define WIN32_LEAN_AND_MEAN
51+
#include <windows.h>
52+
53+
static inline const char *getexecname(void)
54+
{
55+
static char path[32768]; /* Allow for long paths, i.e. do not use MAX_PATH */
56+
57+
switch (GetModuleFileNameA(NULL, path, sizeof(path))) {
58+
case 0:
59+
case sizeof(path):
60+
return NULL;
61+
}
62+
63+
return path;
64+
}
65+
#else
4566
#define getexecname() NULL
4667
#endif
68+
#endif
4769

4870
/* Initialize the fileline information from the executable. Returns 1
4971
on success, 0 on failure. */

0 commit comments

Comments
 (0)