Back to index

openldap  2.4.31
nextid.c
Go to the documentation of this file.
00001 /* init.c - initialize mdb backend */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 #include <ac/string.h>
00021 
00022 #include "back-mdb.h"
00023 
00024 int mdb_next_id( BackendDB *be, MDB_cursor *mc, ID *out )
00025 {
00026        int rc;
00027        ID id = 0;
00028        MDB_val key;
00029 
00030        rc = mdb_cursor_get(mc, &key, NULL, MDB_LAST);
00031 
00032        switch(rc) {
00033        case MDB_NOTFOUND:
00034               rc = 0;
00035               *out = 1;
00036               break;
00037        case 0:
00038               memcpy( &id, key.mv_data, sizeof( id ));
00039               *out = ++id;
00040               break;
00041 
00042        default:
00043               Debug( LDAP_DEBUG_ANY,
00044                      "=> mdb_next_id: get failed: %s (%d)\n",
00045                      mdb_strerror(rc), rc, 0 );
00046               goto done;
00047        }
00048 
00049 done:
00050        return rc;
00051 }