#define EXPORT __attribute__ ((visibility("default")))
static str rosie_new_string_from_const(const char *msg) {
size_t len = strlen(msg);
return rosie_new_string((byte_ptr) msg, len);
}
EXPORT
str rosie_string_from(byte_ptr msg, size_t len) {
str retval;
retval.len = len;
retval.ptr = msg;
return retval;
}
EXPORT
str *rosie_string_ptr_from(byte_ptr msg, size_t len) {
str *retval = malloc(sizeof(str));
if (!retval) {
display("Out of memory (new2)");
return NULL;
}
retval->ptr = msg;
retval->len = len;
return retval;
}
EXPORT
str rosie_new_string(byte_ptr msg, size_t len) {
byte_ptr new = malloc(len);
if (!new) {
display("Out of memory (new0)");
return rosie_string_from(NULL, 0);
}
memcpy((char *)new, msg, len);
return rosie_string_from(new, len);
}
EXPORT
str *rosie_new_string_ptr(byte_ptr msg, size_t len) {
str temp = rosie_new_string(msg, len);
return rosie_string_ptr_from(temp.ptr, temp.len);
}
EXPORT
void rosie_free_string_ptr(str *ref) {
if (ref->ptr) free((void *) ref->ptr);
free(ref);
}
EXPORT
void rosie_free_string(str s) {
if (s.ptr) free((void *) s.ptr);
}