Path_VMS.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Path_VMS.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Path_VMS.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Filesystem
  8. // Module: Path
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Path_VMS.h"
  16. #include "Poco/Environment_VMS.h"
  17. #include <unistd.h>
  18. #include <descrip.h>
  19. #include <dvsdef.h>
  20. #include <dcdef.h>
  21. #include <iledef.h>
  22. #include <gen64def.h>
  23. #include <starlet.h>
  24. namespace Poco {
  25. std::string PathImpl::currentImpl()
  26. {
  27. std::string path;
  28. char cwd[PATH_MAX];
  29. if (getcwd(cwd, sizeof(cwd)))
  30. path = cwd;
  31. else
  32. throw SystemException("cannot get current directory");
  33. return path;
  34. }
  35. std::string PathImpl::homeImpl()
  36. {
  37. return EnvironmentImpl::trnlnm("SYS$LOGIN");
  38. }
  39. std::string PathImpl::tempImpl()
  40. {
  41. std::string result = EnvironmentImpl::trnlnm("SYS$SCRATCH");
  42. if (result.empty())
  43. return homeImpl();
  44. else
  45. return result;
  46. }
  47. std::string PathImpl::nullImpl()
  48. {
  49. return "NLA0:";
  50. }
  51. std::string PathImpl::expandImpl(const std::string& path)
  52. {
  53. std::string result = path;
  54. std::string::const_iterator it = result.begin();
  55. std::string::const_iterator end = result.end();
  56. int n = 0;
  57. while (it != end && n < 10)
  58. {
  59. std::string logical;
  60. while (it != end && *it != ':') logical += *it++;
  61. if (it != end)
  62. {
  63. ++it;
  64. if (it != end && *it == ':') return result;
  65. std::string val = EnvironmentImpl::trnlnm(logical);
  66. if (val.empty())
  67. return result;
  68. else
  69. result = val + std::string(it, end);
  70. it = result.begin();
  71. end = result.end();
  72. ++n;
  73. }
  74. }
  75. return result;
  76. }
  77. void PathImpl::listRootsImpl(std::vector<std::string>& roots)
  78. {
  79. char device[64];
  80. $DESCRIPTOR(deviceDsc, device);
  81. int clss = DC$_DISK;
  82. ILE3 items[2];
  83. items[0].ile3$w_code = DVS$_DEVCLASS;
  84. items[0].ile3$w_length = sizeof(clss);
  85. items[0].ile3$ps_bufaddr = &clss;
  86. items[0].ile3$ps_retlen_addr = 0;
  87. items[1].ile3$w_code = 0;
  88. items[1].ile3$w_length = 0;
  89. int stat;
  90. GENERIC_64 context;
  91. context.gen64$q_quadword = 0;
  92. do
  93. {
  94. unsigned short length;
  95. stat = sys$device_scan(&deviceDsc, &length, 0, &items, &context);
  96. if (stat == SS$_NORMAL)
  97. roots.push_back(std::string(device, length));
  98. }
  99. while (stat == SS$_NORMAL);
  100. }
  101. } // namespace Poco