[Wavelet-commit] Wavelet Image.cc, 1.28, 1.29 JpgReader.cc, 1.5, 1.6 MagickInter.cc, 1.1, 1.2 tools
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2009-02-23 17:26:48
|
Update of /cvsroot/wavelet/Wavelet In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8899 Modified Files: Image.cc JpgReader.cc MagickInter.cc tools.cc Log Message: sanified the temp file creation in MagickInter.cc Index: JpgReader.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/JpgReader.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** JpgReader.cc 7 Aug 2007 17:00:58 -0000 1.5 --- JpgReader.cc 23 Feb 2009 17:26:41 -0000 1.6 *************** *** 18,21 **** --- 18,22 ---- #include <stdexcept> #include <iostream> + #include <cstring> #if !(defined __WATCOMC__ && __WATCOMC__ < 1230) Index: tools.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/tools.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** tools.cc 17 Apr 2008 07:27:34 -0000 1.9 --- tools.cc 23 Feb 2009 17:26:41 -0000 1.10 *************** *** 37,41 **** tools_epsilons (double d1, double d2, double epsilon) { ! return !((d1 > d2) && (d1 - d2 > epsilon) || (d2 - d1 > epsilon)); } --- 37,41 ---- tools_epsilons (double d1, double d2, double epsilon) { ! return !(((d1 > d2) && (d1 - d2 > epsilon)) || (d2 - d1 > epsilon)); } Index: Image.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/Image.cc,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Image.cc 17 Apr 2008 07:27:34 -0000 1.28 --- Image.cc 23 Feb 2009 17:26:41 -0000 1.29 *************** *** 418,422 **** bool lifted = false; ! if (lifted = (startH < 0)) { for (int y = yoffs; y < toY; y++) --- 418,422 ---- bool lifted = false; ! if ((lifted = (startH < 0))) { for (int y = yoffs; y < toY; y++) Index: MagickInter.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/MagickInter.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MagickInter.cc 17 Apr 2008 07:27:34 -0000 1.1 --- MagickInter.cc 23 Feb 2009 17:26:41 -0000 1.2 *************** *** 12,15 **** --- 12,16 ---- #include <cstring> #include <iostream> + #include <cerrno> #include <Magick++/Image.h> #include <Magick++/Color.h> *************** *** 26,30 **** #include <fcntl.h> ! static int tempFileName (char *templ, const char *extension); static std::string --- 27,33 ---- #include <fcntl.h> ! static std::string tempFilePrefixFromEnv (std::string paddern, ! std::string delim); ! static int tempFileName (char *templ, const char *extension, unsigned int seed); static std::string *************** *** 34,41 **** static char buf[64] = { '\0' }; pid_t pid = getpid(); ! snprintf (buf, sizeof buf - 1, "util-tmp-%05d-XXXXXX", (int)pid); ! if (tempFileName (buf, theExtension.c_str ()) < 0) { ! throw std::invalid_argument ("Could not create temp file"); } return std::string (buf); --- 37,73 ---- static char buf[64] = { '\0' }; pid_t pid = getpid(); ! int rc = -1; ! std::string paddern = "wavelet-tmp-%05d-XXXXXX"; ! std::string paddernWithPrefix = tempFilePrefixFromEnv (paddern, "/"); ! unsigned seed = (unsigned)pid; ! ! if (paddernWithPrefix.size () > 0) { ! /* if we found a matching environment variable, then use it. */ ! snprintf (buf, sizeof buf - 1, paddernWithPrefix.c_str (), (int)pid); ! rc = tempFileName (buf, theExtension.c_str (), seed); ! } ! else ! { ! /* we found no matching environment variable, we try /tmp/ first. */ ! paddernWithPrefix = "/tmp/" + paddern; ! snprintf (buf, sizeof buf - 1, paddernWithPrefix.c_str (), (int)pid); ! rc = tempFileName (buf, theExtension.c_str (), seed); ! if (rc < 0) ! { ! snprintf (buf, sizeof buf - 1, paddern.c_str (), (int)pid); ! rc = tempFileName (buf, theExtension.c_str (), seed); ! } ! } ! ! ! if (rc < 0) ! { ! char ctemp[64]; ! snprintf(ctemp, sizeof ctemp, "%d", rc); ! throw std::invalid_argument ("Could not create temp file, rc: " ! + std::string(ctemp) + ", system error is: " ! + std::string (strerror (errno)).c_str () ! + ", could it be that the current directory is not writable?"); } return std::string (buf); *************** *** 319,323 **** // lib to depend on it... static int ! tempFileName (char *templ, const char *extension) { static char letters[] --- 351,355 ---- // lib to depend on it... static int ! tempFileName (char *templ, const char *extension, unsigned int seed) { static char letters[] *************** *** 328,332 **** int extenlen = strlen (extension); ! if(templen < 6) { return -1; --- 360,364 ---- int extenlen = strlen (extension); ! if (templen < 6) { return -1; *************** *** 340,344 **** } ! srand ((unsigned)time (NULL)); int fd; char *fname = NEW (char [templen + extenlen + 1]); --- 372,383 ---- } ! if (seed == 0) ! { ! srand ((unsigned)time (NULL)); ! } ! else ! { ! srand (seed); ! } int fd; char *fname = NEW (char [templen + extenlen + 1]); *************** *** 373,374 **** --- 412,434 ---- return 0; } + + + static std::string + tempFilePrefixFromEnv (std::string paddern, std::string delim = "/") + { + std::string rv; + + if (::getenv ("TMP") != NULL) + { + rv = ::getenv ("TMP") + delim + paddern; + } + else if (::getenv ("TEMP") != NULL) + { + rv = ::getenv ("TEMP") + delim + paddern; + } + else + { + rv = ""; + } + return rv; + } |