mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
Several places in the runtime make use of the program basename. This is
computed by stripping any directory qualification from the value of argv[0].
Currently, this is done by searching for uses of '/' as a directory separator.
This does not work on Windows where '\' is the directory separator and paths
may also be drive qualified. This diff adds a function that will handle
Windows-style paths.
Also, none of the uses of the program basename in the runtime currently account
for the presence of the .exe executable extension on Windows. After this diff,
users won't have to, and in fact will not be allowed to, include the .exe
extension in the program name in these contexts.
runtime/mercury_runtime_util.[ch]:
Add a function, MR_get_program_basename(), whose job is
to strip any drive or directory qualification, and the executable
extension from a given path. On Windows, we use the OS's splitpath()
function to do this.
Add an XXX about the .exe extension on Cygwin.
runtime/mercury_wrapper.c:
Use the new function when computing:
- the name of the program-specific MERCURY_OPTIONS environment variable;
- the value of the --trace-count-if-exec runtime option;
- the value of the --coverage-test-if-exec runtime option.
doc/user_guide.texi:
Document that the .exe extension is not expected in the three spots above.
36 lines
1.3 KiB
C
36 lines
1.3 KiB
C
// vim: ts=4 sw=4 expandtab ft=c
|
|
|
|
// Copyright (C) 2001,2006 The University of Melbourne.
|
|
// Copyright (C) 2014, 2016, 2018 The Mercury team.
|
|
// This file is distributed under the terms specified in COPYING.LIB.
|
|
|
|
#ifndef MERCURY_RUNTIME_UTIL_H
|
|
#define MERCURY_RUNTIME_UTIL_H
|
|
|
|
#include <stdio.h>
|
|
|
|
// A reasonable buffer size for MR_strerror().
|
|
|
|
#define MR_STRERROR_BUF_SIZE 256
|
|
|
|
// Thread-safe strerror function. Returns a pointer to a null terminated string
|
|
// describing the error number. The returned pointer may be to the provided
|
|
// buffer, or it may be a pointer into static or thread-local memory.
|
|
// errno may be modified by this call.
|
|
|
|
extern const char *MR_strerror(int errnum, char *buf, size_t buflen);
|
|
|
|
extern FILE *MR_checked_fopen(const char *filename,
|
|
const char *message, const char *mode);
|
|
extern void MR_checked_fclose(FILE *file, const char *filename);
|
|
extern void MR_checked_atexit(void (*func)(void));
|
|
extern int MR_setenv(const char *name, const char *value,
|
|
int overwrite);
|
|
|
|
// Strip any directory components from the argument.
|
|
// On Windows, this will also strip the ".exe" extension.
|
|
// A ".exe" extension on other systems (e.g. Linux) will be left alone.
|
|
extern const char *MR_get_program_basename(const char *);
|
|
|
|
#endif // MERCURY_RUNTIME_UTIL_H
|