Changeset 1742


Ignore:
Timestamp:
08/11/11 10:39:23 (7 months ago)
Author:
Freddie Akeroyd
Message:

Fix path length bug in C++ inquire file command - tests now work. Refs #299

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/cpp/NeXusFile.hpp

    r1735 r1742  
    801801     * \return The name of the file. 
    802802     */ 
    803     std::string inquireFile(const int buff_length = NX_MAXNAMELEN); 
     803    std::string inquireFile(const int buff_length = NX_MAXPATHLEN); 
    804804 
    805805    /** 
  • trunk/include/napi.h

    r1738 r1742  
    119119#define NX_MAXRANK 32 
    120120#define NX_MAXNAMELEN 64 
     121#define NX_MAXPATHLEN 1024 
    121122 
    122123 
  • trunk/test/napi_test.c

    r1741 r1742  
    3636static int testExternal(char *progName); 
    3737 
    38 char *relativePathOf(const char* filename) { 
     38static const char *relativePathOf(const char* filename) { 
    3939  char cwd[1024]; 
    40   char *pointer; 
    4140 
    4241  getcwd(cwd, sizeof(cwd)); 
    4342   
    44   if (strncmp(filename, cwd, strlen(cwd)) == 0) { 
     43  if (strncmp(filename, cwd, strlen(cwd)) == 0)  
     44  { 
    4545        return filename+strlen(cwd)+1; 
    4646  } 
    47   return filename; 
     47  else 
     48  { 
     49        return filename; 
     50  } 
    4851} 
    4952 
  • trunk/test/napi_test_cpp.cxx

    r1741 r1742  
    1717using std::vector; 
    1818 
    19 char *relativePathOf(std::string filenamestr) { 
     19static std::string relativePathOf(const std::string& filenamestr) { 
    2020  char cwd[1024]; 
    21   char *filename; 
    22  
    23   filename = strdup(filenamestr.c_str()); 
    2421 
    2522  getcwd(cwd, sizeof(cwd)); 
    2623   
    27 //fprintf(stderr, "filename %s cwd %s\n", filename, cwd); 
    28   if (strncmp(filename, cwd, strlen(cwd)) == 0) { 
    29         return filename + strlen(cwd) + 1; 
    30   } 
    31   return filename; 
    32 } 
    33  
    34 int writeTest(const string& filename, NXaccess create_code) { 
     24  if ( filenamestr.compare(0, strlen(cwd), cwd) == 0 ) 
     25  { 
     26      return filenamestr.substr(strlen(cwd)+1);  // +1 to skip trailing / 
     27  } 
     28  else 
     29  { 
     30      return filenamestr; 
     31  } 
     32} 
     33 
     34static int writeTest(const string& filename, NXaccess create_code) { 
    3535  NeXus::File file(filename, create_code); 
    3636  // create group 
Note: See TracChangeset for help on using the changeset viewer.