coverity appeasement
[minix.git] / lib / libvboxfs / path.c
blob6b8c021d826f433ba86b4cae2e7059f4c50e0721
1 /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
3 #include "inc.h"
5 /*
6 * Store a local path name in the given path object, performing any necessary
7 * conversions. The path object is expected to be used read-only, so the size
8 * of the path object is set as small as possible. If 'name' is NULL, the path
9 * will be initialized to the empty string.
11 int
12 vboxfs_set_path(vboxfs_path_t *path, char *name)
14 size_t len;
16 len = strlen(name);
18 /* FIXME: missing UTF-8 conversion */
20 if (len >= sizeof(path->data))
21 return ENAMETOOLONG;
23 strcpy(path->data, name);
25 path->len = len;
26 path->size = len + 1;
28 return OK;
32 * Retrieve the path name from the given path object. Make sure the name fits
33 * in the given name buffer first. The given size must include room for a
34 * terminating null character.
36 int
37 vboxfs_get_path(vboxfs_path_t *path, char *name, size_t size)
40 /* FIXME: missing UTF-8 conversion */
42 if (path->len >= size)
43 return ENAMETOOLONG;
45 assert(path->data[path->len] == 0);
47 strcpy(name, path->data);
49 return OK;
53 * Return the byte size of a previously initialized path object.
55 size_t
56 vboxfs_get_path_size(vboxfs_path_t *path)
59 return offsetof(vboxfs_path_t, data) + path->size;