]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/nextid.c
Use #ifdef, not #if
[openldap] / servers / slapd / back-bdb2 / nextid.c
1 /* id.c - keep track of the next id to be given out */
2 /* $OpenLDAP$ */
3
4 #include "portable.h"
5
6 #include <stdio.h>
7
8 #include <ac/socket.h>
9
10 #ifdef HAVE_SYS_PARAM_H
11 #include <sys/param.h>
12 #endif
13
14 #include "slap.h"
15 #include "back-bdb2.h"
16
17 /*  reading and writing NEXTID is handled in txn.c  */
18 #define next_id_read(be)  bdb2i_get_nextid( (be) )
19 #define next_id_write(be,id)  bdb2i_put_nextid( (be), (id) )
20
21
22 int
23 bdb2i_next_id_save( BackendDB *be )
24 {
25         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
26         ID id = bdb2i_next_id_get( be );
27         int rc;
28
29         rc = next_id_write( be, id );
30
31         return rc;
32 }
33
34 ID
35 bdb2i_next_id( BackendDB *be )
36 {
37         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
38         ID              id;
39
40         /* first time in here since startup - try to read the nexid */
41         if ( li->li_nextid == NOID ) {
42                 li->li_nextid = next_id_read( be );
43
44                 if ( li->li_nextid == NOID ) {
45                         li->li_nextid = 1;
46                 }
47         }
48
49         id = li->li_nextid++;
50
51         (void) next_id_write( be, li->li_nextid );
52
53         return( id );
54 }
55
56 ID
57 bdb2i_next_id_get( BackendDB *be )
58 {
59         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
60         ID              id;
61
62         /* first time in here since startup - try to read the nexid */
63         if ( li->li_nextid == NOID ) {
64                 li->li_nextid = next_id_read( be );
65
66                 if ( li->li_nextid == NOID ) {
67                         li->li_nextid = 1;
68                 }
69         }
70
71         id = li->li_nextid;
72
73         return( id );
74 }