1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
7 /*===========================================================================*
9 *===========================================================================*/
10 void path_put(const char *path
)
12 /* Append the given path name in HGFS format to the RPC buffer. Truncate it
13 * if it is longer than PATH_MAX bytes.
19 /* No leading slashes are allowed. */
20 for (p
= path
; *p
== '/'; p
++);
22 /* No double or tailing slashes, either. */
23 for (len
= 0; *p
&& len
< sizeof(buf
) - 1; len
++) {
25 for (p
++; *p
== '/'; p
++);
36 memcpy(RPC_PTR
, buf
, len
);
42 /*===========================================================================*
44 *===========================================================================*/
45 int path_get(char *path
, int max
)
47 /* Retrieve a HGFS formatted path name from the RPC buffer. Returns EINVAL if
48 * the path name is invalid. Returns ENAMETOOLONG if the path name is too
49 * long. Returns OK on success.
56 if (len
>= max
) return ENAMETOOLONG
;
58 for (p
= path
, q
= RPC_PTR
; n
--; p
++, q
++) {
59 /* We can not deal with a slash in a path component. */
60 if (*q
== '/') return EINVAL
;
62 if (*q
== 0) *p
= '/';
70 return (RPC_NEXT8
!= 0) ? EINVAL
: OK
;