8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libnisdb / db_vers.cc
blob79c1d46fc97618643b7db0cb11505a50d5fe6df5
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * db_vers.cc
25 * Copyright (c) 1988-2000 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <stdio.h>
32 #include <string.h>
34 #include "db_headers.h"
35 #include "db_vers.h"
36 #include "nisdb_mt.h"
38 const long unsigned MAXLOW = 32768*32768;
40 /* Constructor that makes copy of 'other'. */
41 vers::vers(vers* other)
43 INITRW(vers);
44 assign(other);
47 void
48 vers::assign(vers* other)
50 WRITELOCKV(this, "w vers::assign");
51 if (other == NULL) {
52 syslog(LOG_ERR, "vers::vers: making copy of null vers?");
53 vers_high = vers_low = time_sec = time_usec = 0;
54 } else {
55 time_sec = other->time_sec;
56 time_usec = other->time_usec;
57 vers_low = other->vers_low;
58 vers_high = other->vers_high;
60 WRITEUNLOCKV(this, "wu vers::assign");
64 * Creates new 'vers' with next higher minor version.
65 * If minor version exceeds MAXLOW, bump up major version instead.
66 * Set timestamp to that of the current time.
68 vers*
69 vers::nextminor()
71 READLOCK(this, NULL, "r vers::nextminor");
73 vers * newvers = new vers;
75 if (newvers == NULL) {
76 READUNLOCK(this, NULL, "ru vers::nextminor DB_MEMORY_LIMIT");
77 FATAL3("vers::nextminor: cannot allocation space",
78 DB_MEMORY_LIMIT, NULL);
81 struct timeval mt;
82 gettimeofday(&mt, NULL);
84 newvers->time_sec = (unsigned int) mt.tv_sec;
85 newvers->time_usec = (unsigned int) mt.tv_usec;
86 newvers->vers_low = (this->vers_low + 1);
87 newvers->vers_high = (this->vers_high);
89 if (newvers->vers_low >= MAXLOW){
90 newvers->vers_high++;
91 newvers->vers_low = 0;
94 READUNLOCK(this, newvers, "ru vers::nextminor");
95 return (newvers);
99 * Creates new 'vers' with next higher major version.
100 * Set timestamp to that of the current time.
102 vers*
103 vers::nextmajor()
105 READLOCK(this, NULL, "r vers::nextmajor");
107 vers * newvers = new vers;
109 if (newvers == NULL) {
110 READUNLOCK(this, NULL, "ru vers::nextmajor DB_MEMORY_LIMIT");
111 FATAL3("vers::nextminor: cannot allocation space",
112 DB_MEMORY_LIMIT, NULL);
115 struct timeval mt;
116 gettimeofday(&mt, NULL);
118 newvers->time_sec = (unsigned int) mt.tv_sec;
119 newvers->time_usec = (unsigned int) mt.tv_usec;
120 newvers->vers_low = 0;
121 newvers->vers_high = (this->vers_high+1);
123 READUNLOCK(this, newvers, "ru vers::nextmajor");
124 return (newvers);
128 * Predicate indicating whether this vers is earlier than 'other' in
129 * terms of version numbers.
131 bool_t
132 vers::earlier_than(vers *other)
134 int ret, lret;
136 if (other == NULL) {
137 syslog(LOG_ERR,
138 "vers::earlier_than: comparing against null vers");
139 return (FALSE);
142 READLOCK(this, FALSE, "r vers::earlier_than");
143 READLOCKNR(other, lret, "r other vers::earlier_than");
144 if (lret != 0) {
145 READUNLOCK(this, FALSE, "ru + r other vers::earlier_than");
146 return (FALSE);
149 if (other->vers_high > vers_high) ret = TRUE;
150 else if (other->vers_high < vers_high) ret = FALSE;
151 else if (other->vers_low > vers_low) ret = TRUE;
152 else ret = FALSE;
154 READUNLOCKNR(other, lret, "ru other vers::earlier_than");
155 READUNLOCK(this, ret, ((lret != 0) ?
156 "ru + ru other vers::earlier_than" :
157 "ru vers::earlier_than"));
158 return (ret);
161 /* Print the value of this 'vers' to specified file. */
162 void
163 vers::print(FILE* file)
165 char *thetime;
166 thetime = ctime((long *) (&(time_sec)));
167 thetime[strlen(thetime)-1] = 0;
169 READLOCKV(this, "r vers::print");
170 fprintf(file, "version=%u.%u %s:%u",
171 vers_high,
172 vers_low,
173 /* time_sec, */
174 thetime,
175 time_usec);
176 READUNLOCKV(this, "ru vers::print");
179 void
180 vers::zero() {
181 WRITELOCKV(this, "r vers::zero");
182 vers_high = vers_low = time_sec = time_usec = 0;
183 WRITEUNLOCKV(this, "ru vers::zero");
186 bool_t
187 vers::equal( vers *other) {
188 READLOCK(this, FALSE, "r vers::equal");
189 bool_t ret = other != NULL &&
190 vers_high == other->vers_high &&
191 vers_low == other->vers_low &&
192 time_sec == other->time_sec &&
193 time_usec == other->time_usec;
194 READUNLOCK(this, ret, "ru vers::equal");
195 return (ret);