diff --git a/src/libraries/libmisc/s-string.c b/src/libraries/libmisc/s-string.c index 850f48e81e7b1e44769b091fa54426c75ff75787..ae34c0706a87b4f8c3977131dce0f05f0d4df9c5 100644 --- a/src/libraries/libmisc/s-string.c +++ b/src/libraries/libmisc/s-string.c @@ -120,6 +120,69 @@ s_crea_str (String * dest_string, return OK; } +/* + * Create a string from a buffer. The contents of the buffer + * are copied into the new string. + */ + +EXPORT Success +s_mem_crea_str (String * dest_string, + const char * buffer, + String_size length) +{ + void * temp_ptr; /* To hold result from malloc/realloc + * before actually using it. */ + + temp_ptr = MALLOC_0 (length); + if (temp_ptr == NULL) + { + return FAILURE; + } + + if ( dest_string->string == NULL ) + ++no_of_allocated_strings; + + FREE_0 (dest_string->string); + dest_string->string = temp_ptr; + + memcpy(dest_string->string, buffer, length); + dest_string->len = length; + + return OK; +} + + +/* + * Create a string of a given size. The contents of the string + * are unspecified. The LysKOM-server uses this to get a string + * of a fixed size into which it can fread() data. This is probably + * not a good idea since it relies heavily on the implementation + * of strings. However, by using this function, those places are + * easy to identify if the implementation should be done differently. + */ + +EXPORT Success +s_size_crea_str(String *result, + String_size length) +{ + void * temp_ptr; /* To hold result from malloc/realloc + * before actually using it. */ + + temp_ptr = MALLOC_0 (length); + if (temp_ptr == NULL) + { + return FAILURE; + } + + if ( result->string == NULL ) + ++no_of_allocated_strings; + + FREE_0 (result->string); + result->string = temp_ptr; + result->len = length; + + return OK; +} /*