3 #ifndef vtksys_SharedForward_h 4 # define vtksys_SharedForward_h 62 # if defined(__clang__) && defined(__has_warning) 63 # if __has_warning("-Wcast-qual") 64 # pragma clang diagnostic push 65 # pragma clang diagnostic ignored "-Wcast-qual" 71 # if !defined(vtksys_SHARED_FORWARD_DIR_BUILD) 72 # error "Must define vtksys_SHARED_FORWARD_DIR_BUILD" 74 # if !defined(KWSYS_SHARED_FORWARD_DIR_BUILD) 75 # define KWSYS_SHARED_FORWARD_DIR_BUILD \ 76 vtksys_SHARED_FORWARD_DIR_BUILD 80 # if !defined(vtksys_SHARED_FORWARD_PATH_BUILD) 81 # error "Must define vtksys_SHARED_FORWARD_PATH_BUILD" 83 # if !defined(KWSYS_SHARED_FORWARD_PATH_BUILD) 84 # define KWSYS_SHARED_FORWARD_PATH_BUILD \ 85 vtksys_SHARED_FORWARD_PATH_BUILD 89 # if !defined(vtksys_SHARED_FORWARD_PATH_INSTALL) 90 # error "Must define vtksys_SHARED_FORWARD_PATH_INSTALL" 92 # if !defined(KWSYS_SHARED_FORWARD_PATH_INSTALL) 93 # define KWSYS_SHARED_FORWARD_PATH_INSTALL \ 94 vtksys_SHARED_FORWARD_PATH_INSTALL 98 # if !defined(vtksys_SHARED_FORWARD_EXE_BUILD) 99 # error "Must define vtksys_SHARED_FORWARD_EXE_BUILD" 101 # if !defined(KWSYS_SHARED_FORWARD_EXE_BUILD) 102 # define KWSYS_SHARED_FORWARD_EXE_BUILD \ 103 vtksys_SHARED_FORWARD_EXE_BUILD 107 # if !defined(vtksys_SHARED_FORWARD_EXE_INSTALL) 108 # error "Must define vtksys_SHARED_FORWARD_EXE_INSTALL" 110 # if !defined(KWSYS_SHARED_FORWARD_EXE_INSTALL) 111 # define KWSYS_SHARED_FORWARD_EXE_INSTALL \ 112 vtksys_SHARED_FORWARD_EXE_INSTALL 117 # if defined(vtksys_SHARED_FORWARD_CONFIG_NAME) 118 # define KWSYS_SHARED_FORWARD_CONFIG_NAME \ 119 vtksys_SHARED_FORWARD_CONFIG_NAME 121 # undef KWSYS_SHARED_FORWARD_CONFIG_NAME 125 # if defined(vtksys_SHARED_FORWARD_OPTION_COMMAND) 126 # if !defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND) 127 # define KWSYS_SHARED_FORWARD_OPTION_COMMAND \ 128 vtksys_SHARED_FORWARD_OPTION_COMMAND 131 # undef KWSYS_SHARED_FORWARD_OPTION_COMMAND 135 # if defined(vtksys_SHARED_FORWARD_OPTION_PRINT) 136 # if !defined(KWSYS_SHARED_FORWARD_OPTION_PRINT) 137 # define KWSYS_SHARED_FORWARD_OPTION_PRINT \ 138 vtksys_SHARED_FORWARD_OPTION_PRINT 141 # undef KWSYS_SHARED_FORWARD_OPTION_PRINT 145 # if defined(vtksys_SHARED_FORWARD_OPTION_LDD) 146 # if !defined(KWSYS_SHARED_FORWARD_OPTION_LDD) 147 # define KWSYS_SHARED_FORWARD_OPTION_LDD \ 148 vtksys_SHARED_FORWARD_OPTION_LDD 151 # undef KWSYS_SHARED_FORWARD_OPTION_LDD 163 # if defined(_WIN32) && !defined(__CYGWIN__) 164 # include <windows.h> 167 # include <process.h> 168 # define KWSYS_SHARED_FORWARD_ESCAPE_ARGV 170 # include <sys/stat.h> 177 # if defined(_WIN32) && !defined(__CYGWIN__) 178 # define KWSYS_SHARED_FORWARD_PATH_SEP ';' 179 # define KWSYS_SHARED_FORWARD_PATH_SLASH '\\' 181 # define KWSYS_SHARED_FORWARD_PATH_SEP ':' 182 # define KWSYS_SHARED_FORWARD_PATH_SLASH '/' 192 # if defined(PATH_MAX) 193 # define KWSYS_SHARED_FORWARD_MAXPATH PATH_MAX 194 # elif defined(MAXPATHLEN) 195 # define KWSYS_SHARED_FORWARD_MAXPATH MAXPATHLEN 197 # define KWSYS_SHARED_FORWARD_MAXPATH 16384 205 # if defined(__linux) 206 # define KWSYS_SHARED_FORWARD_LDD "ldd" 207 # define KWSYS_SHARED_FORWARD_LDD_N 1 208 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 211 # elif defined(__FreeBSD__) 212 # define KWSYS_SHARED_FORWARD_LDD "ldd" 213 # define KWSYS_SHARED_FORWARD_LDD_N 1 214 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 217 # elif defined(__OpenBSD__) 218 # define KWSYS_SHARED_FORWARD_LDD "ldd" 219 # define KWSYS_SHARED_FORWARD_LDD_N 1 220 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 223 # elif defined(__APPLE__) 224 # define KWSYS_SHARED_FORWARD_LDD "otool", "-L" 225 # define KWSYS_SHARED_FORWARD_LDD_N 2 226 # define KWSYS_SHARED_FORWARD_LDPATH "DYLD_LIBRARY_PATH" 230 # define KWSYS_SHARED_FORWARD_LDD "dump", "-H" 231 # define KWSYS_SHARED_FORWARD_LDD_N 2 232 # define KWSYS_SHARED_FORWARD_LDPATH "LIBPATH" 235 # elif defined(__sun) 236 # define KWSYS_SHARED_FORWARD_LDD "ldd" 237 # define KWSYS_SHARED_FORWARD_LDD_N 1 238 # include <sys/isa_defs.h> 240 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 241 # elif defined(_LP64) 242 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH_64" 246 # elif defined(__hpux) 247 # define KWSYS_SHARED_FORWARD_LDD "chatr" 248 # define KWSYS_SHARED_FORWARD_LDD_N 1 249 # if defined(__LP64__) 250 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 252 # define KWSYS_SHARED_FORWARD_LDPATH "SHLIB_PATH" 256 # elif defined(__sgi) && defined(_MIPS_SIM) 257 # define KWSYS_SHARED_FORWARD_LDD "ldd" 258 # define KWSYS_SHARED_FORWARD_LDD_N 1 259 # if _MIPS_SIM == _ABIO32 260 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 261 # elif _MIPS_SIM == _ABIN32 262 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARYN32_PATH" 263 # elif _MIPS_SIM == _ABI64 264 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY64_PATH" 268 # elif defined(__CYGWIN__) 269 # define KWSYS_SHARED_FORWARD_LDD \ 272 # define KWSYS_SHARED_FORWARD_LDD_N 1 273 # define KWSYS_SHARED_FORWARD_LDPATH "PATH" 276 # elif defined(_WIN32) 277 # define KWSYS_SHARED_FORWARD_LDPATH "PATH" 281 # define KWSYS_SHARED_FORWARD_LDD "ldd" 282 # define KWSYS_SHARED_FORWARD_LDD_N 1 283 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH" 286 # ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV 287 typedef struct kwsys_sf_arg_info_s
294 static kwsys_sf_arg_info kwsys_sf_get_arg_info(
const char* in)
297 kwsys_sf_arg_info
info;
303 int windows_backslashes = 0;
308 info.size = (
int)strlen(in) + 1;
312 for (c = in; *c; ++c) {
314 if (strchr(
" \t?'#&<>|^", *c)) {
321 ++windows_backslashes;
322 }
else if (*c ==
'"') {
325 info.size += windows_backslashes + 1;
326 windows_backslashes = 0;
331 windows_backslashes = 0;
341 info.size += windows_backslashes;
347 static char* kwsys_sf_get_arg(kwsys_sf_arg_info
info,
char* out)
353 int windows_backslashes = 0;
362 for (c =
info.arg; *c; ++c) {
366 ++windows_backslashes;
367 }
else if (*c ==
'"') {
370 while (windows_backslashes > 0) {
371 --windows_backslashes;
380 windows_backslashes = 0;
389 while (windows_backslashes > 0) {
390 --windows_backslashes;
408 # if defined(_WIN32) && !defined(__CYGWIN__) 415 return realpath(in_path, out_path) != 0;
423 HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
424 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
425 HANDLE h2 = CreateFileA(file2, GENERIC_READ, FILE_SHARE_READ, NULL,
426 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
427 if (h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE) {
428 BY_HANDLE_FILE_INFORMATION fi1;
429 BY_HANDLE_FILE_INFORMATION fi2;
430 GetFileInformationByHandle(h1, &fi1);
431 GetFileInformationByHandle(h2, &fi2);
432 result = (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
433 fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
434 fi1.nFileIndexLow == fi2.nFileIndexLow);
440 struct stat fs1, fs2;
441 return (stat(file1, &fs1) == 0 && stat(file2, &fs2) == 0 &&
442 memcmp(&fs2.st_dev, &fs1.st_dev,
sizeof(fs1.st_dev)) == 0 &&
443 memcmp(&fs2.st_ino, &fs1.st_ino,
sizeof(fs1.st_ino)) == 0 &&
444 fs2.st_size == fs1.st_size);
451 # if defined(_WIN32) && !defined(__CYGWIN__) 453 DWORD original = GetLastError();
455 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
456 0, original, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
460 snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH,
461 "Error 0x%lX (FormatMessage failed with error 0x%lX)", original,
466 strcpy(message, strerror(errno));
472 char const*
const* argv)
474 # ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV 478 char const*
const* argvc;
479 for (argvc = argv; *argvc; ++argvc, ++argc) {
485 char** nargv = (
char**)malloc((argc + 1) *
sizeof(
char*));
487 for (i = 0; i < argc; ++i) {
488 kwsys_sf_arg_info
info = kwsys_sf_get_arg_info(argv[i]);
489 nargv[i] = (
char*)malloc(info.size);
490 kwsys_sf_get_arg(info, nargv[i]);
495 argv = (
char const*
const*)nargv;
500 # if defined(_MSC_VER) 502 # elif defined(__MINGW32__) && !defined(__MINGW64__) 505 execvp(cmd, (
char*
const*)argv);
513 int last_slash_index = -1;
514 const char* end = begin + strlen(begin);
515 for (; begin <= end && last_slash_index < 0; --end) {
516 if (*end ==
'/' || *end ==
'\\') {
517 last_slash_index = (
int)(end - begin);
522 if (last_slash_index < 0) {
525 }
else if (last_slash_index == 0) {
530 else if (last_slash_index == 2 && begin[1] ==
':') {
532 strncpy(result, begin, (
size_t)last_slash_index);
534 result[last_slash_index + 1] = 0;
539 strncpy(result, begin, (
size_t)last_slash_index);
540 result[last_slash_index] = 0;
547 # if defined(_MSC_VER) 548 # define KWSYS_SHARED_FORWARD_ACCESS _access 550 # define KWSYS_SHARED_FORWARD_ACCESS access 553 # define KWSYS_SHARED_FORWARD_ACCESS_OK X_OK 555 # define KWSYS_SHARED_FORWARD_ACCESS_OK 04 569 const char* p = argv0;
570 for (; *p && !has_slash; ++p) {
571 if (*p ==
'/' || *p ==
'\\') {
582 const char* path = getenv(
"PATH");
583 const char* begin = path;
584 const char* end = begin + (begin ? strlen(begin) : 0);
585 const char* first = begin;
586 while (first != end) {
602 size_t length = (size_t)(last - first);
603 if (*(last - 1) ==
'/' || *(last - 1) ==
'\\') {
608 strncpy(result, first, length);
610 strcpy(result + (length) + 1, argv0);
632 const char* in_path,
char* result,
636 if (in_path[0] ==
'/') {
638 strcpy(result, in_path);
641 else if (in_path[0] && in_path[1] ==
':') {
643 strcpy(result, in_path);
649 strcpy(temp_path, self_path);
651 strcat(temp_path, in_path);
656 fprintf(stderr,
"Error converting %s \"%s\" to real path: %s\n", desc,
668 char* ldpath,
char* exe)
673 static const char* search_path_install[] = {
678 const char** search_path;
679 const char* exe_path;
682 # if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) 688 const char* self_path_logical = self_path;
695 fprintf(stderr,
"Error converting self path \"%s\" to real path: %s\n",
704 search_path = search_path_build;
711 # if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) 717 search_path = search_path_install;
724 # if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME) 726 strcpy(self_path_logical, self_path);
733 for (dir = search_path; *dir; ++dir) {
735 if (dir != search_path) {
741 ldpath + strlen(ldpath),
742 "runtime path entry")) {
750 "executable file")) {
760 char const*
const* arg = argv;
762 fprintf(stderr,
"Error running");
763 for (; *arg; ++arg) {
764 fprintf(stderr,
" \"%s\"", *arg);
766 fprintf(stderr,
": %s\n", msg);
776 char const** argv = (
char const**)argv_in;
794 # if defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND) 797 strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_COMMAND) == 0) {
800 strcpy(exe, argv[2]);
806 "Option " KWSYS_SHARED_FORWARD_OPTION_COMMAND
807 " must be followed by a command line.\n");
813 # if defined(KWSYS_SHARED_FORWARD_OPTION_PRINT) 816 strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_PRINT) == 0) {
818 fprintf(stdout,
"%s\n", exe);
823 # if defined(KWSYS_SHARED_FORWARD_OPTION_LDD) 825 if (argc > 1 && strcmp(argv[1], KWSYS_SHARED_FORWARD_OPTION_LDD) == 0) {
826 # if defined(KWSYS_SHARED_FORWARD_LDD) 837 fprintf(stderr,
"No ldd-like tool is known to this executable.\n");
854 fprintf(stderr,
"Error locating executable \"%s\".\n", argv[0]);
865 # if defined(__clang__) && defined(__has_warning) 866 # if __has_warning("-Wcast-qual") 867 # pragma clang diagnostic pop 872 # error "vtksys/SharedForward.h should be included only once." static int kwsys_shared_forward_realpath(const char *in_path, char *out_path)
#define KWSYS_SHARED_FORWARD_PATH_SEP
static int kwsys_shared_forward_fullpath(const char *self_path, const char *in_path, char *result, const char *desc)
static void kwsys_shared_forward_print_failure(char const *const *argv)
static void kwsys_shared_forward_execvp(const char *cmd, char const *const *argv)
#define KWSYS_SHARED_FORWARD_PATH_BUILD
#define KWSYS_SHARED_FORWARD_ACCESS_OK
static const char kwsys_shared_forward_path_sep[2]
#define KWSYS_SHARED_FORWARD_LDD_N
#define KWSYS_SHARED_FORWARD_EXE_INSTALL
#define KWSYS_SHARED_FORWARD_EXE_BUILD
static void kwsys_shared_forward_strerror(char *message)
#define KWSYS_SHARED_FORWARD_DIR_BUILD
static int vtksys_shared_forward_to_real(int argc, char **argv_in)
static int kwsys_shared_forward_samepath(const char *file1, const char *file2)
static void kwsys_shared_forward_dirname(const char *begin, char *result)
#define KWSYS_SHARED_FORWARD_LDD
#define KWSYS_SHARED_FORWARD_ACCESS
static int kwsys_shared_forward_is_executable(const char *f)
static char kwsys_shared_forward_ldpath[65535]
#define KWSYS_SHARED_FORWARD_PATH_SLASH
#define KWSYS_SHARED_FORWARD_PATH_INSTALL
static const char kwsys_shared_forward_path_slash[2]
#define KWSYS_SHARED_FORWARD_LDPATH
#define KWSYS_SHARED_FORWARD_MAXPATH
static int kwsys_shared_forward_get_settings(const char *self_path, char *ldpath, char *exe)
static int kwsys_shared_forward_self_path(const char *argv0, char *result)