]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/cnid_get.c
Whoops, forgot to declare rc in cnid_get.c.
[netatalk.git] / libatalk / cnid / cnid_get.c
1 /*
2  * $Id: cnid_get.c,v 1.6 2001-09-21 15:09:54 jmarcus Exp $
3  */
4
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif /* HAVE_CONFIG_H */
8
9 #ifdef CNID_DB
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/param.h>
13 #include <sys/stat.h>
14 #include <syslog.h>
15 #include <errno.h>
16
17 #include <db.h>
18 #include <netatalk/endian.h>
19 #include <atalk/adouble.h>
20 #include <atalk/cnid.h>
21
22 #include "cnid_private.h"
23
24 /* return CNID for a given did/name */
25 cnid_t cnid_get(void *CNID, const cnid_t did, const char *name,
26                 const int len) 
27 {
28   char start[CNID_DID_LEN + MAXPATHLEN + 1], *buf;
29   CNID_private *db;
30   DBT key, data;
31   cnid_t id;
32   int rc = 0;
33
34   if (!(db = CNID) || (len > MAXPATHLEN))
35     return 0;
36
37   memset(&key, 0, sizeof(key));
38   memset(&data, 0, sizeof(data));
39
40   buf = start;
41   memcpy(buf, &did, sizeof(did));
42   buf += sizeof(did);
43   memcpy(buf, name, len);
44   *(buf + len) = '\0'; /* make sure to nul terminate. */
45   key.data = start;
46   key.size = CNID_DID_LEN + len + 1;
47
48   while ((rc = db->db_didname->get(db->db_didname, NULL,
49                                       &key, &data, 0))) {
50     if (rc == EAGAIN) 
51       continue;
52
53     if (rc != DB_NOTFOUND)
54       syslog(LOG_ERR, "cnid_get: can't get CNID(%u:%s) (%d)", did, name, rc);
55
56     return 0;
57   }
58
59   memcpy(&id, data.data, sizeof(id));
60   return id;
61 }
62 #endif /* CNID_DB */