Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed use of PATH_MAX (only used in searchpath expansion).

Added searchpath to regression test.
  • Loading branch information...
commit 2d346a02ca88d90b3866c4af6e17be52e73fdf9c 1 parent 5052077
Brent Burley authored
2  src/ptex/Makefile
@@ -9,7 +9,7 @@ endif
9 9 # DEBUG = -g -DDEBUG
10 10 DEBUG = -O2 -DNDEBUG
11 11 INCPATH = -I.
12   -DEFINES = -DPATH_MAX=256
  12 +DEFINES =
13 13 CXXFLAGS = -Wall -pedantic -W -std=c++98 $(DEBUG) $(INCPATH) $(DEFINES) -fPIC
14 14 LFLAGS =
15 15 LIBS = -lm -lz -lpthread
14 src/ptex/PtexCache.cpp
@@ -334,17 +334,21 @@ PtexTexture* PtexReaderCache::get(const char* filename, Ptex::String& error)
334 334
335 335 // temporarily release cache lock while we open the file
336 336 cachelock.unlock();
337   - char tmppath[PATH_MAX+1];
  337 + std::string tmppath;
  338 + const char* pathToOpen = filename;
338 339 if (!_io) {
339 340 if (filename[0] != '/' && !_searchdirs.empty()) {
340 341 // file is relative, search in searchpath
  342 + tmppath.reserve(256); // minimize reallocs (will grow automatically)
341 343 bool found = false;
342 344 struct stat statbuf;
343 345 for (size_t i = 0, size = _searchdirs.size(); i < size; i++) {
344   - snprintf(tmppath, sizeof(tmppath), "%s/%s", _searchdirs[i].c_str(), filename);
345   - if (stat(tmppath, &statbuf) == 0) {
  346 + tmppath = _searchdirs[i];
  347 + tmppath += "/";
  348 + tmppath += filename;
  349 + if (stat(tmppath.c_str(), &statbuf) == 0) {
346 350 found = true;
347   - filename = tmppath;
  351 + pathToOpen = tmppath.c_str();
348 352 break;
349 353 }
350 354 }
@@ -356,7 +360,7 @@ PtexTexture* PtexReaderCache::get(const char* filename, Ptex::String& error)
356 360 }
357 361 }
358 362 }
359   - if (ok) ok = reader->open(filename, error);
  363 + if (ok) ok = reader->open(pathToOpen, error);
360 364
361 365 // reacquire cache lock
362 366 cachelock.lock();
1  src/ptex/PtexPlatform.h
@@ -79,7 +79,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
79 79 typedef __int64 FilePos;
80 80 #define fseeko _fseeki64
81 81 #define ftello _ftelli64
82   -#define PATH_MAX MAX_PATH
83 82
84 83 inline double log2(double x) {
85 84 return log(x) * 1.4426950408889634;
5 src/tests/rtest.cpp
@@ -101,7 +101,9 @@ void DumpMetaData(PtexMetaData* meta)
101 101 int main(int /*argc*/, char** /*argv*/)
102 102 {
103 103 Ptex::String error;
104   - PtexTexture* r = PtexTexture::open("test.ptx", error);
  104 + PtexPtr<PtexCache> c(PtexCache::create());
  105 + c->setSearchPath("foo/bar:.");
  106 + PtexPtr<PtexTexture> r(c->get("test.ptx", error));
105 107
106 108 if (!r) {
107 109 std::cerr << error.c_str() << std::endl;
@@ -153,6 +155,5 @@ int main(int /*argc*/, char** /*argv*/)
153 155 dh->release();
154 156 }
155 157
156   - r->release();
157 158 return 0;
158 159 }

0 comments on commit 2d346a0

Please sign in to comment.
Something went wrong with that request. Please try again.