Skip to content

Commit e6ce18f

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

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
@@ -51,8 +51,30 @@ POSSIBILITY OF SUCH DAMAGE. */
5151
#include "internal.h"
5252

5353
#ifndef HAVE_GETEXECNAME
54+
#if defined(__WIN32__) && !defined(__MSYS__) && !defined(__CYGWIN__)
55+
/*
56+
* Windows-specific implementation of getexecname();
57+
* MSYS/Cygwin want to fall back to /proc/self/exe instead.
58+
*/
59+
#define WIN32_LEAN_AND_MEAN
60+
#include <windows.h>
61+
62+
static inline const char *getexecname(void)
63+
{
64+
static char path[32768]; /* Allow for long paths, i.e. do not use MAX_PATH */
65+
66+
switch (GetModuleFileNameA(NULL, path, sizeof(path))) {
67+
case 0:
68+
case sizeof(path):
69+
return NULL;
70+
}
71+
72+
return path;
73+
}
74+
#else
5475
#define getexecname() NULL
5576
#endif
77+
#endif
5678

5779
#if !defined (HAVE_KERN_PROC_ARGS) && !defined (HAVE_KERN_PROC)
5880

0 commit comments

Comments
 (0)