2
0

fileacc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_strings.h"
  17. #include "fspr_arch_file_io.h"
  18. /* A file to put ALL of the accessor functions for fspr_file_t types. */
  19. APR_DECLARE(fspr_status_t) fspr_file_name_get(const char **fname,
  20. fspr_file_t *thefile)
  21. {
  22. *fname = thefile->fname;
  23. return APR_SUCCESS;
  24. }
  25. APR_DECLARE(fspr_int32_t) fspr_file_flags_get(fspr_file_t *f)
  26. {
  27. return f->flags;
  28. }
  29. #if !defined(OS2) && !defined(WIN32)
  30. mode_t fspr_unix_perms2mode(fspr_fileperms_t perms)
  31. {
  32. mode_t mode = 0;
  33. if (perms & APR_USETID)
  34. mode |= S_ISUID;
  35. if (perms & APR_UREAD)
  36. mode |= S_IRUSR;
  37. if (perms & APR_UWRITE)
  38. mode |= S_IWUSR;
  39. if (perms & APR_UEXECUTE)
  40. mode |= S_IXUSR;
  41. if (perms & APR_GSETID)
  42. mode |= S_ISGID;
  43. if (perms & APR_GREAD)
  44. mode |= S_IRGRP;
  45. if (perms & APR_GWRITE)
  46. mode |= S_IWGRP;
  47. if (perms & APR_GEXECUTE)
  48. mode |= S_IXGRP;
  49. #ifdef S_ISVTX
  50. if (perms & APR_WSTICKY)
  51. mode |= S_ISVTX;
  52. #endif
  53. if (perms & APR_WREAD)
  54. mode |= S_IROTH;
  55. if (perms & APR_WWRITE)
  56. mode |= S_IWOTH;
  57. if (perms & APR_WEXECUTE)
  58. mode |= S_IXOTH;
  59. return mode;
  60. }
  61. fspr_fileperms_t fspr_unix_mode2perms(mode_t mode)
  62. {
  63. fspr_fileperms_t perms = 0;
  64. if (mode & S_ISUID)
  65. perms |= APR_USETID;
  66. if (mode & S_IRUSR)
  67. perms |= APR_UREAD;
  68. if (mode & S_IWUSR)
  69. perms |= APR_UWRITE;
  70. if (mode & S_IXUSR)
  71. perms |= APR_UEXECUTE;
  72. if (mode & S_ISGID)
  73. perms |= APR_GSETID;
  74. if (mode & S_IRGRP)
  75. perms |= APR_GREAD;
  76. if (mode & S_IWGRP)
  77. perms |= APR_GWRITE;
  78. if (mode & S_IXGRP)
  79. perms |= APR_GEXECUTE;
  80. #ifdef S_ISVTX
  81. if (mode & S_ISVTX)
  82. perms |= APR_WSTICKY;
  83. #endif
  84. if (mode & S_IROTH)
  85. perms |= APR_WREAD;
  86. if (mode & S_IWOTH)
  87. perms |= APR_WWRITE;
  88. if (mode & S_IXOTH)
  89. perms |= APR_WEXECUTE;
  90. return perms;
  91. }
  92. #endif
  93. APR_DECLARE(fspr_status_t) fspr_file_data_get(void **data, const char *key,
  94. fspr_file_t *file)
  95. {
  96. return fspr_pool_userdata_get(data, key, file->pool);
  97. }
  98. APR_DECLARE(fspr_status_t) fspr_file_data_set(fspr_file_t *file, void *data,
  99. const char *key,
  100. fspr_status_t (*cleanup)(void *))
  101. {
  102. return fspr_pool_userdata_set(data, key, cleanup, file->pool);
  103. }