2
0

filesys.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. fspr_status_t filepath_root_case(char **rootpath, char *root, fspr_pool_t *p)
  20. {
  21. /* See the Windows code to figure out what to do here.
  22. It probably checks to make sure that the root exists
  23. and case it correctly according to the file system.
  24. */
  25. *rootpath = fspr_pstrdup(p, root);
  26. return APR_SUCCESS;
  27. }
  28. fspr_status_t filepath_has_drive(const char *rootpath, int only, fspr_pool_t *p)
  29. {
  30. char *s;
  31. if (rootpath) {
  32. s = strchr (rootpath, ':');
  33. if (only)
  34. /* Test if the path only has a drive/volume and nothing else
  35. */
  36. return (s && (s != rootpath) && !s[1]);
  37. else
  38. /* Test if the path includes a drive/volume
  39. */
  40. return (s && (s != rootpath));
  41. }
  42. return 0;
  43. }
  44. fspr_status_t filepath_compare_drive(const char *path1, const char *path2, fspr_pool_t *p)
  45. {
  46. char *s1, *s2;
  47. if (path1 && path2) {
  48. s1 = strchr (path1, ':');
  49. s2 = strchr (path2, ':');
  50. /* Make sure that they both have a drive/volume delimiter
  51. and are the same size. Then see if they match.
  52. */
  53. if (s1 && s2 && ((s1-path1) == (s2-path2))) {
  54. return strnicmp (s1, s2, s1-path1);
  55. }
  56. }
  57. return -1;
  58. }
  59. APR_DECLARE(fspr_status_t) fspr_filepath_get(char **rootpath, fspr_int32_t flags,
  60. fspr_pool_t *p)
  61. {
  62. char path[APR_PATH_MAX];
  63. char *ptr;
  64. /* use getcwdpath to make sure that we get the volume name*/
  65. if (!getcwdpath(path, NULL, 0)) {
  66. if (errno == ERANGE)
  67. return APR_ENAMETOOLONG;
  68. else
  69. return errno;
  70. }
  71. /* Strip off the server name if there is one*/
  72. ptr = strpbrk(path, "\\/:");
  73. if (!ptr) {
  74. return APR_ENOENT;
  75. }
  76. if (*ptr == ':') {
  77. ptr = path;
  78. }
  79. *rootpath = fspr_pstrdup(p, ptr);
  80. if (!(flags & APR_FILEPATH_NATIVE)) {
  81. for (ptr = *rootpath; *ptr; ++ptr) {
  82. if (*ptr == '\\')
  83. *ptr = '/';
  84. }
  85. }
  86. return APR_SUCCESS;
  87. }
  88. APR_DECLARE(fspr_status_t) fspr_filepath_set(const char *rootpath,
  89. fspr_pool_t *p)
  90. {
  91. if (chdir2(rootpath) != 0)
  92. return errno;
  93. return APR_SUCCESS;
  94. }