Visual Servoing Platform  version 3.6.1 under development (2024-12-07)
vpIoTools.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Directory management.
32  */
33 
39 // At this point, to make scandir() working as expected on armv7 virtualized on a x86-64bit architecture
40 // (see github/workflow/other-arch-isolated.yml) we need to define _FILE_OFFSET_BITS=64. Otherwise
41 // testVideo.cpp will fail.
42 // Since adding here something like:
43 // #include <visp3/core/vpConfig.h>
44 // #ifdef VISP_DEFINE_FILE_OFFSET_BITS
45 // # define _FILE_OFFSET_BITS 64
46 // #endif
47 // where VISP_DEFINE_FILE_OFFSET_BITS is defined in vpConfig.h doesn't work (my explanation is that the define
48 // should be done before any other includes; in vpConfig.h there is cstdlib that is included), the other way
49 // that was retained is to add to vpIoTools.cpp COMPILE_DEFINTIONS _FILE_OFFSET_BITS=64 (see CMakeLists.txt)
50 
51 #include <algorithm>
52 #include <cctype>
53 #include <cmath>
54 #include <errno.h>
55 #include <fcntl.h>
56 #include <fstream>
57 #include <functional>
58 #include <limits> // numeric_limits
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <sys/stat.h>
63 #include <sys/types.h>
64 #include <visp3/core/vpEndian.h>
65 #include <visp3/core/vpIoException.h>
66 #include <visp3/core/vpIoTools.h>
67 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
68 #include <dirent.h>
69 #include <unistd.h>
70 #elif defined(_WIN32)
71 #include <direct.h>
72 #include <windows.h>
73 #endif
74 #if !defined(_WIN32)
75 #ifdef __ANDROID__
76 // Like IOS, wordexp.cpp is not defined for Android
77 #else
78 #include <wordexp.h>
79 #endif
80 #endif
81 
82 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
83 #include <TargetConditionals.h> // To detect OSX or IOS using TARGET_OS_IOS macro
84 #endif
85 
86 #ifndef PATH_MAX
87 #ifdef _MAX_PATH
88 #define PATH_MAX _MAX_PATH
89 #else
90 #define PATH_MAX 1024
91 #endif
92 #endif
93 
94 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
95 #define VP_STAT stat
96 #elif defined(_WIN32) && defined(__MINGW32__)
97 #define VP_STAT stat
98 #elif defined(_WIN32)
99 #define VP_STAT _stat
100 #else
101 #define VP_STAT stat
102 #endif
103 namespace
104 {
105 // The following code is not working on iOS since wordexp() is not available
106 // The function is not used on Android
107 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
108 #if (TARGET_OS_IOS == 0) && !defined(__ANDROID__)
109 void replaceAll(std::string &str, const std::string &search, const std::string &replace)
110 {
111  size_t start_pos = 0;
112  while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
113  str.replace(start_pos, search.length(), replace);
114  start_pos += replace.length(); // Handles case where 'replace' is a
115  // substring of 'search'
116  }
117 }
118 #endif
119 #endif
120 } // namespace
121 
122 BEGIN_VISP_NAMESPACE
126  const std::string &vpIoTools::getBuildInformation()
127 {
128  static std::string build_info =
129 #include "version_string.inc"
130  ;
131  return build_info;
132 }
133 
190 {
191 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
192  std::string username;
193  vpIoTools::getUserName(username);
194  return "/tmp/" + username;
195 #elif defined(_WIN32) && !defined(WINRT)
196  // https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-using-a-temporary-file
197  // Gets the temp path env string (no guarantee it's a valid path).
198  TCHAR lpTempPathBuffer[MAX_PATH];
199  DWORD dwRetVal = GetTempPath(MAX_PATH /* length of the buffer */, lpTempPathBuffer /* buffer for path */);
200  if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
201  throw vpIoException(vpIoException::cantGetenv, "Error with GetTempPath() call!");
202  }
203  std::string temp_path(lpTempPathBuffer);
204  if (!temp_path.empty()) {
205  if (temp_path.back() == '\\') {
206  temp_path.resize(temp_path.size() - 1);
207  }
208  }
209  else {
210  temp_path = "C:\temp";
211  try {
212  vpIoTools::makeDirectory(temp_path);
213  }
214  catch (...) {
215  throw(vpException(vpException::fatalError, "Cannot set temp path to %s", temp_path.c_str()));
216  }
217  }
218  return temp_path;
219 #else
220  throw vpIoException(vpException::fatalError, "Not implemented on this platform!");
221 #endif
222 }
223 
237 void vpIoTools::getUserName(std::string &username)
238 {
239  // With MinGW, UNIX and _WIN32 are defined
240 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
241  // Get the user name.
242  char *logname = ::getenv("LOGNAME");
243  if (!logname) {
244  username = "unknown";
245  }
246  else {
247  username = logname;
248  }
249 #elif defined(_WIN32)
250 #if (!defined(WINRT))
251  unsigned int info_buffer_size = 1024;
252  TCHAR *infoBuf = new TCHAR[info_buffer_size];
253  DWORD bufCharCount = (DWORD)info_buffer_size;
254  // Get the user name.
255  if (!GetUserName(infoBuf, &bufCharCount)) {
256  username = "unknown";
257  }
258  else {
259  username = infoBuf;
260  }
261  delete[] infoBuf;
262 #else
263  // Universal platform
264  username = "unknown";
265 #endif
266 #else
267  username = "unknown";
268 #endif
269 }
270 
286 {
287  std::string username;
288  getUserName(username);
289  return username;
290 }
291 
326 std::string vpIoTools::getenv(const std::string &env)
327 {
328 #if defined(_WIN32) && defined(WINRT)
329  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
330  "implemented on Universal Windows Platform"));
331 #else
332  std::string value;
333  // Get the environment variable value.
334  char *v_value = ::getenv(env.c_str());
335  if (!v_value) {
336  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
337  }
338  value = v_value;
339 
340  return value;
341 #endif
342 }
343 
353 void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
354 {
355  if (version.size() == 0) {
356  major = 0;
357  minor = 0;
358  patch = 0;
359  }
360  else {
361  size_t major_pos = version.find('.');
362  std::string major_str = version.substr(0, major_pos);
363  major = static_cast<unsigned>(atoi(major_str.c_str()));
364 
365  if (major_pos != std::string::npos) {
366  size_t minor_pos = version.find('.', major_pos + 1);
367  std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
368  minor = static_cast<unsigned>(atoi(minor_str.c_str()));
369 
370  if (minor_pos != std::string::npos) {
371  std::string patch_str = version.substr(minor_pos + 1);
372  patch = static_cast<unsigned>(atoi(patch_str.c_str()));
373  }
374  else {
375  patch = 0;
376  }
377  }
378  else {
379  minor = 0;
380  patch = 0;
381  }
382  }
383 }
384 
396 bool vpIoTools::checkDirectory(const std::string &dirname)
397 {
398 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
399  struct stat stbuf;
400 #elif defined(_WIN32) && defined(__MINGW32__)
401  struct stat stbuf;
402 #elif defined(_WIN32)
403  struct _stat stbuf;
404 #endif
405 
406  if (dirname.empty()) {
407  return false;
408  }
409 
410  std::string path_dirname = path(dirname);
411 
412  if (VP_STAT(path_dirname.c_str(), &stbuf) != 0) {
413  // Test adding the separator if not already present
414  if (path_dirname.at(path_dirname.size() - 1) != separator) {
415  if (VP_STAT((path_dirname + separator).c_str(), &stbuf) != 0) {
416  return false;
417  }
418  }
419  // Test removing the separator if already present
420  if (path_dirname.at(path_dirname.size() - 1) == separator) {
421  if (VP_STAT((path_dirname.substr(0, path_dirname.size() - 1)).c_str(), &stbuf) != 0) {
422  return false;
423  }
424  }
425  }
426 
427 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
428  if ((stbuf.st_mode & S_IFDIR) == 0)
429 #endif
430  {
431  return false;
432  }
433 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
434  if ((stbuf.st_mode & S_IWUSR) == 0)
435 #elif defined(_WIN32)
436  if ((stbuf.st_mode & S_IWRITE) == 0)
437 #endif
438  {
439  return false;
440  }
441  return true;
442 }
443 
456 bool vpIoTools::checkFifo(const std::string &fifofilename)
457 {
458 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
459  struct stat stbuf;
460 
461  std::string v_filename = path(fifofilename);
462  if (stat(v_filename.c_str(), &stbuf) != 0) {
463  return false;
464  }
465  if ((stbuf.st_mode & S_IFIFO) == 0) {
466  return false;
467  }
468  if ((stbuf.st_mode & S_IRUSR) == 0)
469 
470  {
471  return false;
472  }
473  return true;
474 #elif defined(_WIN32)
475  (void)fifofilename;
476  throw(vpIoException(vpIoException::notImplementedError, "Fifo files are not supported on Windows platforms."));
477 #endif
478 }
479 
480 #ifndef DOXYGEN_SHOULD_SKIP_THIS
481 int vpIoTools::mkdir_p(const std::string &path, int mode)
482 {
483  errno = 0;
484  if (path.size() > PATH_MAX) {
485  errno = ENAMETOOLONG;
486  return -1;
487  }
488 
489  // Iterate over the string
490  std::string cpy_path = path;
491  std::string sub_path;
492  size_t pos = 0;
493  while (pos != std::string::npos) {
494  sub_path += cpy_path.substr(0, pos + 1);
495  // Continue if sub_path = separator
496  bool stop_for_loop = false;
497  if (pos == 0) {
498  cpy_path.erase(0, pos + 1);
499  stop_for_loop = true;
500  }
501  if (!stop_for_loop) {
502 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
503  if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
504 #elif defined(_WIN32)
505  (void)mode; // var not used
506  if (!checkDirectory(sub_path) && _mkdir(sub_path.c_str()) != 0)
507 #endif
508  {
509  if (errno != EEXIST) {
510  return -1;
511  }
512  }
513  cpy_path.erase(0, pos + 1);
514  }
515  pos = cpy_path.find(vpIoTools::separator);
516 }
517 
518  if (!cpy_path.empty()) {
519  sub_path += cpy_path;
520 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
521  if (mkdir(sub_path.c_str(), static_cast<mode_t>(mode)) != 0)
522 #elif defined(_WIN32)
523 
524  if (_mkdir(sub_path.c_str()) != 0)
525 #endif
526  {
527  if (errno != EEXIST) {
528  return -1;
529  }
530  }
531  }
532 
533  return 0;
534 }
535 
536 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
537 
550 void vpIoTools::makeDirectory(const std::string &dirname)
551 {
552 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
553  std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
554  return;
555 #endif
556 
557 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
558  struct stat stbuf;
559 #elif defined(_WIN32) && defined(__MINGW32__)
560  struct stat stbuf;
561 #elif defined(_WIN32)
562  struct _stat stbuf;
563 #endif
564 
565  if (dirname.empty()) {
566  throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
567  }
568 
569  std::string v_dirname = path(dirname);
570 
571 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
572  if (stat(v_dirname.c_str(), &stbuf) != 0)
573 #elif defined(_WIN32) && defined(__MINGW32__)
574  if (stat(v_dirname.c_str(), &stbuf) != 0)
575 #elif defined(_WIN32)
576  if (_stat(v_dirname.c_str(), &stbuf) != 0)
577 #endif
578  {
579  if (vpIoTools::mkdir_p(v_dirname, 0755) != 0) {
580  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
581  }
582 }
583 
584  if (checkDirectory(dirname) == false) {
585  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str()));
586  }
587 }
588 
601 void vpIoTools::makeFifo(const std::string &fifoname)
602 {
603 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
604 
605  // If dirname is a directory, we throw an error
606  if (vpIoTools::checkDirectory(fifoname)) {
608  "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
609  }
610 
611  // If dirname refers to an already existing file, we throw an error
612  else if (vpIoTools::checkFilename(fifoname)) {
613  throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. File already exists.",
614  fifoname.c_str()));
615  // If dirname refers to an already existing fifo, we throw an error
616  }
617  else if (vpIoTools::checkFifo(fifoname)) {
618  throw(vpIoException(vpIoException::invalidDirectoryName, "Unable to create fifo file '%s'. Fifo already exists.",
619  fifoname.c_str()));
620  }
621 
622  else if (mkfifo(fifoname.c_str(), 0666) < 0) {
623  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo file '%s'.", fifoname.c_str()));
624  }
625 #elif defined(_WIN32)
626  (void)fifoname;
627  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create fifo on Windows platforms."));
628 #endif
629 }
630 
631 #if defined(_WIN32) && !defined(WINRT)
632 std::string getUuid()
633 {
634  UUID uuid;
635  if (UuidCreate(&uuid) != RPC_S_OK) {
636  throw(vpIoException(vpIoException::fatalError, "UuidCreate() failed!"));
637  }
638 
639  RPC_CSTR stringUuid;
640  if (UuidToString(&uuid, &stringUuid) != RPC_S_OK) {
641  throw(vpIoException(vpIoException::fatalError, "UuidToString() failed!"));
642  }
643 
644  return reinterpret_cast<char *>(stringUuid);
645 }
646 #endif
647 
708 std::string vpIoTools::makeTempDirectory(const std::string &dirname)
709 {
710 #if defined(WINRT) || !defined(_WIN32) && !(defined(__unix__) || defined(__unix) || \
711  (defined(__APPLE__) && defined(__MACH__))) // not UNIX and not Windows
712  throw(vpIoException(vpIoException::cantCreateDirectory, "makeTempDirectory() is not supported on this platform!"));
713 #endif
714 
715  std::string dirname_cpy = std::string(dirname);
716  std::string correctEnding = "XXXXXX";
717 
718  // If dirname is an unexisting directory, it should end with XXXXXX in order to create a temp directory
719  if (!vpIoTools::checkDirectory(dirname_cpy)) {
720 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
721  // Check if dirname ends with XXXXXX
722  if (dirname_cpy.rfind(correctEnding) == std::string::npos) {
723  if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
724  dirname_cpy = dirname_cpy + "/";
725  }
726  try {
727  vpIoTools::makeDirectory(dirname_cpy);
728  }
729  catch (...) {
730  throw(vpException(vpException::fatalError, "Cannot create temp directory %s", dirname_cpy.c_str()));
731  }
732 
733  dirname_cpy = dirname_cpy + "XXXXXX";
734  }
735 
736 #elif defined(_WIN32) && !defined(WINRT)
737  // Remove XXXXXX
738  dirname_cpy = dirname_cpy.substr(0, dirname_cpy.rfind(correctEnding));
739  // Append UUID
740  dirname_cpy = dirname_cpy + getUuid();
741 #endif
742 
743  }
744  else {
745  // If dirname is an existing directory, we create a temp directory inside
746 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
747  if (dirname_cpy.at(dirname_cpy.length() - 1) != '/') {
748  dirname_cpy = dirname_cpy + "/";
749  }
750  dirname_cpy = dirname_cpy + "XXXXXX";
751 #elif defined(_WIN32) && !defined(WINRT)
752  dirname_cpy = createFilePath(dirname_cpy, getUuid());
753 #endif
754  }
755 
756 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
757  char *dirname_char = new char[dirname_cpy.length() + 1];
758  strcpy(dirname_char, dirname_cpy.c_str());
759 
760  char *computedDirname = mkdtemp(dirname_char);
761 
762  if (!computedDirname) {
763  delete[] dirname_char;
764  throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'.", dirname_cpy.c_str()));
765  }
766 
767  std::string res(computedDirname);
768  delete[] dirname_char;
769  return res;
770 #elif defined(_WIN32) && !defined(WINRT)
771  makeDirectory(dirname_cpy);
772  return dirname_cpy;
773 #endif
774 }
775 
786 bool vpIoTools::checkFilename(const std::string &filename)
787 {
788 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
789  struct stat stbuf;
790 #elif defined(_WIN32)
791  struct _stat stbuf;
792 #endif
793 
794  if (filename.empty()) {
795  return false;
796  }
797 
798  std::string v_filename = path(filename);
799 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
800  if (stat(v_filename.c_str(), &stbuf) != 0)
801 #elif defined(_WIN32)
802  if (_stat(v_filename.c_str(), &stbuf) != 0)
803 #endif
804  {
805  return false;
806 }
807  if ((stbuf.st_mode & S_IFREG) == 0) {
808  return false;
809  }
810 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
811  if ((stbuf.st_mode & S_IRUSR) == 0)
812 #elif defined(_WIN32)
813  if ((stbuf.st_mode & S_IREAD) == 0)
814 #endif
815  {
816  return false;
817  }
818  return true;
819 }
820 
828 bool vpIoTools::copy(const std::string &src, const std::string &dst)
829 {
830  // Check if we have to consider a file or a directory
831  if (vpIoTools::checkFilename(src)) {
832  // --comment: std::cout "copy file: " src " in " dst std::endl;
833 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
834 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
835  // wordexp() is not available
836  std::stringstream cmd;
837  cmd << "cp -p ";
838  cmd << src;
839  cmd << " ";
840  cmd << dst;
841  int ret = system(cmd.str().c_str());
842  if (ret) {
843  } // to avoid a warning
844  // std::cout << cmd << " return value: " << ret << std::endl;
845  return true;
846 #else
847  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
848  dst.c_str()));
849 #endif
850 #elif defined(_WIN32)
851 #if (!defined(WINRT))
852  std::stringstream cmd;
853  cmd << "copy ";
854  cmd << vpIoTools::path(src);
855  cmd << " ";
856  cmd << vpIoTools::path(dst);
857  int ret = system(cmd.str().c_str());
858  if (ret) {
859  }; // to avoid a warning
860  // std::cout << cmd << " return value: " << ret << std::endl;
861  return true;
862 #else
863  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
864  src.c_str(), dst.c_str()));
865 #endif
866 #endif
867  }
868  else if (vpIoTools::checkDirectory(src)) {
869  // --comment: std::cout "copy directory: " src " in " dst
870 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
871 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
872  // wordexp() is not available
873  std::stringstream cmd;
874  cmd << "cp -p ";
875  cmd << src;
876  cmd << " ";
877  cmd << dst;
878  int ret = system(cmd.str().c_str());
879  if (ret) {
880  } // to avoid a warning
881  // std::cout << cmd << " return value: " << ret << std::endl;
882  return true;
883 #else
884  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src.c_str(),
885  dst.c_str()));
886 #endif
887 #elif defined(_WIN32)
888 #if (!defined(WINRT))
889  std::stringstream cmd;
890  cmd << "copy ";
891  cmd << vpIoTools::path(src);
892  cmd << " ";
893  cmd << vpIoTools::path(dst);
894  int ret = system(cmd.str().c_str());
895  if (ret) {
896  }; // to avoid a warning
897  // std::cout << cmd << " return value: " << ret << std::endl;
898  return true;
899 #else
900  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
901  src.c_str(), dst.c_str()));
902 #endif
903 #endif
904  }
905  else {
906  std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
907  return false;
908  }
909  }
910 
921 bool vpIoTools::remove(const std::string &file_or_dir)
922 {
923  // Check if we have to consider a file or a directory
924  if (vpIoTools::checkFilename(file_or_dir)
925 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
926  || vpIoTools::checkFifo(std::string(file_or_dir))
927 #endif
928  ) {
929  if (::remove(file_or_dir.c_str()) != 0) {
930  return false;
931  }
932  else {
933  return true;
934  }
935  }
936  else if (vpIoTools::checkDirectory(file_or_dir)) {
937 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
938 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
939  // wordexp() is not available
940  std::stringstream cmd;
941  cmd << "rm -rf \"";
942  cmd << file_or_dir;
943  cmd << "\"";
944  int ret = system(cmd.str().c_str());
945  if (ret) {
946  } // to avoid a warning
947  // std::cout << cmd << " return value: " << ret << std::endl;
948  return true;
949 #else
950  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform",
951  file_or_dir.c_str()));
952 #endif
953 #elif defined(_WIN32)
954 #if (!defined(WINRT))
955  std::stringstream cmd;
956  cmd << "rmdir /S /Q ";
957  cmd << vpIoTools::path(file_or_dir);
958  cmd << "\"";
959  int ret = system(cmd.str().c_str());
960  if (ret) {
961  }; // to avoid a warning
962  // std::cout << cmd << " return value: " << ret << std::endl;
963  return true;
964 #else
965  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
966  file_or_dir.c_str()));
967 #endif
968 #endif
969  }
970  else {
971  std::cout << "Cannot remove: " << file_or_dir << std::endl;
972  return false;
973  }
974  }
975 
985 bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
986 {
987  if (::rename(oldfilename.c_str(), newfilename.c_str()) != 0) {
988  return false;
989  }
990  else {
991  return true;
992  }
993 }
994 
1005 std::string vpIoTools::path(const std::string &pathname)
1006 {
1007  std::string path(pathname);
1008 
1009 #if defined(_WIN32)
1010  for (unsigned int i = 0; i < path.length(); ++i)
1011  if (path[i] == '/')
1012  path[i] = '\\';
1013 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
1014  unsigned int path_length = path.length();
1015  for (unsigned int i = 0; i < path_length; ++i) {
1016  if (path[i] == '\\') {
1017  path[i] = '/';
1018  }
1019  }
1020 #if TARGET_OS_IOS == 0 // The following code is not working on iOS and android since
1021  // wordexp() is not available
1022 #ifdef __ANDROID__
1023 // Do nothing
1024 #else
1025  wordexp_t exp_result;
1026 
1027  // escape quote character
1028  replaceAll(path, "'", "'\\''");
1029  // add quotes to handle special characters like parentheses and spaces
1030  wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
1031  path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
1032  wordfree(&exp_result);
1033 #endif
1034 #endif
1035 #endif
1036 
1037  return path;
1038 }
1039 
1054 {
1055  std::string data_path;
1056  std::string file_to_test("mbt/cube.cao");
1057  std::string filename;
1058  // Test if VISP_INPUT_IMAGE_PATH env var is set
1059  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
1060  filename = data_path + "/" + file_to_test;
1061  if (vpIoTools::checkFilename(filename)) {
1062  return data_path;
1063  }
1064  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/ViSP-images";
1065  filename = data_path + "/" + file_to_test;
1066  if (vpIoTools::checkFilename(filename)) {
1067  return data_path;
1068  }
1069  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1070  filename = data_path + "/" + file_to_test;
1071  if (vpIoTools::checkFilename(filename)) {
1072  return data_path;
1073  }
1074 
1075 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1076  // Test if visp-images-data package is installed (Ubuntu and Debian)
1077  data_path = "/usr/share/visp-images-data/ViSP-images";
1078  filename = data_path + "/" + file_to_test;
1079  if (vpIoTools::checkFilename(filename)) {
1080  return data_path;
1081  }
1082  data_path = "/usr/share/visp-images-data/visp-images";
1083  filename = data_path + "/" + file_to_test;
1084  if (vpIoTools::checkFilename(filename)) {
1085  return data_path;
1086  }
1087 #endif
1088  data_path = "";
1089  return data_path;
1090 }
1091 
1124 std::string vpIoTools::getFileExtension(const std::string &pathname, bool checkFile)
1125 {
1126  if (checkFile && (vpIoTools::checkDirectory(pathname) || (!vpIoTools::checkFilename(pathname)))) {
1127  return "";
1128  }
1129 
1130 #if defined(_WIN32)
1131  std::string sep = "\\";
1132  std::string altsep = "/";
1133  std::string extsep = ".";
1134 #else
1135  // On Unix, or on the Mac
1136  std::string sep = "/";
1137  std::string altsep = "";
1138  std::string extsep = ".";
1139 #endif
1140 
1141  // Python 2.7.8 module.
1142  // # Split a path in root and extension.
1143  // # The extension is everything starting at the last dot in the last
1144  // # pathname component; the root is everything before that.
1145  // # It is always true that root + ext == p.
1146  //
1147  // # Generic implementation of splitext, to be parametrized with
1148  // # the separators
1149  // def _splitext(p, sep, altsep, extsep):
1150  // """Split the extension from a pathname.
1151  //
1152  // Extension is everything from the last dot to the end, ignoring
1153  // leading dots. Returns "(root, ext)"; ext may be empty."""
1154  //
1155  // sepIndex = p.rfind(sep)
1156  // if altsep:
1157  // altsepIndex = p.rfind(altsep)
1158  // sepIndex = max(sepIndex, altsepIndex)
1159  //
1160  // dotIndex = p.rfind(extsep)
1161  // if dotIndex > sepIndex:
1162  // # skip all leading dots
1163  // filenameIndex = sepIndex + 1
1164  // while filenameIndex < dotIndex:
1165  // if p[filenameIndex] != extsep:
1166  // return p[:dotIndex], p[dotIndex:]
1167  // filenameIndex += 1
1168  //
1169  // return p, ''
1170 
1171  int sepIndex = static_cast<int>(pathname.rfind(sep));
1172  if (!altsep.empty()) {
1173  int altsepIndex = static_cast<int>(pathname.rfind(altsep));
1174  sepIndex = std::max<int>(sepIndex, altsepIndex);
1175  }
1176 
1177  size_t dotIndex = pathname.rfind(extsep);
1178  if (dotIndex != std::string::npos) {
1179  // The extsep character exists
1180  size_t npos = std::string::npos;
1181  if (((sepIndex != static_cast<int>(npos)) && (static_cast<int>(dotIndex) > sepIndex)) ||
1182  (sepIndex == static_cast<int>(npos))) {
1183  if (sepIndex == static_cast<int>(npos)) {
1184  sepIndex = 0;
1185  }
1186  size_t filenameIndex = static_cast<size_t>(sepIndex) + static_cast<size_t>(1);
1187 
1188  while (filenameIndex < dotIndex) {
1189  if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1190  return pathname.substr(dotIndex);
1191  }
1192  filenameIndex++;
1193  }
1194  }
1195  }
1196 
1197  return "";
1198 }
1199 
1205 std::string vpIoTools::getName(const std::string &pathname)
1206 {
1207  if (pathname.size() > 0) {
1208  std::string convertedPathname = vpIoTools::path(pathname);
1209 
1210  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1211  if (index != std::string::npos) {
1212  return convertedPathname.substr(index + 1);
1213  }
1214 
1215  return convertedPathname;
1216  }
1217 
1218  return "";
1219 }
1220 
1227 std::string vpIoTools::getNameWE(const std::string &pathname)
1228 {
1229  std::string name = vpIoTools::getName(pathname);
1230  size_t found = name.find_last_of(".");
1231  std::string name_we = name.substr(0, found);
1232  return name_we;
1233 }
1234 
1272 long vpIoTools::getIndex(const std::string &filename, const std::string &format)
1273 {
1274  size_t indexBegin = format.find_last_of('%');
1275  size_t indexEnd = format.find_first_of('d', indexBegin);
1276  size_t suffixLength = format.length() - indexEnd - 1;
1277  // Extracting index
1278  if (filename.length() <= (suffixLength + indexBegin)) {
1279  return -1;
1280  }
1281  size_t indexLength = filename.length() - suffixLength - indexBegin;
1282  std::string indexSubstr = filename.substr(indexBegin, indexLength);
1283  std::istringstream ss(indexSubstr);
1284  long index = 0;
1285  ss >> index;
1286  if (ss.fail() || (index < 0) || (!ss.eof())) {
1287  return -1;
1288  }
1289 
1290  // Checking that format with inserted index equals filename
1291  char nameByFormat[FILENAME_MAX];
1292  snprintf(nameByFormat, FILENAME_MAX, format.c_str(), index);
1293  if (std::string(nameByFormat) != filename) {
1294  return -1;
1295  }
1296  return index;
1297 }
1298 
1314 std::string vpIoTools::getParent(const std::string &pathname)
1315 {
1316  if (pathname.size() > 0) {
1317  std::string convertedPathname = vpIoTools::path(pathname);
1318 
1319  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1320  if (index != std::string::npos) {
1321  return convertedPathname.substr(0, index);
1322  }
1323 
1324  return ".";
1325  }
1326  else {
1327  return "";
1328  }
1329 }
1330 
1339 std::string vpIoTools::toLowerCase(const std::string &input)
1340 {
1341  std::string out;
1342 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1343  const std::string::const_iterator it_end = input.cend();
1344  for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1345 #else
1346  const std::string::const_iterator it_end = input.end();
1347  for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1348 #endif
1349  out += std::tolower(*it);
1350  }
1351  return out;
1352  }
1353 
1362 std::string vpIoTools::toUpperCase(const std::string &input)
1363 {
1364  std::string out;
1365 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
1366  const std::string::const_iterator it_end = input.cend();
1367  for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) {
1368 #else
1369  const std::string::const_iterator it_end = input.end();
1370  for (std::string::const_iterator it = input.begin(); it != it_end; ++it) {
1371 #endif
1372  out += std::toupper(*it);
1373  }
1374  return out;
1375  }
1376 
1385 std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1386 {
1387 
1388 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1389  std::string real_path_str = pathname;
1390  char *real_path = realpath(pathname.c_str(), nullptr);
1391 
1392  if (real_path) {
1393  real_path_str = real_path;
1394  free(real_path);
1395  }
1396  return real_path_str;
1397 #elif defined(_WIN32)
1398 #if (!defined(WINRT))
1399  std::string real_path_str = pathname;
1400  DWORD retval = 0;
1401  TCHAR buffer[4096] = TEXT("");
1402 
1403  retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1404  if (retval != 0) {
1405  real_path_str = buffer;
1406  }
1407  return real_path_str;
1408 #else
1410  "Cannot get absolute path of %s: not implemented on "
1411  "Universal Windows Platform",
1412  pathname.c_str()));
1413 #endif
1414 #endif
1415 }
1416 
1427 std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1428 {
1429  if ((child.size() == 0) && (parent.size() == 0)) {
1430  return "";
1431  }
1432 
1433  if (child.size() == 0) {
1434  return vpIoTools::path(parent);
1435  }
1436 
1437  if (parent.size() == 0) {
1438  return vpIoTools::path(child);
1439  }
1440 
1441  std::string convertedParent = vpIoTools::path(parent);
1442  std::string convertedChild = vpIoTools::path(child);
1443 
1444  std::stringstream ss;
1445  ss << vpIoTools::separator;
1446  std::string stringSeparator;
1447  ss >> stringSeparator;
1448 
1449  std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1450  std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1451 
1452  if (lastConvertedParentChar == stringSeparator) {
1453  convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1454  }
1455 
1456  if (firstConvertedChildChar == stringSeparator) {
1457  convertedChild = convertedChild.substr(1);
1458  }
1459 
1460  return std::string(convertedParent + vpIoTools::separator + convertedChild);
1461 }
1462 
1468 bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1469 {
1470  // # Inspired by the Python 2.7.8 module.
1471  // # Return whether a path is absolute.
1472  // # Trivial in Posix, harder on the Mac or MS-DOS.
1473  // # For DOS it is absolute if it starts with a slash or backslash (current
1474  // # volume), or if a pathname after the volume letter and colon / UNC
1475  // resource # starts with a slash or backslash.
1476  //
1477  // def isabs(s):
1478  // """Test whether a path is absolute"""
1479  // s = splitdrive(s)[1]
1480  // return s != '' and s[:1] in '/\\'
1481  std::string path = splitDrive(pathname).second;
1482  return (path.size() > 0) && ((path.substr(0, 1) == "/") || (path.substr(0, 1) == "\\"));
1483 }
1484 
1492 bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1493 {
1494  // Normalize path
1495  std::string path1_normalize = vpIoTools::path(pathname1);
1496  std::string path2_normalize = vpIoTools::path(pathname2);
1497 
1498  // Get absolute path
1499  path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1500  path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1501 
1502  return (path1_normalize == path2_normalize);
1503 }
1504 
1512 std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1513 {
1514  // # Split a path in a drive specification (a drive letter followed by a
1515  // # colon) and the path specification.
1516  // # It is always true that drivespec + pathspec == p
1517  // def splitdrive(p):
1518  // """Split a pathname into drive/UNC sharepoint and relative path
1519  // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1520  // empty.
1521  //
1522  // If you assign
1523  // result = splitdrive(p)
1524  // It is always true that:
1525  // result[0] + result[1] == p
1526  //
1527  // If the path contained a drive letter, drive_or_unc will contain
1528  // everything up to and including the colon. e.g. splitdrive("c:/dir")
1529  // returns ("c:", "/dir")
1530  //
1531  // If the path contained a UNC path, the drive_or_unc will contain the host
1532  // name and share up to but not including the fourth directory separator
1533  // character. e.g. splitdrive("//host/computer/dir") returns
1534  // ("//host/computer", "/dir")
1535  //
1536  // Paths cannot contain both a drive letter and a UNC path.
1537  //
1538  // """
1539  // if len(p) > 1:
1540  // normp = p.replace(altsep, sep)
1541  // if (normp[0:2] == sep*2) and (normp[2] != sep):
1542  // # is a UNC path:
1543  // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1544  // # \\machine\mountpoint\directory\etc\...
1545  // # directory ^^^^^^^^^^^^^^^
1546  // index = normp.find(sep, 2)
1547  // if index == -1:
1548  // return '', p
1549  // index2 = normp.find(sep, index + 1)
1550  // # a UNC path can't have two slashes in a row
1551  // # (after the initial two)
1552  // if index2 == index + 1:
1553  // return '', p
1554  // if index2 == -1:
1555  // index2 = len(p)
1556  // return p[:index2], p[index2:]
1557  // if normp[1] == ':':
1558  // return p[:2], p[2:]
1559  // return '', p
1560 
1561  // On Unix, the drive is always empty.
1562  // On the Mac, the drive is always empty (don't use the volume name -- it
1563  // doesn't have the same syntactic and semantic oddities as DOS drive
1564  // letters, such as there being a separate current directory per drive).
1565 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1566  return std::pair<std::string, std::string>("", pathname);
1567 #else
1568  const std::string sep = "\\";
1569  const std::string sepsep = "\\\\";
1570  const std::string altsep = "/";
1571 
1572  if (pathname.size() > 1) {
1573  std::string normPathname = pathname;
1574  std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1575 
1576  if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1577  // is a UNC path:
1578  // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1579  // \\machine\mountpoint\directory\etc\...
1580  // directory ^^^^^^^^^^^^^^^
1581  size_t index = normPathname.find(sep, 2);
1582  if (index == std::string::npos) {
1583  return std::pair<std::string, std::string>("", pathname);
1584  }
1585 
1586  size_t index2 = normPathname.find(sep, index + 1);
1587  // # a UNC path can't have two slashes in a row
1588  // # (after the initial two)
1589  if (index2 == index + 1) {
1590  return std::pair<std::string, std::string>("", pathname);
1591  }
1592 
1593  if (index2 == std::string::npos) {
1594  index2 = pathname.size();
1595  }
1596 
1597  return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1598  }
1599 
1600  if (normPathname[1] == ':') {
1601  return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1602  }
1603  }
1604 
1605  return std::pair<std::string, std::string>("", pathname);
1606 #endif
1607 }
1608 
1661 std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1662 {
1663  size_t startIndex = 0;
1664 
1665  std::string chainToSplit = chain;
1666  std::vector<std::string> subChain;
1667  size_t sepIndex = chainToSplit.find(sep);
1668 
1669  while (sepIndex != std::string::npos) {
1670  std::string sub = chainToSplit.substr(startIndex, sepIndex);
1671  if (!sub.empty()) {
1672  subChain.push_back(sub);
1673  }
1674  chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1675 
1676  sepIndex = chainToSplit.find(sep);
1677  }
1678  if (!chainToSplit.empty()) {
1679  subChain.push_back(chainToSplit);
1680  }
1681 
1682  return subChain;
1683 }
1684 
1692 std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1693 {
1694 
1695  if (!checkDirectory(pathname)) {
1696  throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1697  }
1698  std::string dirName = path(pathname);
1699 
1700 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1701 
1702  std::vector<std::string> files;
1703  struct dirent **list = nullptr;
1704  int filesCount = scandir(dirName.c_str(), &list, nullptr, nullptr);
1705  if (filesCount == -1) {
1706  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1707  }
1708  for (int i = 0; i < filesCount; ++i) {
1709  std::string fileName = list[i]->d_name;
1710  if ((fileName != ".") && (fileName != "..")) {
1711  files.push_back(fileName);
1712  }
1713  free(list[i]);
1714  }
1715  free(list);
1716  std::sort(files.begin(), files.end());
1717  return files;
1718 
1719 #elif defined(_WIN32)
1720 #if (!defined(WINRT))
1721 
1722  std::vector<std::string> files;
1723  std::string fileMask = dirName;
1724  fileMask.append("\\*");
1725  WIN32_FIND_DATA FindFileData;
1726  HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1727  // Directory is empty
1728  if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1729  return files;
1730  }
1731  if (hFind == INVALID_HANDLE_VALUE) {
1732  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1733  }
1734  do {
1735  std::string fileName = FindFileData.cFileName;
1736  if (fileName != "." && fileName != "..") {
1737  files.push_back(fileName);
1738  }
1739  } while (FindNextFile(hFind, &FindFileData));
1740  FindClose(hFind);
1741  std::sort(files.begin(), files.end());
1742  return files;
1743 
1744 #else
1746  "Cannot read files of directory %s: not implemented on "
1747  "Universal Windows Platform",
1748  dirName.c_str()));
1749 #endif
1750 #endif
1751 }
1752 
1753 END_VISP_NAMESPACE
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ notImplementedError
Not implemented.
Definition: vpException.h:69
@ fatalError
Fatal error.
Definition: vpException.h:72
Error that can be emitted by the vpIoTools class and its derivatives.
Definition: vpIoException.h:55
@ invalidDirectoryName
Directory name is invalid.
Definition: vpIoException.h:63
@ cantCreateDirectory
Unable to create a directory.
Definition: vpIoException.h:64
@ cantGetenv
Cannot get environment variable value.
Definition: vpIoException.h:66
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
Definition: vpIoTools.cpp:353
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1053
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1661
static std::string path(const std::string &pathname)
Definition: vpIoTools.cpp:1005
static std::string getAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1385
static std::string toLowerCase(const std::string &input)
Return a lower-case version of the string input . Numbers and special characters stay the same.
Definition: vpIoTools.cpp:1339
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:786
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
Definition: vpIoTools.cpp:1512
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
Definition: vpIoTools.cpp:1492
static std::string getTempPath()
Definition: vpIoTools.cpp:189
static bool isAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1468
static bool copy(const std::string &src, const std::string &dst)
Definition: vpIoTools.cpp:828
static bool checkDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:396
static bool rename(const std::string &oldfilename, const std::string &newfilename)
Definition: vpIoTools.cpp:985
static long getIndex(const std::string &filename, const std::string &format)
Definition: vpIoTools.cpp:1272
static std::string getUserName()
Definition: vpIoTools.cpp:285
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1427
static std::string getenv(const std::string &env)
Definition: vpIoTools.cpp:326
static std::string getFileExtension(const std::string &pathname, bool checkFile=false)
Definition: vpIoTools.cpp:1124
static std::vector< std::string > getDirFiles(const std::string &dirname)
Definition: vpIoTools.cpp:1692
static void makeDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:550
static bool remove(const std::string &filename)
Definition: vpIoTools.cpp:921
static const std::string & getBuildInformation()
Definition: vpIoTools.cpp:126
static std::string getNameWE(const std::string &pathname)
Definition: vpIoTools.cpp:1227
static std::string makeTempDirectory(const std::string &dirname)
Definition: vpIoTools.cpp:708
static bool checkFifo(const std::string &filename)
Definition: vpIoTools.cpp:456
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1314
static std::string getName(const std::string &pathname)
Definition: vpIoTools.cpp:1205
static std::string toUpperCase(const std::string &input)
Return a upper-case version of the string input . Numbers and special characters stay the same.
Definition: vpIoTools.cpp:1362
static const char separator
Definition: vpIoTools.h:532
static void makeFifo(const std::string &dirname)
Definition: vpIoTools.cpp:601