~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/os/os_oflags.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * See the file LICENSE for redistribution information.
 
3
 *
 
4
 * Copyright (c) 1997-2001
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 */
 
7
 
 
8
#include "db_config.h"
 
9
 
 
10
#ifndef lint
 
11
static const char revid[] = "$Id: os_oflags.c,v 11.8 2001/04/27 17:16:24 bostic Exp $";
 
12
#endif /* not lint */
 
13
 
 
14
#ifndef NO_SYSTEM_INCLUDES
 
15
#include <sys/types.h>
 
16
#include <sys/stat.h>
 
17
 
 
18
#include <fcntl.h>
 
19
#endif
 
20
 
 
21
#include "db_int.h"
 
22
 
 
23
/*
 
24
 * __db_oflags --
 
25
 *      Convert open(2) flags to DB flags.
 
26
 *
 
27
 * PUBLIC: u_int32_t __db_oflags __P((int));
 
28
 */
 
29
u_int32_t
 
30
__db_oflags(oflags)
 
31
        int oflags;
 
32
{
 
33
        u_int32_t dbflags;
 
34
 
 
35
        dbflags = 0;
 
36
 
 
37
        if (oflags & O_CREAT)
 
38
                dbflags |= DB_CREATE;
 
39
 
 
40
        if (oflags & O_TRUNC)
 
41
                dbflags |= DB_TRUNCATE;
 
42
 
 
43
        /*
 
44
         * !!!
 
45
         * Convert POSIX 1003.1 open(2) mode flags to DB flags.  This isn't
 
46
         * an exact science as few POSIX implementations have a flag value
 
47
         * for O_RDONLY, it's simply the lack of a write flag.
 
48
         */
 
49
#ifndef O_ACCMODE
 
50
#define O_ACCMODE       (O_RDONLY | O_RDWR | O_WRONLY)
 
51
#endif
 
52
        switch (oflags & O_ACCMODE) {
 
53
        case O_RDWR:
 
54
        case O_WRONLY:
 
55
                break;
 
56
        default:
 
57
                dbflags |= DB_RDONLY;
 
58
                break;
 
59
        }
 
60
        return (dbflags);
 
61
}
 
62
 
 
63
/*
 
64
 * __db_omode --
 
65
 *      Convert a permission string to the correct open(2) flags.
 
66
 *
 
67
 * PUBLIC: int __db_omode __P((const char *));
 
68
 */
 
69
int
 
70
__db_omode(perm)
 
71
        const char *perm;
 
72
{
 
73
        int mode;
 
74
 
 
75
#ifdef DB_WIN32
 
76
#ifndef S_IRUSR
 
77
#define S_IRUSR S_IREAD         /* R for owner */
 
78
#endif
 
79
#ifndef S_IWUSR
 
80
#define S_IWUSR S_IWRITE        /* W for owner */
 
81
#endif
 
82
#ifndef S_IRGRP
 
83
#define S_IRGRP 0               /* R for group */
 
84
#endif
 
85
#ifndef S_IWGRP
 
86
#define S_IWGRP 0               /* W for group */
 
87
#endif
 
88
#ifndef S_IROTH
 
89
#define S_IROTH 0               /* R for other */
 
90
#endif
 
91
#ifndef S_IWOTH
 
92
#define S_IWOTH 0               /* W for other */
 
93
#endif
 
94
#else
 
95
#ifndef S_IRUSR
 
96
#define S_IRUSR 0000400         /* R for owner */
 
97
#define S_IWUSR 0000200         /* W for owner */
 
98
#define S_IRGRP 0000040         /* R for group */
 
99
#define S_IWGRP 0000020         /* W for group */
 
100
#define S_IROTH 0000004         /* R for other */
 
101
#define S_IWOTH 0000002         /* W for other */
 
102
#endif
 
103
#endif /* DB_WIN32 */
 
104
        mode = 0;
 
105
        if (perm[0] == 'r')
 
106
                mode |= S_IRUSR;
 
107
        if (perm[1] == 'w')
 
108
                mode |= S_IWUSR;
 
109
        if (perm[2] == 'r')
 
110
                mode |= S_IRGRP;
 
111
        if (perm[3] == 'w')
 
112
                mode |= S_IWGRP;
 
113
        if (perm[4] == 'r')
 
114
                mode |= S_IROTH;
 
115
        if (perm[5] == 'w')
 
116
                mode |= S_IWOTH;
 
117
        return (mode);
 
118
}