4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright (c) 1988-2000 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 /* #include <sys/types.h> */
33 /* #include <syslog.h> */
36 #include "db_headers.h"
37 #include "db_pickle.h"
40 /* Constructor. Creates pickle_file with given name and mode. */
41 pickle_file::pickle_file(char* f
, pickle_mode m
)
43 if ((filename
= strdup(f
)) == NULL
) {
44 FATAL("pickle_file::pickle_file: cannot allocate space",
54 * Opens pickle_file with mode specified with constructor.
55 * Returns TRUE if open was successful; FALSE otherwise.
60 WRITELOCK(this, FALSE
, "w pickle_file::open");
61 if (mode
== PICKLE_READ
) {
62 file
= fopen(filename
, "r");
64 xdrstdio_create(&(xdr
), file
, XDR_DECODE
);
65 } else if (mode
== PICKLE_WRITE
) {
66 file
= fopen(filename
, "w");
68 setvbuf(file
, NULL
, _IOFBF
, 81920);
69 xdrstdio_create(&(xdr
), file
, XDR_ENCODE
);
71 } else if (mode
== PICKLE_APPEND
) {
72 file
= fopen(filename
, "a");
74 xdrstdio_create(&(xdr
), file
, XDR_ENCODE
);
77 WRITEUNLOCK(this, FALSE
, "wu pickle_file::open");
80 WRITEUNLOCK(this, FALSE
, "wu pickle_file::open");
85 /* Closes pickle_file. Returns 0 if successful; -1 otherwise. */
91 WRITELOCK(this, EOF
, "w pickle_file::close");
94 WRITEUNLOCK(this, EOF
, "wu pickle_file::close");
100 * dump or load data structure to/from 'filename' using function 'f'.
101 * dump or load is determined by 'mode' with which pickle_file was created.
102 * Returns 0 if successful; 1 if file cannot be opened in mode
103 * specified; -1 if transfer failed do to encoding/decoding errors.
106 pickle_file::transfer(pptr p
, bool_t (*f
) (XDR
*, pptr
))
108 WRITELOCK(this, -1, "w pickle_file::transfer");
110 if ((f
)(&xdr
, p
) == FALSE
) {
112 WRITEUNLOCK(this, -1, "wu pickle_file::transfer");
116 WRITEUNLOCK(this, -1, "wu pickle_file::transfer");
120 WRITEUNLOCK(this, -1, "wu pickle_file::transfer");