Update.
[glibc.git] / db2 / os / os_config.c
blob4150c843e45f3e395c7ff90790a0040c0637be16
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_config.c 10.26 (Sleepycat) 5/23/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #include <errno.h>
18 #endif
20 #include "db_int.h"
23 * XXX
24 * We provide our own extern declarations so that we don't collide with
25 * systems that get them wrong, e.g., SunOS.
27 #ifdef _WIN32
28 #define fsync _commit
29 #define imported __declspec(dllimport)
30 #else
31 #define imported
32 #endif
35 * XXX
36 * HP/UX MPE doesn't have fsync, but you can build one using FCONTROL.
38 #ifdef __hp3000s900
39 #define fsync __mpe_fsync
40 #endif
42 imported extern int close __P((int));
43 imported extern void free __P((void *));
44 imported extern int fsync __P((int));
45 imported extern void *malloc __P((size_t));
46 imported extern int open __P((const char *, int, ...));
47 imported extern ssize_t read __P((int, void *, size_t));
48 imported extern void *realloc __P((void *, size_t));
49 imported extern int unlink __P((const char *));
50 imported extern ssize_t write __P((int, const void *, size_t));
53 * __db_jump --
54 * This list of interfaces that applications can replace. In some
55 * cases, the user is permitted to replace the standard ANSI C or
56 * POSIX 1003.1 call, e.g., malloc or read. In others, we provide
57 * a local interface to the functionality, e.g., __os_ioinfo.
59 struct __db_jumptab __db_jump = {
60 close, /* DB_FUNC_CLOSE */
61 __os_dirfree, /* DB_FUNC_DIRFREE */
62 __os_dirlist, /* DB_FUNC_DIRLIST */
63 __os_exists, /* DB_FUNC_EXISTS */
64 free, /* DB_FUNC_FREE */
65 fsync, /* DB_FUNC_FSYNC */
66 __os_ioinfo, /* DB_FUNC_IOINFO */
67 malloc, /* DB_FUNC_MALLOC */
68 NULL, /* DB_FUNC_MAP */
69 open, /* DB_FUNC_OPEN */
70 read, /* DB_FUNC_READ */
71 realloc, /* DB_FUNC_REALLOC */
72 NULL, /* DB_FUNC_RUNLINK */
73 __os_seek, /* DB_FUNC_SEEK */
74 __os_sleep, /* DB_FUNC_SLEEP */
75 unlink, /* DB_FUNC_UNLINK */
76 NULL, /* DB_FUNC_UNMAP */
77 write, /* DB_FUNC_WRITE */
78 NULL /* DB_FUNC_YIELD */
81 DB_GLOBALS __db_global_values = {
82 1, /* DB_MUTEXLOCKS */
83 0, /* DB_REGION_ANON, DB_REGION_NAME */
84 0, /* DB_REGION_INIT */
85 0, /* DB_TSL_SPINS */
86 0 /* DB_PAGEYIELD */
90 * db_jump_set --
91 * Replace functions for the DB package.
93 int
94 db_jump_set(func, which)
95 void *func;
96 int which;
98 switch (which) {
99 case DB_FUNC_CLOSE:
100 __db_jump.j_close = (int (*) __P((int)))func;
101 break;
102 case DB_FUNC_DIRFREE:
103 __db_jump.j_dirfree = (void (*) __P((char **, int)))func;
104 break;
105 case DB_FUNC_DIRLIST:
106 __db_jump.j_dirlist =
107 (int (*) __P((const char *, char ***, int *)))func;
108 break;
109 case DB_FUNC_EXISTS:
110 __db_jump.j_exists = (int (*) __P((const char *, int *)))func;
111 break;
112 case DB_FUNC_FREE:
113 __db_jump.j_free = (void (*) __P((void *)))func;
114 break;
115 case DB_FUNC_FSYNC:
116 __db_jump.j_fsync = (int (*) __P((int)))func;
117 break;
118 case DB_FUNC_IOINFO:
119 __db_jump.j_ioinfo = (int (*) __P((const char *,
120 int, u_int32_t *, u_int32_t *, u_int32_t *)))func;
121 break;
122 case DB_FUNC_MALLOC:
123 __db_jump.j_malloc = (void *(*) __P((size_t)))func;
124 break;
125 case DB_FUNC_MAP:
126 __db_jump.j_map = (int (*)
127 __P((char *, int, size_t, int, int, int, void **)))func;
128 break;
129 case DB_FUNC_OPEN:
130 __db_jump.j_open = (int (*) __P((const char *, int, ...)))func;
131 break;
132 case DB_FUNC_READ:
133 __db_jump.j_read =
134 (ssize_t (*) __P((int, void *, size_t)))func;
135 break;
136 case DB_FUNC_REALLOC:
137 __db_jump.j_realloc = (void *(*) __P((void *, size_t)))func;
138 break;
139 case DB_FUNC_RUNLINK:
140 __db_jump.j_runlink = (int (*) __P((char *)))func;
141 break;
142 case DB_FUNC_SEEK:
143 __db_jump.j_seek = (int (*)
144 __P((int, size_t, db_pgno_t, u_int32_t, int, int)))func;
145 break;
146 case DB_FUNC_SLEEP:
147 __db_jump.j_sleep = (int (*) __P((u_long, u_long)))func;
148 break;
149 case DB_FUNC_UNLINK:
150 __db_jump.j_unlink = (int (*) __P((const char *)))func;
151 break;
152 case DB_FUNC_UNMAP:
153 __db_jump.j_unmap = (int (*) __P((void *, size_t)))func;
154 break;
155 case DB_FUNC_WRITE:
156 __db_jump.j_write =
157 (ssize_t (*) __P((int, const void *, size_t)))func;
158 break;
159 case DB_FUNC_YIELD:
160 __db_jump.j_yield = (int (*) __P((void)))func;
161 break;
162 default:
163 return (EINVAL);
165 return (0);
169 * db_value_set --
170 * Replace values for the DB package.
173 db_value_set(value, which)
174 int value, which;
176 int ret;
178 switch (which) {
179 case DB_MUTEXLOCKS:
180 DB_GLOBAL(db_mutexlocks) = value;
181 break;
182 case DB_PAGEYIELD:
183 DB_GLOBAL(db_pageyield) = value;
184 break;
185 case DB_REGION_ANON:
186 if (value != 0 && (ret = __db_mapanon_ok(0)) != 0)
187 return (ret);
188 DB_GLOBAL(db_region_anon) = value;
189 break;
190 case DB_REGION_INIT:
191 DB_GLOBAL(db_region_init) = value;
192 break;
193 case DB_REGION_NAME:
194 if (value != 0 && (ret = __db_mapanon_ok(1)) != 0)
195 return (ret);
196 DB_GLOBAL(db_region_anon) = value;
197 break;
198 case DB_TSL_SPINS:
199 if (value <= 0)
200 return (EINVAL);
201 DB_GLOBAL(db_tsl_spins) = value;
202 break;
203 default:
204 return (EINVAL);
206 return (0);