1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
5 *
6 * $Id: openflags.c,v 12.13 2008/01/11 16:54:09 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13/*
14 * __db_openflags --
15 *	Convert open(2) flags to DB flags.
16 *
17 * PUBLIC: u_int32_t __db_openflags __P((int));
18 */
19u_int32_t
20__db_openflags(oflags)
21	int oflags;
22{
23	u_int32_t dbflags;
24
25	dbflags = 0;
26
27	if (oflags & O_CREAT)
28		dbflags |= DB_CREATE;
29
30	if (oflags & O_TRUNC)
31		dbflags |= DB_TRUNCATE;
32
33	/*
34	 * !!!
35	 * Convert POSIX 1003.1 open(2) mode flags to DB flags.  This isn't
36	 * an exact science as few POSIX implementations have a flag value
37	 * for O_RDONLY, it's simply the lack of a write flag.
38	 */
39#ifndef	O_ACCMODE
40#define	O_ACCMODE	(O_RDONLY | O_RDWR | O_WRONLY)
41#endif
42	switch (oflags & O_ACCMODE) {
43	case O_RDWR:
44	case O_WRONLY:
45		break;
46	default:
47		dbflags |= DB_RDONLY;
48		break;
49	}
50	return (dbflags);
51}
52