apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr-util/dbm apr_dbm.c
Date Sat, 28 Apr 2001 00:23:42 GMT
wrowe       01/04/27 17:23:42

  Modified:    .        CHANGES
               include  apr_dbm.h
               dbm      apr_dbm.c
  Log:
    Adding perms to apr_dbm_open
  
  Revision  Changes    Path
  1.12      +2 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CHANGES	2001/04/11 19:07:02	1.11
  +++ CHANGES	2001/04/28 00:23:41	1.12
  @@ -1,5 +1,7 @@
   Changes with APR-util b1  
   
  +  *) Introduce an apr_fileperms_t argument to apr_dbm_open(). [Will Rowe]
  +
     *) Removed apr_bucket_do_create() macro, which was causing warnings
        about unreachable code in some compilers (notably MSVC).  What
        used to be done by this macro is now done inline in the various
  
  
  
  1.10      +4 -1      apr-util/include/apr_dbm.h
  
  Index: apr_dbm.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_dbm.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apr_dbm.h	2001/02/16 04:17:10	1.9
  +++ apr_dbm.h	2001/04/28 00:23:41	1.10
  @@ -59,6 +59,7 @@
   #include "apr.h"
   #include "apr_errno.h"
   #include "apr_pools.h"
  +#include "apr_file_info.h"
   
   #ifdef __cplusplus
   extern "C" {
  @@ -99,13 +100,15 @@
    *           APR_DBM_READWRITE  open for read-write access
    *           APR_DBM_RWCREATE   open for r/w, create if needed
    * </PRE>
  + * @param perm Permissions to apply to if created
    * @param cntxt The pool to use when creating the dbm
    * @deffunc apr_status_t apr_dbm_open(apr_dbm_t **dbm, const char *name, int mode
    * @tip The dbm name may not be a true file name, as many dbm packages
    * append suffixes for seperate data and index files.
    */
   APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **dbm, const char *name, 
  -                                       int mode, apr_pool_t *cntxt);
  +                                       apr_int32_t mode, apr_fileperms_t perm,
  +                                       apr_pool_t *cntxt);
   
   /**
    * Close a dbm file previously opened by apr_dbm_open
  
  
  
  1.19      +32 -13    apr-util/dbm/apr_dbm.c
  
  Index: apr_dbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- apr_dbm.c	2001/02/16 04:17:09	1.18
  +++ apr_dbm.c	2001/04/28 00:23:41	1.19
  @@ -65,11 +65,9 @@
      to stop "no effect" warnings from GCC. */
   #define NOOP_FUNCTION if (0) ; else
   
  -/* some of the DBM functions take a POSIX mode for creating files. use this. */
  -#define POSIX_FILEMODE 0660
   
  -
   #if APU_USE_SDBM
  +
   #include "apr_sdbm.h"
   
   typedef SDBM *real_file_t;
  @@ -92,7 +90,23 @@
   #define APR_DBM_DBMODE_RW       (APR_READ | APR_WRITE)
   #define APR_DBM_DBMODE_RWCREATE (APR_READ | APR_WRITE | APR_CREATE)
   
  -#elif APU_USE_GDBM
  +#else /* Not using SDBM: */
  +
  +/* Most DBM libraries take a POSIX mode for creating files.  Don't trust
  + * the mode_t type, some platforms may not support it, int is safe.
  + */
  +int apr_posix_perms2mode(apr_fileperms_t perm) 
  +{
  +    int mode = 0;
  +
  +    mode |= 0700 & (perm >> 2); /* User  is off-by-2 bits */
  +    mode |= 0070 & (perm >> 1); /* Group is off-by-1 bit */
  +    mode |= 0007 & (perm);      /* World maps 1 for 1 */
  +    return mode;
  +}
  +
  +#if APU_USE_GDBM
  +
   #include <gdbm.h>
   #include <stdlib.h>     /* for free() */
   
  @@ -253,10 +267,11 @@
       return db2s(dberr);
   }
   
  -#else
  +#else /* Not in the USE_xDBM list above */
   #error a DBM implementation was not specified
   #endif
   
  +#endif /* Not USE_SDBM */
   
   struct apr_dbm_t
   {
  @@ -341,7 +356,8 @@
   }
   
   APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **pdb, const char *pathname, 
  -                                       int mode, apr_pool_t *pool)
  +                                       apr_int32_t mode, apr_fileperms_t perm,
  +                                       apr_pool_t *pool)
   {
       real_file_t file;
       int dbmode;
  @@ -367,7 +383,7 @@
       {
           apr_status_t rv;
   
  -        rv = sdbm_open(&file, pathname, dbmode, APR_OS_DEFAULT, pool);
  +        rv = sdbm_open(&file, pathname, dbmode, perm, pool);
           if (rv != APR_SUCCESS)
               return rv;
       }
  @@ -376,7 +392,8 @@
   
       {
           /* Note: stupid cast to get rid of "const" on the pathname */
  -        file = gdbm_open((char *) pathname, 0, dbmode, POSIX_FILEMODE, NULL);
  +        file = gdbm_open((char *) pathname, 0, dbmode,
  +                         apr_posix_perms2mode(perm), NULL);
           if (file == NULL)
               return APR_EGENERAL;      /* ### need a better error */
       }
  @@ -388,19 +405,21 @@
   
   #if DB_VER == 3
           if ((dberr = db_create(&file.bdb, NULL, 0)) == 0) {
  -            if ((dberr = (*file.bdb->open)(file.bdb, pathname, NULL, DB_HASH,
  -                                           dbmode, POSIX_FILEMODE)) != 0) {
  +            if ((dberr = (*file.bdb->open)(file.bdb, pathname, NULL, 
  +                                           DB_HASH, dbmode, 
  +                                           apr_posix_perms2mode(perm))) != 0) {
                   /* close the DB handler */
                   (void) (*file.bdb->close)(file.bdb, 0);
               }
           }
           file.curs = NULL;
   #elif DB_VER == 2
  -        dberr = db_open(pathname, DB_HASH, dbmode, POSIX_FILEMODE, NULL, NULL,
  -                        &file.bdb);
  +        dberr = db_open(pathname, DB_HASH, dbmode, apr_posix_perms2mode(perm),
  +                        NULL, NULL, &file.bdb);
           file.curs = NULL;
   #else
  -        file.bdb = dbopen(pathname, dbmode, POSIX_FILEMODE, DB_HASH, NULL);
  +        file.bdb = dbopen(pathname, dbmode, apr_posix_perms2mode(perm),
  +                          DB_HASH, NULL);
           if (file.bdb == NULL)
               return APR_EGENERAL;      /* ### need a better error */
           dberr = 0;
  
  
  

Mime
View raw message