Commit 54981ae5 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Added s_mem_crea_str and s_size_crea_str.

parent 530e2ee0
......@@ -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;
}
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment