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 17#include "apr_strings.h" 18#include "apr_arch_file_io.h" 19 20/* A file to put ALL of the accessor functions for apr_file_t types. */ 21 22APR_DECLARE(apr_status_t) apr_file_name_get(const char **fname, 23 apr_file_t *thefile) 24{ 25 *fname = thefile->fname; 26 return APR_SUCCESS; 27} 28 29APR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f) 30{ 31 return f->flags; 32} 33 34#if !defined(OS2) && !defined(WIN32) 35mode_t apr_unix_perms2mode(apr_fileperms_t perms) 36{ 37 mode_t mode = 0; 38 39 if (perms & APR_USETID) 40 mode |= S_ISUID; 41 if (perms & APR_UREAD) 42 mode |= S_IRUSR; 43 if (perms & APR_UWRITE) 44 mode |= S_IWUSR; 45 if (perms & APR_UEXECUTE) 46 mode |= S_IXUSR; 47 48 if (perms & APR_GSETID) 49 mode |= S_ISGID; 50 if (perms & APR_GREAD) 51 mode |= S_IRGRP; 52 if (perms & APR_GWRITE) 53 mode |= S_IWGRP; 54 if (perms & APR_GEXECUTE) 55 mode |= S_IXGRP; 56 57#ifdef S_ISVTX 58 if (perms & APR_WSTICKY) 59 mode |= S_ISVTX; 60#endif 61 if (perms & APR_WREAD) 62 mode |= S_IROTH; 63 if (perms & APR_WWRITE) 64 mode |= S_IWOTH; 65 if (perms & APR_WEXECUTE) 66 mode |= S_IXOTH; 67 68 return mode; 69} 70 71apr_fileperms_t apr_unix_mode2perms(mode_t mode) 72{ 73 apr_fileperms_t perms = 0; 74 75 if (mode & S_ISUID) 76 perms |= APR_USETID; 77 if (mode & S_IRUSR) 78 perms |= APR_UREAD; 79 if (mode & S_IWUSR) 80 perms |= APR_UWRITE; 81 if (mode & S_IXUSR) 82 perms |= APR_UEXECUTE; 83 84 if (mode & S_ISGID) 85 perms |= APR_GSETID; 86 if (mode & S_IRGRP) 87 perms |= APR_GREAD; 88 if (mode & S_IWGRP) 89 perms |= APR_GWRITE; 90 if (mode & S_IXGRP) 91 perms |= APR_GEXECUTE; 92 93#ifdef S_ISVTX 94 if (mode & S_ISVTX) 95 perms |= APR_WSTICKY; 96#endif 97 if (mode & S_IROTH) 98 perms |= APR_WREAD; 99 if (mode & S_IWOTH) 100 perms |= APR_WWRITE; 101 if (mode & S_IXOTH) 102 perms |= APR_WEXECUTE; 103 104 return perms; 105} 106#endif 107 108APR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key, 109 apr_file_t *file) 110{ 111 return apr_pool_userdata_get(data, key, file->pool); 112} 113 114APR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data, 115 const char *key, 116 apr_status_t (*cleanup)(void *)) 117{ 118 return apr_pool_userdata_set(data, key, cleanup, file->pool); 119} 120