|
|
@@ -1,24 +1,36 @@
|
|
|
#include "toolbox/cstr_fixed.h"
|
|
|
-#include "toolbox/cstring.h"
|
|
|
|
|
|
-#include <stdbool.h>
|
|
|
#include <stddef.h>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#include "toolbox/cstring.h"
|
|
|
+#include "toolbox/errno.h"
|
|
|
+#include "toolbox/errcode.h"
|
|
|
+
|
|
|
+#define false 0
|
|
|
+#define true 1
|
|
|
|
|
|
struct cstr_fixed
|
|
|
cstr_fixed_from_cstring(const char *cstring) {
|
|
|
+ toolbox_errno = RET_OK;
|
|
|
struct cstr_fixed ret = {
|
|
|
.size = cstring_len(cstring),
|
|
|
.data = {0}
|
|
|
};
|
|
|
- for(size_t i = 0; i < ret.size; ++i ) {
|
|
|
- ret.data[i] = *(cstring + i);
|
|
|
+
|
|
|
+ if ( ret.size > TOOLBOX_CSTR_FIXED_MAX_SIZE ) {
|
|
|
+ toolbox_errno = RET_EVBTS;
|
|
|
+ return ret;
|
|
|
}
|
|
|
+
|
|
|
+ memcpy(ret.data, cstring, ret.size);
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
_Bool
|
|
|
cstr_fixed_equal(const struct cstr_fixed cstr_fixed1
|
|
|
- , const struct cstr_fixed cstr_fixed2) {
|
|
|
+ , const struct cstr_fixed cstr_fixed2) {
|
|
|
if ( cstr_fixed1.size != cstr_fixed2.size ) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -32,6 +44,9 @@ cstr_fixed_equal(const struct cstr_fixed cstr_fixed1
|
|
|
|
|
|
_Bool
|
|
|
cstr_fixed_equal_cstring(const struct cstr_fixed cstr_fixed
|
|
|
- , const char *cstring) {
|
|
|
+ , const char *cstring) {
|
|
|
return cstr_fixed_equal(cstr_fixed, cstr_fixed_from_cstring(cstring));
|
|
|
}
|
|
|
+
|
|
|
+#undef false
|
|
|
+#undef true
|