#ifndef _di_f_socket_file_bind_
f_status_t f_socket_file_bind(const f_string_t path, const int id, struct sockaddr_un *address) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!address) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
- memset(&address, 0, sizeof(struct sockaddr_un));
+ memset(address, 0, sizeof(struct sockaddr_un));
address->sun_family = AF_UNIX;
strncpy(address->sun_path, path, sizeof(address->sun_path) - 1);
f_status_t f_utf_character_to_char(const f_utf_character_t utf_character, f_string_t *character, f_array_length_t *width_max) {
#ifndef _di_level_0_parameter_checking_
if (!utf_character) return F_status_set_error(F_parameter);
- if (!width_max && *character) return F_status_set_error(F_parameter);
- if (width_max && !*character) return F_status_set_error(F_parameter);
- if (width_max && *width_max > 4) return F_status_set_error(F_parameter);
+ if (!character) return F_status_set_error(F_parameter);
+ if (!width_max) return F_status_set_error(F_parameter);
+ if (!*width_max) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- f_status_t status = F_none;
-
- uint8_t width = macro_f_utf_character_t_width_is(utf_character);
-
- if (!width_max) {
- macro_f_string_t_clear((*character))
- macro_f_string_t_resize(status, (*character), 0, width)
- if (F_status_is_error(status)) return status;
-
- width = 1;
- *width_max = 1;
- }
- else if (width == 1) {
- return F_status_is_error(F_utf);
- }
- else if (width > *width_max) {
- return F_status_set_error(F_failure);
- }
-
- *width_max = width;
+ if (macro_f_utf_character_t_width_is(utf_character)) {
+
+ // @todo: endianess is compile time so a function is not needed, replace with macros.
+ if (f_utf_is_big_endian()) {
+ memcpy(*character, &utf_character, macro_f_utf_character_t_width_is(utf_character));
+ }
+ else {
+ uint32_t utf = 0;
+
+ switch (macro_f_utf_character_t_width_is(utf_character)) {
+ case 1:
+ utf = macro_f_utf_character_t_to_char_1(utf_character) << 24;
+ break;
+ case 2:
+ utf = (macro_f_utf_character_t_to_char_2(utf_character) << 24) | (macro_f_utf_character_t_to_char_1(utf_character) << 16);
+ break;
+ case 3:
+ utf = (macro_f_utf_character_t_to_char_3(utf_character) << 24) | (macro_f_utf_character_t_to_char_2(utf_character) << 16) | (macro_f_utf_character_t_to_char_1(utf_character) << 8);
+ break;
+ case 4:
+ utf = (macro_f_utf_character_t_to_char_4(utf_character) << 24) | (macro_f_utf_character_t_to_char_3(utf_character) << 16) | (macro_f_utf_character_t_to_char_2(utf_character) << 8) | macro_f_utf_character_t_to_char_1(utf_character);
+ break;
+ default:
+ return F_status_set_error(F_failure);
+ }
- if (f_utf_is_big_endian()) {
- memcpy(*character, &utf_character, width);
+ memcpy(*character, &utf, macro_f_utf_character_t_width_is(utf_character));
+ }
}
else {
- uint32_t utf = 0;
- if (width == 1) {
- utf = macro_f_utf_character_t_to_char_1(utf_character) << 24;
- }
- else if (width == 2) {
- utf = (macro_f_utf_character_t_to_char_2(utf_character) << 24) | (macro_f_utf_character_t_to_char_1(utf_character) << 16);
- }
- else if (width == 3) {
- utf = (macro_f_utf_character_t_to_char_3(utf_character) << 24) | (macro_f_utf_character_t_to_char_2(utf_character) << 16) | (macro_f_utf_character_t_to_char_1(utf_character) << 8);
- }
- else if (width == 4) {
- utf = (macro_f_utf_character_t_to_char_4(utf_character) << 24) | (macro_f_utf_character_t_to_char_3(utf_character) << 16) | (macro_f_utf_character_t_to_char_2(utf_character) << 8) | macro_f_utf_character_t_to_char_1(utf_character);
+ // @todo: endianess is compile time so a function is not needed, replace with macros.
+ if (f_utf_is_big_endian()) {
+ memcpy(*character, &utf_character, 1);
}
+ else {
+ uint32_t utf = macro_f_utf_character_t_to_char_1(utf_character) << 24;
- memcpy(*character, &utf, width);
+ memcpy(*character, &utf, 1);
+ }
}
return F_none;
* Convert a specialized f_utf_character_t type to a uint8_t, stored as a string (character buffer).
*
* This will also convert ASCII characters stored in the utf_character array.
+ * This will not resize character.
*
* @param utf_character
- * The UTF-8 characterr to convert from.
+ * The UTF-8 character to convert from.
* @param character
* A uint8_t representation of the UTF-8 character, stored as a string of width bytes.
- * If width_max is 0, then this should not be allocated (set the pointer address to 0).
+ * If width_max is 0, then this should be set to 0.
* @param width_max
- * The number of bytes the generated character represents.
- * If this is set to 0, then the character will be allocated and this will be set to the width of the utf_character.
- * If this is set to some value greater than 0 (up to 4), then this represents the size of the character array (no allocations are performed).
- * If this is greater than 0, and the utf_character width is larger than this size, then an error is returned.
+ * This is set to the max number of bytes available.
+ * This is then updated to represent the max bytes used if enough space is available.
*
* @return
* F_none if conversion was successful.
*
* F_failure (with error bit) if width is not long enough to convert.
* F_parameter (with error bit) if a parameter is invalid.
- * F_memory_not (with error bit) on out of memory.
* F_utf (with error bit) if character is an invalid UTF-8 character.
- * F_failure (with error bit) if width is not long enough to convert.
*/
#ifndef _di_f_utf_character_to_char_
extern f_status_t f_utf_character_to_char(const f_utf_character_t utf_character, f_string_t *character, f_array_length_t *width_max);