Changeset 35699 for main/trunk


Ignore:
Timestamp:
2021-10-25T00:14:15+13:00 (3 years ago)
Author:
davidb
Message:

dirname() wasn't part of VS, so adding in our own get_dirname()

Location:
main/trunk/search4j
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/search4j/libsearch4j.cpp

    r35698 r35699  
    339339#endif
    340340
     341
     342char* get_dirname (const char* full_file_path)
     343{
     344  char* full_file_path_dup = strdup(full_file_path);
     345#ifdef WINDOWS
     346  char *p = strrchr(full_file_path_dup, '\\');
     347#else
     348  char *p = strrchr(full_file_path_dup, '/');
     349#endif
     350
     351  if (p != NULL) {
     352    p[0] = 0;
     353  }
     354   
     355  return full_file_path_dup;
     356}
     357
    341358/*
    342359* function to find java
     
    348365    if ( verbose ) cout << "Searching for a JVM" << endl;
    349366   
    350     char *javaHomeEnv = NULL;
     367    char *javaHomeEnv = NULL; // use below would benefit from more careful application of strdup()/free()
    351368    bool jvmFound = false;
    352369   
     
    559576        if ( strcmp(full_path_java,"") != 0) {
    560577          // go two directories up from where 'java' was found
    561           javaHomeEnv = dirname(dirname(full_path_java));
    562 
     578
     579          char* parent_dir = get_dirname(full_path_java);
     580          char* parent_parent_dir = get_dirname(parent_dir);
     581         
     582          javaHomeEnv = parent_parent_dir;
     583
     584          free(parent_dir);
     585         
    563586          // Logic from here same as for other search4j java/javac testing
    564587          if ( verbose ) cout << "(" << javaHomeEnv << ") ";
  • main/trunk/search4j/libsearch4j.h

    r35698 r35699  
    66#include <sstream>
    77#include <sys/stat.h>
    8 
    9 #include <libgen.h>
    108
    119using namespace std;
Note: See TracChangeset for help on using the changeset viewer.