Integer functions
These functions should be used to encode and decode 16, 32, and 64 bit integers.
size_t enc_uint16be(uint16_t s, unsigned char *dst);
Encode a 16 bit integer in big endian order into the memory at dst and return the number of bytes written which is always 2.
size_t enc_uint32be(uint32_t i, unsigned char *dst);
Encode a 32 bit integer in big endian order into the memory at dst and return the number of bytes written which is always 4.
size_t enc_uint64be(uint64_t l, unsigned char *dst);
Encode a 64 bit integer in big endian order into the memory at dst and return the number of bytes written which is always 8.
size_t enc_uint16le(uint16_t s, unsigned char *dst);
Encode a 16 bit integer in little endian order into the memory at dst and return the number of bytes written which is always 2.
size_t enc_uint32le(uint32_t i, unsigned char *dst);
Encode a 32 bit integer in little endian order into the memory at dst and return the number of bytes written which is always 4.
size_t enc_uint64le(uint64_t l, unsigned char *dst);
Encode a 64 bit integer in little endian order into the memory at dst and return the number of bytes written which is always 8.
uint16_t dec_uint16be(const unsigned char *src);
Return a 16 bit integer decoded in big endian byte order from 2 bytes of src memory.
uint32_t dec_uint32be(const unsigned char *src);
Return a 32 bit integer decoded in big endian byte order from 4 bytes of src memory.
uint64_t dec_uint64be(const unsigned char *src);
Return a 64 bit integer decoded in big endian byte order from 8 bytes of src memory.
uint16_t dec_uint16le(const unsigned char *src);
Return a 16 bit integer decoded in little endian byte order from 2 bytes of src memory.
uint32_t dec_uint32le(const unsigned char *src);
Return a 32 bit integer decoded in little endian byte order from 4 bytes of src memory.
uint64_t dec_uint64le(const unsigned char *src);
Return a 64 bit integer decoded in little endian byte order from 8 bytes of src memory.
Floating point numbers
size_t enc_floatle(const float f, unsigned char *dst);
Encode a 32 bit real number f into dst in little endian IEEE754 format and return the number of bytes encoded which is always 4.
size_t enc_doublele(const double d, unsigned char *dst);
Encode a 64 bit real number d into dst in little endian IEEE754 format and return the number of bytes encoded which is always 8.
size_t enc_floatbe(const float f, unsigned char *dst);
Encode a 32 bit real number f into dst in big endian IEEE754 format and return the number of bytes encoded which is always 4.
size_t enc_doublebe(const double d, unsigned char *dst);
Encode a 64 bit real number d into dst in big endian IEEE754 format and return the number of bytes encoded which is always 8.
float dec_floatle(const unsigned char *src);
Return a 32 bit real number decoded in little endian IEEE754 format from 4 bytes of src memory.
double dec_doublele(const unsigned char *src);
Return a 64 bit real number decoded in little endian IEEE754 format from 8 bytes of src memory.
float dec_floatbe(const unsigned char *src);
Return a 32 bit real number decoded in big endian IEEE754 format from 4 bytes of src memory.
double dec_doublebe(const unsigned char *src);
Return a 64 bit real number decoded in big endian IEEE754 format from 4 bytes of src memory.
Sting functions
int enc_mbsncpy(const char *src, size_t sn, char **dst, size_t dn, int cn, const char *tocode);
The enc_mbsncpy function encodes the multi-byte string at src into dst using the tocode encoding identifier. The tocode parameter can be one of the standard encoding identifiers such as "UTF-8", "KOI8-R", "ISO-8859-2", etc. See the libiconv documentation for a complete list:
http://www.gnu.org/software/libiconv/
Specifically the enc_mbsncpy function;
- does not read more than sn bytes of src,
- does not write to more than dn bytes of dst,
- does not convert more than cn characters,
- does not convert characters after a '\0' encountered in src,
- advances dst by the number of bytes encoded into dst
- and returns the number of characters converted
int enc_mbscpy(const char *src, char **dst, const char *tocode);
The enc_mbscpy function encodes the multi-byte string at src into dst using the tocode encoding identifier.
The conversion stops when a '\0' character is encountered in src.
This function is equivalent to enc_mbsncpy(src, INT_MAX, dst, INT_MAX, INT_MAX, tocode). See enc_mbsncpy for details.
size_t dec_mbsncpy(char **src, size_t sn, char *dst, size_t dn, int cn, const char *fromcode);
The dec_mbsncpy function decodes the string at src encoded as fromcode to the memory at dst as a locale dependent string (possibly UTF-8). The fromcode parameter can be one of the standard encoding identifiers such as "UTF-8", "KOI8-R", "ISO-8859-2", etc. See the libiconv documentation for a complete list:
http://www.gnu.org/software/libiconv/
More specifically the dec_mbsncpy function;
- does not read more than sn bytes of src,
- does not write to more than dn bytes of dst,
- does not convert more than cn characters,
- does not convert characters after a '\0' encountered in src,
- advances src by the number of bytes decoded,
- and returns the number of bytes written to dst unless a '\0' terminator is not encountered in src in which case one is artifically written to dst but not counted in the return value.
Additionally, if dst is NULL this function
- does not write to dst,
- does not advance the src pointer,
- and returns the exact number of bytes required to encode a multi-byte string had dst not been NULL (i.e. for malloc). This includes the '\0' terminator regardless of wheather one was encountered in src.
size_t dec_mbscpy(char **src, char *dst, const char *fromcode);
The dec_mbscpy function decodes the string at src encoded as fromcode to the memory at dst as a locale dependent string (possibly UTF-8).
The conversion stops when the character '\0' is encountered in src.
This function is equivalent to dec_mbsncpy(src, INT_MAX, dst, INT_MAX, INT_MAX, fromcode);. See dec_mbscpy for details.
char *dec_mbsndup(char **src, size_t sn, size_t dn, int wn, const char *fromcode);
The dec_mbsndup function decodes the string at src encoded as fromcode and returns a locale dependent string (possibly UTF-8) stored in memory allocated with malloc(3). This memory should be freed with free(3) when it will no longer be referenced. This function just calls dec_mbsncpy(src, sn, NULL, dn, wn, fromcode), allocates the precise amount of memory, encodes the string in it with dec_mbsncpy(src, sn, dst, dn, wn, fromcode), and returns the new string.
char *dec_mbsdup(char **src, const char *fromcode);
The dec_mbsdup function decodes the string at src encoded as fromcode and returns a locale dependent string (possibly UTF-8) stored in memory allocated with malloc(3). This memory should be freed with free(3) when it will no longer be referenced. This function is equivalent to dec_mbsndup(src, -1, -1, -1, fromcode). See dec_mbsndup for details.