Encoding utils

Encoding utils — encode strings to safe udev-compatible formats

Synopsis

int                 blkid_encode_string                 (const char *str,
                                                         char *str_enc,
                                                         size_t len);
int                 blkid_safe_string                   (const char *str,
                                                         char *str_safe,
                                                         size_t len);

Description

Details

blkid_encode_string ()

int                 blkid_encode_string                 (const char *str,
                                                         char *str_enc,
                                                         size_t len);

Encode all potentially unsafe characters of a string to the corresponding hex value prefixed by '\x'.

str :

input string to be encoded

str_enc :

output string to store the encoded input string

len :

maximum size of the output string, which may be four times as long as the input string

Returns :

0 if the entire string was copied, non-zero otherwise.

blkid_safe_string ()

int                 blkid_safe_string                   (const char *str,
                                                         char *str_safe,
                                                         size_t len);

Allows plain ascii, hex-escaping and valid utf8. Replaces all whitespaces with '_'.

str :

input string

str_safe :

output string

len :

size of output string

Returns :

0 on success or -1 in case of error.