1433d6423SLionel Sambuc /* Part of libvboxfs - (c) 2012, D.C. van Moolenbroek */
2433d6423SLionel Sambuc
3433d6423SLionel Sambuc #include "inc.h"
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc /*
6433d6423SLionel Sambuc * Store a local path name in the given path object, performing any necessary
7433d6423SLionel Sambuc * conversions. The path object is expected to be used read-only, so the size
8433d6423SLionel Sambuc * of the path object is set as small as possible. If 'name' is NULL, the path
9433d6423SLionel Sambuc * will be initialized to the empty string.
10433d6423SLionel Sambuc */
11433d6423SLionel Sambuc int
vboxfs_set_path(vboxfs_path_t * path,const char * name)12*94e65446SDavid van Moolenbroek vboxfs_set_path(vboxfs_path_t *path, const char *name)
13433d6423SLionel Sambuc {
14433d6423SLionel Sambuc size_t len;
15433d6423SLionel Sambuc
16433d6423SLionel Sambuc len = strlen(name);
17433d6423SLionel Sambuc
18433d6423SLionel Sambuc /* FIXME: missing UTF-8 conversion */
19433d6423SLionel Sambuc
20433d6423SLionel Sambuc if (len >= sizeof(path->data))
21433d6423SLionel Sambuc return ENAMETOOLONG;
22433d6423SLionel Sambuc
23433d6423SLionel Sambuc strcpy(path->data, name);
24433d6423SLionel Sambuc
25433d6423SLionel Sambuc path->len = len;
26433d6423SLionel Sambuc path->size = len + 1;
27433d6423SLionel Sambuc
28433d6423SLionel Sambuc return OK;
29433d6423SLionel Sambuc }
30433d6423SLionel Sambuc
31433d6423SLionel Sambuc /*
32433d6423SLionel Sambuc * Retrieve the path name from the given path object. Make sure the name fits
33433d6423SLionel Sambuc * in the given name buffer first. The given size must include room for a
34433d6423SLionel Sambuc * terminating null character.
35433d6423SLionel Sambuc */
36433d6423SLionel Sambuc int
vboxfs_get_path(vboxfs_path_t * path,char * name,size_t size)37433d6423SLionel Sambuc vboxfs_get_path(vboxfs_path_t *path, char *name, size_t size)
38433d6423SLionel Sambuc {
39433d6423SLionel Sambuc
40433d6423SLionel Sambuc /* FIXME: missing UTF-8 conversion */
41433d6423SLionel Sambuc
42433d6423SLionel Sambuc if (path->len >= size)
43433d6423SLionel Sambuc return ENAMETOOLONG;
44433d6423SLionel Sambuc
45433d6423SLionel Sambuc assert(path->data[path->len] == 0);
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc strcpy(name, path->data);
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc return OK;
50433d6423SLionel Sambuc }
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc /*
53433d6423SLionel Sambuc * Return the byte size of a previously initialized path object.
54433d6423SLionel Sambuc */
55433d6423SLionel Sambuc size_t
vboxfs_get_path_size(vboxfs_path_t * path)56433d6423SLionel Sambuc vboxfs_get_path_size(vboxfs_path_t *path)
57433d6423SLionel Sambuc {
58433d6423SLionel Sambuc
59433d6423SLionel Sambuc return offsetof(vboxfs_path_t, data) + path->size;
60433d6423SLionel Sambuc }
61