]> arthur.barton.de Git - netatalk.git/blob - libatalk/cnid/cnid_resolve.c
Warning fixes.
[netatalk.git] / libatalk / cnid / cnid_resolve.c
1 /*
2  * $Id: cnid_resolve.c,v 1.3 2001-08-15 02:16:25 srittau 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 the did/name pair corresponding to a CNID. */
24 char *cnid_resolve(void *CNID, cnid_t *id)
25 {
26   CNID_private *db;
27   DBT key, data;
28
29   if (!(db = CNID) || !id || !(*id))
30     return NULL;
31
32   memset(&key, 0, sizeof(key));
33   memset(&data, 0, sizeof(data));
34
35   key.data = id;
36   key.size = sizeof(*id);
37   while ((errno = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
38     if (errno == EAGAIN)
39       continue;
40
41     if (errno != DB_NOTFOUND) 
42       syslog(LOG_ERR, "cnid_resolve: can't get did/name");
43
44     *id = 0;
45     return NULL;
46   }
47   
48   memcpy(id, (char *) data.data + CNID_DEVINO_LEN, sizeof(*id));
49   return (char *) data.data + CNID_HEADER_LEN;
50 }