From: Karel Zak Date: Wed, 21 Jul 2010 12:18:02 +0000 (+0200) Subject: libmount: add unmangle/mangle() functions to API X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c5e4ef8881272a97edb2a01649780c9b5bbcf3b;p=util-linux libmount: add unmangle/mangle() functions to API Signed-off-by: Karel Zak --- diff --git a/include/mangle.h b/include/mangle.h index 8ce38752..0ccd3776 100644 --- a/include/mangle.h +++ b/include/mangle.h @@ -7,8 +7,8 @@ extern char *mangle(const char *s); -extern void unmangle_to_buffer(char *s, char *buf, size_t len); -extern char *unmangle(char *s); +extern void unmangle_to_buffer(const char *s, char *buf, size_t len); +extern char *unmangle(const char *s); #endif /* UTIL_LINUX_MANGLE_H */ diff --git a/lib/mangle.c b/lib/mangle.c index 766d479d..c40e67ba 100644 --- a/lib/mangle.c +++ b/lib/mangle.c @@ -44,7 +44,7 @@ char *mangle(const char *s) return ss; } -void unmangle_to_buffer(char *s, char *buf, size_t len) +void unmangle_to_buffer(const char *s, char *buf, size_t len) { size_t sz = 0; @@ -63,7 +63,7 @@ void unmangle_to_buffer(char *s, char *buf, size_t len) *buf = '\0'; } -static inline char *skip_nonspaces(char *s) +static inline const char *skip_nonspaces(const char *s) { while (*s && !(*s == ' ' || *s == '\t')) s++; @@ -73,9 +73,10 @@ static inline char *skip_nonspaces(char *s) /* * Returns mallocated buffer or NULL in case of error. */ -char *unmangle(char *s) +char *unmangle(const char *s) { - char *buf, *end; + char *buf; + const char *end; size_t sz; end = skip_nonspaces(s); diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index 9a628042..af1dd38a 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -110,6 +110,8 @@ extern int mnt_parse_version_string(const char *ver_string); extern int mnt_get_library_version(const char **ver_string); /* utils.c */ +extern char *mnt_mangle(const char *str); +extern char *mnt_unmangle(const char *str); extern int mnt_fstype_is_netfs(const char *type); extern int mnt_fstype_is_pseudofs(const char *type); extern int mnt_match_fstype(const char *type, const char *pattern); diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index a33c7f26..7824597c 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -55,6 +55,7 @@ global: mnt_lock_file; mnt_lock_get_linkfile; mnt_lock_get_lockfile; + mnt_mangle; mnt_match_fstype; mnt_match_options; mnt_new_cache; @@ -132,6 +133,7 @@ global: mnt_tab_set_parser_errcb; mnt_tab_update_file; mnt_unlock_file; + mnt_unmangle; local: *; }; diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index eb183ee0..372351ac 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -31,6 +31,7 @@ #include "strutils.h" #include "pathnames.h" #include "mountP.h" +#include "mangle.h" char *mnt_getenv_safe(const char *arg) { @@ -84,6 +85,32 @@ int startswith(const char *s, const char *sx) return !strncmp(s, sx, off); } +/** + * mnt_mangle: + * @str: string + * + * Encode @str to be compatible with fstab/mtab + * + * Returns: new allocated string or NULL in case of error. + */ +char *mnt_mangle(const char *str) +{ + return mangle(str); +} + +/** + * mnt_unmangle: + * @str: string + * + * Decode @str from fstab/mtab + * + * Returns: new allocated string or NULL in case of error. + */ +char *mnt_unmangle(const char *str) +{ + return unmangle(str); +} + /** * mnt_fstype_is_pseudofs: * @type: filesystem name