|
@@ -63,7 +63,7 @@
|
|
|
|
|
|
/* * * RETURN CODES * * */
|
|
/* * * RETURN CODES * * */
|
|
|
|
|
|
-/**@defgroup rc Return codes
|
|
|
|
|
|
+/**@defgroup rc return codes
|
|
* 0 is success, positive integers (>88800) are warnings, and negative integers
|
|
* 0 is success, positive integers (>88800) are warnings, and negative integers
|
|
* (>-88900) are errors.
|
|
* (>-88900) are errors.
|
|
*
|
|
*
|
|
@@ -228,23 +228,6 @@ typedef LSUP_Key LSUP_QuadKey[4];
|
|
typedef char uuid_str_t[UUIDSTR_SIZE];
|
|
typedef char uuid_str_t[UUIDSTR_SIZE];
|
|
|
|
|
|
|
|
|
|
-/** @brief Make recursive directories.
|
|
|
|
- *
|
|
|
|
- * Modified from
|
|
|
|
- * https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950
|
|
|
|
- */
|
|
|
|
-LSUP_rc
|
|
|
|
-mkdir_p (const char *path, mode_t mode);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Remove a directory recursively, as in Unix "rm -r".
|
|
|
|
- *
|
|
|
|
- * @param[in] path Path of directory to remove.
|
|
|
|
- */
|
|
|
|
-LSUP_rc
|
|
|
|
-rm_r (const char *path);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/** @brief Return an error message for a return code.
|
|
/** @brief Return an error message for a return code.
|
|
*/
|
|
*/
|
|
const char *
|
|
const char *
|
|
@@ -263,61 +246,6 @@ LSUP_strerror (LSUP_rc rc);
|
|
*/
|
|
*/
|
|
#define LSUP_MAX_ERROR LSUP_ENV_ERR
|
|
#define LSUP_MAX_ERROR LSUP_ENV_ERR
|
|
|
|
|
|
-/** @brief Encode a code point using UTF-8.
|
|
|
|
- *
|
|
|
|
- * https://gist.github.com/MightyPork/52eda3e5677b4b03524e40c9f0ab1da5
|
|
|
|
- *
|
|
|
|
- * @author Ondřej Hruška <ondra@ondrovo.com>
|
|
|
|
- *
|
|
|
|
- * @copyright MIT
|
|
|
|
- *
|
|
|
|
- * @param out - output buffer (min 5 characters), will be 0-terminated
|
|
|
|
- * @param utf - code point 0-0x10FFFF
|
|
|
|
- * @return number of bytes on success, 0 on failure (also produces U+FFFD,
|
|
|
|
- * which uses 3 bytes)
|
|
|
|
- */
|
|
|
|
-inline int utf8_encode (const uint32_t utf, unsigned char *out)
|
|
|
|
-{
|
|
|
|
- if (utf <= 0x7F) {
|
|
|
|
- // Plain ASCII
|
|
|
|
- out[0] = (char) utf;
|
|
|
|
- out[1] = 0;
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
- else if (utf <= 0x07FF) {
|
|
|
|
- // 2-byte unicode
|
|
|
|
- out[0] = (char) (((utf >> 6) & 0x1F) | 0xC0);
|
|
|
|
- out[1] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
- out[2] = 0;
|
|
|
|
- return 2;
|
|
|
|
- }
|
|
|
|
- else if (utf <= 0xFFFF) {
|
|
|
|
- // 3-byte unicode
|
|
|
|
- out[0] = (char) (((utf >> 12) & 0x0F) | 0xE0);
|
|
|
|
- out[1] = (char) (((utf >> 6) & 0x3F) | 0x80);
|
|
|
|
- out[2] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
- out[3] = 0;
|
|
|
|
- return 3;
|
|
|
|
- }
|
|
|
|
- else if (utf <= 0x10FFFF) {
|
|
|
|
- // 4-byte unicode
|
|
|
|
- out[0] = (char) (((utf >> 18) & 0x07) | 0xF0);
|
|
|
|
- out[1] = (char) (((utf >> 12) & 0x3F) | 0x80);
|
|
|
|
- out[2] = (char) (((utf >> 6) & 0x3F) | 0x80);
|
|
|
|
- out[3] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
- out[4] = 0;
|
|
|
|
- return 4;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- // error - use replacement character
|
|
|
|
- out[0] = (char) 0xEF;
|
|
|
|
- out[1] = (char) 0xBF;
|
|
|
|
- out[2] = (char) 0xBD;
|
|
|
|
- out[3] = 0;
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
* Only compile debug code in debug mode. Parsing variables for debug and
|
|
* Only compile debug code in debug mode. Parsing variables for debug and
|
|
@@ -403,6 +331,81 @@ inline int utf8_encode (const uint32_t utf, unsigned char *out)
|
|
#define MALLOC_GUARD_NL(var) MALLOC_GUARD((var), NULL) \
|
|
#define MALLOC_GUARD_NL(var) MALLOC_GUARD((var), NULL) \
|
|
#define CALLOC_GUARD_NL(var) CALLOC_GUARD((var), NULL) \
|
|
#define CALLOC_GUARD_NL(var) CALLOC_GUARD((var), NULL) \
|
|
*/
|
|
*/
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Make recursive directories.
|
|
|
|
+ *
|
|
|
|
+ * Modified from
|
|
|
|
+ * https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950
|
|
|
|
+ */
|
|
|
|
+LSUP_rc
|
|
|
|
+mkdir_p (const char *path, mode_t mode);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Remove a directory recursively, as in Unix "rm -r".
|
|
|
|
+ *
|
|
|
|
+ * @param[in] path Path of directory to remove.
|
|
|
|
+ */
|
|
|
|
+LSUP_rc
|
|
|
|
+rm_r (const char *path);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Encode a code point using UTF-8.
|
|
|
|
+ *
|
|
|
|
+ * https://gist.github.com/MightyPork/52eda3e5677b4b03524e40c9f0ab1da5
|
|
|
|
+ *
|
|
|
|
+ * @author Ondřej Hruška <ondra@ondrovo.com>
|
|
|
|
+ *
|
|
|
|
+ * @copyright MIT
|
|
|
|
+ *
|
|
|
|
+ * @param out - output buffer (min 5 characters), will be 0-terminated
|
|
|
|
+ * @param utf - code point 0-0x10FFFF
|
|
|
|
+ * @return number of bytes on success, 0 on failure (also produces U+FFFD,
|
|
|
|
+ * which uses 3 bytes)
|
|
|
|
+ */
|
|
|
|
+inline int utf8_encode (const uint32_t utf, unsigned char *out)
|
|
|
|
+{
|
|
|
|
+ if (utf <= 0x7F) {
|
|
|
|
+ // Plain ASCII
|
|
|
|
+ out[0] = (char) utf;
|
|
|
|
+ out[1] = 0;
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ else if (utf <= 0x07FF) {
|
|
|
|
+ // 2-byte unicode
|
|
|
|
+ out[0] = (char) (((utf >> 6) & 0x1F) | 0xC0);
|
|
|
|
+ out[1] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
+ out[2] = 0;
|
|
|
|
+ return 2;
|
|
|
|
+ }
|
|
|
|
+ else if (utf <= 0xFFFF) {
|
|
|
|
+ // 3-byte unicode
|
|
|
|
+ out[0] = (char) (((utf >> 12) & 0x0F) | 0xE0);
|
|
|
|
+ out[1] = (char) (((utf >> 6) & 0x3F) | 0x80);
|
|
|
|
+ out[2] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
+ out[3] = 0;
|
|
|
|
+ return 3;
|
|
|
|
+ }
|
|
|
|
+ else if (utf <= 0x10FFFF) {
|
|
|
|
+ // 4-byte unicode
|
|
|
|
+ out[0] = (char) (((utf >> 18) & 0x07) | 0xF0);
|
|
|
|
+ out[1] = (char) (((utf >> 12) & 0x3F) | 0x80);
|
|
|
|
+ out[2] = (char) (((utf >> 6) & 0x3F) | 0x80);
|
|
|
|
+ out[3] = (char) (((utf >> 0) & 0x3F) | 0x80);
|
|
|
|
+ out[4] = 0;
|
|
|
|
+ return 4;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // error - use replacement character
|
|
|
|
+ out[0] = (char) 0xEF;
|
|
|
|
+ out[1] = (char) 0xBF;
|
|
|
|
+ out[2] = (char) 0xBD;
|
|
|
|
+ out[3] = 0;
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/// @} END defgroup private
|
|
/// @} END defgroup private
|
|
|
|
|
|
#endif /* _LSUP_CORE_H */
|
|
#endif /* _LSUP_CORE_H */
|