fileacc.c revision 285830
1234353Sdim/* Licensed to the Apache Software Foundation (ASF) under one or more 2198090Srdivacky * contributor license agreements. See the NOTICE file distributed with 3198090Srdivacky * this work for additional information regarding copyright ownership. 4198090Srdivacky * The ASF licenses this file to You under the Apache License, Version 2.0 5198090Srdivacky * (the "License"); you may not use this file except in compliance with 6198090Srdivacky * the License. You may obtain a copy of the License at 7198090Srdivacky * 8198090Srdivacky * http://www.apache.org/licenses/LICENSE-2.0 9198090Srdivacky * 10198090Srdivacky * Unless required by applicable law or agreed to in writing, software 11198090Srdivacky * distributed under the License is distributed on an "AS IS" BASIS, 12198090Srdivacky * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13198090Srdivacky * See the License for the specific language governing permissions and 14198090Srdivacky * limitations under the License. 15198090Srdivacky */ 16198090Srdivacky 17198090Srdivacky#include "apr_strings.h" 18198090Srdivacky#include "apr_arch_file_io.h" 19198090Srdivacky 20224145Sdim/* A file to put ALL of the accessor functions for apr_file_t types. */ 21224145Sdim 22224145SdimAPR_DECLARE(apr_status_t) apr_file_name_get(const char **fname, 23198090Srdivacky apr_file_t *thefile) 24198090Srdivacky{ 25198090Srdivacky *fname = thefile->fname; 26198090Srdivacky return APR_SUCCESS; 27198090Srdivacky} 28198090Srdivacky 29198090SrdivackyAPR_DECLARE(apr_int32_t) apr_file_flags_get(apr_file_t *f) 30198090Srdivacky{ 31198090Srdivacky return f->flags; 32198090Srdivacky} 33198090Srdivacky 34198090Srdivacky#if !defined(OS2) && !defined(WIN32) 35198090Srdivackymode_t apr_unix_perms2mode(apr_fileperms_t perms) 36218893Sdim{ 37218893Sdim mode_t mode = 0; 38234353Sdim 39218893Sdim if (perms & APR_USETID) 40218893Sdim mode |= S_ISUID; 41218893Sdim if (perms & APR_UREAD) 42218893Sdim mode |= S_IRUSR; 43218893Sdim if (perms & APR_UWRITE) 44218893Sdim mode |= S_IWUSR; 45218893Sdim if (perms & APR_UEXECUTE) 46234353Sdim mode |= S_IXUSR; 47234353Sdim 48218893Sdim if (perms & APR_GSETID) 49218893Sdim mode |= S_ISGID; 50218893Sdim if (perms & APR_GREAD) 51218893Sdim mode |= S_IRGRP; 52218893Sdim if (perms & APR_GWRITE) 53234353Sdim mode |= S_IWGRP; 54218893Sdim if (perms & APR_GEXECUTE) 55218893Sdim mode |= S_IXGRP; 56218893Sdim 57234353Sdim#ifdef S_ISVTX 58234353Sdim if (perms & APR_WSTICKY) 59218893Sdim mode |= S_ISVTX; 60218893Sdim#endif 61218893Sdim if (perms & APR_WREAD) 62218893Sdim mode |= S_IROTH; 63218893Sdim if (perms & APR_WWRITE) 64234353Sdim mode |= S_IWOTH; 65218893Sdim if (perms & APR_WEXECUTE) 66218893Sdim mode |= S_IXOTH; 67218893Sdim 68218893Sdim return mode; 69218893Sdim} 70218893Sdim 71218893Sdimapr_fileperms_t apr_unix_mode2perms(mode_t mode) 72218893Sdim{ 73218893Sdim apr_fileperms_t perms = 0; 74218893Sdim 75212904Sdim if (mode & S_ISUID) 76198090Srdivacky perms |= APR_USETID; 77198090Srdivacky if (mode & S_IRUSR) 78198090Srdivacky perms |= APR_UREAD; 79198090Srdivacky if (mode & S_IWUSR) 80198090Srdivacky perms |= APR_UWRITE; 81198090Srdivacky if (mode & S_IXUSR) 82198090Srdivacky perms |= APR_UEXECUTE; 83212904Sdim 84212904Sdim if (mode & S_ISGID) 85212904Sdim perms |= APR_GSETID; 86212904Sdim if (mode & S_IRGRP) 87212904Sdim perms |= APR_GREAD; 88198090Srdivacky if (mode & S_IWGRP) 89198090Srdivacky perms |= APR_GWRITE; 90198090Srdivacky if (mode & S_IXGRP) 91198090Srdivacky perms |= APR_GEXECUTE; 92198090Srdivacky 93198090Srdivacky#ifdef S_ISVTX 94198090Srdivacky if (mode & S_ISVTX) 95198090Srdivacky perms |= APR_WSTICKY; 96198090Srdivacky#endif 97234353Sdim if (mode & S_IROTH) 98234353Sdim perms |= APR_WREAD; 99198090Srdivacky if (mode & S_IWOTH) 100198090Srdivacky perms |= APR_WWRITE; 101198090Srdivacky if (mode & S_IXOTH) 102210299Sed perms |= APR_WEXECUTE; 103210299Sed 104210299Sed return perms; 105210299Sed} 106210299Sed#endif 107210299Sed 108210299SedAPR_DECLARE(apr_status_t) apr_file_data_get(void **data, const char *key, 109210299Sed apr_file_t *file) 110210299Sed{ 111208599Srdivacky return apr_pool_userdata_get(data, key, file->pool); 112226633Sdim} 113239462Sdim 114239462SdimAPR_DECLARE(apr_status_t) apr_file_data_set(apr_file_t *file, void *data, 115226633Sdim const char *key, 116198090Srdivacky apr_status_t (*cleanup)(void *)) 117221345Sdim{ 118221345Sdim return apr_pool_userdata_set(data, key, cleanup, file->pool); 119221345Sdim} 120221345Sdim