]>
git.saurik.com Git - apple/network_cmds.git/blob - makedbm.tproj/ypdb.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* $OpenBSD: ypdb.c,v 1.5 1997/02/09 09:49:36 maja Exp $ */
26 * Copyright (c) 1990, 1993
27 * The Regents of the University of California. All rights reserved.
28 * All rights reserved.
30 * This code is derived from software contributed to Berkeley by
33 * This code is derived from ndbm module of BSD4.4 db (hash) by
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
53 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
56 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 #include <sys/param.h>
66 #include <sys/types.h>
73 extern DBM
*__hash_open();
75 extern DBM
*__bt_open();
85 ypdb_open(file
, flags
, mode
)
91 char path
[MAXPATHLEN
];
96 info
.cachesize
= NULL
;
99 snprintf(path
, sizeof(path
), "%s%s", file
, YPDB_SUFFIX
);
100 return ((DBM
*)__hash_open(path
, flags
, mode
, &info
, 0));
103 char path
[MAXPATHLEN
];
114 snprintf(path
, sizeof(path
), "%s%s", file
, YPDB_SUFFIX
);
115 db
= (DBM
*)__bt_open(path
, flags
, mode
, &info
, 0);
127 ypdb_open_suf(file
, flags
, mode
)
137 info
.cachesize
= NULL
;
140 return ((DBM
*)__hash_open(file
, flags
, mode
, &info
, 0));
153 db
= (DBM
*)__bt_open(file
, flags
, mode
, &info
, 0);
162 (void)(db
->close
)(db
);
179 status
= (db
->get
)(db
, (DBT
*)&key
, (DBT
*)&retval
, 0);
198 datum retdata
, retkey
;
200 status
= (db
->seq
)(db
, (DBT
*)&retkey
, (DBT
*)&retdata
, R_FIRST
);
217 datum retdata
, retkey
;
219 status
= (db
->seq
)(db
, (DBT
*)&retkey
, (DBT
*)&retdata
, R_NEXT
);
241 status
= (db
->seq
)(db
, (DBT
*)&retkey
, (DBT
*)&retdata
, R_FIRST
);
244 while ((retkey
.dptr
!= NULL
) &&
245 ((retkey
.dsize
!= key
.dsize
) ||
246 (strncmp(key
.dptr
,retkey
.dptr
,retkey
.dsize
) != 0))) {
247 status
= (db
->seq
)(db
, (DBT
*)&retkey
, (DBT
*)&retdata
, R_NEXT
);
253 status
= (db
->seq
)(db
, (DBT
*)&key
, (DBT
*)&retdata
, R_CURSOR
);
273 status
= (db
->del
)(db
, (DBT
*)&key
, 0);
284 * 1 if YPDB_INSERT and entry exists
288 ypdb_store(db
, key
, content
, flags
)
293 return ((db
->put
)(db
, (DBT
*)&key
, (DBT
*)&content
,
294 (flags
== YPDB_INSERT
) ? R_NOOVERWRITE
: 0));