filesys.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "fspr.h"
  17. #include "fspr_arch_file_io.h"
  18. #include "fspr_strings.h"
  19. #include "fspr_lib.h"
  20. #include <ctype.h>
  21. /* OS/2 Exceptions:
  22. *
  23. * Note that trailing spaces and trailing periods are never recorded
  24. * in the file system.
  25. *
  26. * Leading spaces and periods are accepted, however.
  27. * The * ? < > codes all have wildcard side effects
  28. * The " / \ : are exclusively component separator tokens
  29. * The system doesn't accept | for any (known) purpose
  30. * Oddly, \x7f _is_ acceptable ;)
  31. */
  32. const char c_is_fnchar[256] =
  33. {/* Reject all ctrl codes... */
  34. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  35. /* " * / : < > ? */
  36. 1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,0, 1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,
  37. /* \ */
  38. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
  39. /* | */
  40. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
  41. /* High bit codes are accepted */
  42. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  43. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  44. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  45. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  46. };
  47. #define IS_SLASH(c) (c == '/' || c == '\\')
  48. fspr_status_t filepath_root_test(char *path, fspr_pool_t *p)
  49. {
  50. char drive = fspr_toupper(path[0]);
  51. if (drive >= 'A' && drive <= 'Z' && path[1] == ':' && IS_SLASH(path[2]))
  52. return APR_SUCCESS;
  53. return APR_EBADPATH;
  54. }
  55. fspr_status_t filepath_drive_get(char **rootpath, char drive,
  56. fspr_int32_t flags, fspr_pool_t *p)
  57. {
  58. char path[APR_PATH_MAX];
  59. char *pos;
  60. ULONG rc;
  61. ULONG bufsize = sizeof(path) - 3;
  62. path[0] = drive;
  63. path[1] = ':';
  64. path[2] = '/';
  65. rc = DosQueryCurrentDir(fspr_toupper(drive) - 'A', path+3, &bufsize);
  66. if (rc) {
  67. return APR_FROM_OS_ERROR(rc);
  68. }
  69. if (!(flags & APR_FILEPATH_NATIVE)) {
  70. for (pos=path; *pos; pos++) {
  71. if (*pos == '\\')
  72. *pos = '/';
  73. }
  74. }
  75. *rootpath = fspr_pstrdup(p, path);
  76. return APR_SUCCESS;
  77. }
  78. fspr_status_t filepath_root_case(char **rootpath, char *root, fspr_pool_t *p)
  79. {
  80. if (root[0] && fspr_islower(root[0]) && root[1] == ':') {
  81. *rootpath = fspr_pstrdup(p, root);
  82. (*rootpath)[0] = fspr_toupper((*rootpath)[0]);
  83. }
  84. else {
  85. *rootpath = root;
  86. }
  87. return APR_SUCCESS;
  88. }
  89. APR_DECLARE(fspr_status_t) fspr_filepath_get(char **defpath, fspr_int32_t flags,
  90. fspr_pool_t *p)
  91. {
  92. char path[APR_PATH_MAX];
  93. ULONG drive;
  94. ULONG drivemap;
  95. ULONG rv, pathlen = sizeof(path) - 3;
  96. char *pos;
  97. DosQueryCurrentDisk(&drive, &drivemap);
  98. path[0] = '@' + drive;
  99. strcpy(path+1, ":\\");
  100. rv = DosQueryCurrentDir(drive, path+3, &pathlen);
  101. *defpath = fspr_pstrdup(p, path);
  102. if (!(flags & APR_FILEPATH_NATIVE)) {
  103. for (pos=*defpath; *pos; pos++) {
  104. if (*pos == '\\')
  105. *pos = '/';
  106. }
  107. }
  108. return APR_SUCCESS;
  109. }
  110. APR_DECLARE(fspr_status_t) fspr_filepath_set(const char *path, fspr_pool_t *p)
  111. {
  112. ULONG rv = 0;
  113. if (path[1] == ':')
  114. rv = DosSetDefaultDisk(fspr_toupper(path[0]) - '@');
  115. if (rv == 0)
  116. rv = DosSetCurrentDir(path);
  117. return APR_FROM_OS_ERROR(rv);
  118. }