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