From 54981ae5312cb921d794b48bab8be52fc55206b9 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Sat, 6 Jul 1991 07:49:29 +0000 Subject: [PATCH] Added s_mem_crea_str and s_size_crea_str. --- src/libraries/libmisc/s-string.c | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/libraries/libmisc/s-string.c b/src/libraries/libmisc/s-string.c index 850f48e81..ae34c0706 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; +} /* -- GitLab