Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Per Cederqvist
lyskom-server-ceder-1616-generations-topgit
Commits
54981ae5
Commit
54981ae5
authored
Jul 06, 1991
by
Per Cederqvist
Browse files
Added s_mem_crea_str and s_size_crea_str.
parent
530e2ee0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/libraries/libmisc/s-string.c
View file @
54981ae5
...
...
@@ -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
;
}
/*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment