diff options
author | Stefan Jahn <stefan@lkcc.org> | 2002-01-28 21:15:55 +0000 |
---|---|---|
committer | Stefan Jahn <stefan@lkcc.org> | 2002-01-28 21:15:55 +0000 |
commit | af68e5e5a6d30dde274191530556b565dead45aa (patch) | |
tree | ec22e62374eabb7fe3f97dcb5ccef75b4464b304 /libguile/strings.c | |
parent | 962b1f0bacacb920e43a2e8d156e51b46b8f5197 (diff) | |
download | guile-af68e5e5a6d30dde274191530556b565dead45aa.tar.gz |
2002-01-28 Stefan Jahn <stefan@lkcc.org>
* configure.in (guile_cv_have_uint32_t): Look also in
`stdint.h' for uint32_t.
2002-01-28 Stefan Jahn <stefan@lkcc.org>
* symbols.c (scm_c_symbol2str): New function, replacement for
`gh_scm2newsymbol()'.
* strings.c (scm_c_substring2str): New function. Proper
replacement for `gh_get_substr()'.
* socket.c: Include `stdint.h' if available for the `uint32_t'
declaration.
* scmsigs.c (s_scm_sigaction): Initialize `chandler' (inhibits
compiler warning).
* backtrace.c: Include `lang.h' for GUILE_DEBUG conditional.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 3aa24958d..6744a58c6 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -350,12 +350,13 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1, determine the length of the returned value. However, the function always copies the complete contents of OBJ, and sets *LENP to the length of the scheme string (if LENP is non-null). */ +#define FUNC_NAME "scm_c_string2str" char * scm_c_string2str (SCM obj, char *str, size_t *lenp) { size_t len; - SCM_ASSERT (SCM_STRINGP (obj), obj, SCM_ARG1, "scm_c_string2str"); + SCM_ASSERT (SCM_STRINGP (obj), obj, SCM_ARG1, FUNC_NAME); len = SCM_STRING_LENGTH (obj); if (str == NULL) @@ -376,6 +377,30 @@ scm_c_string2str (SCM obj, char *str, size_t *lenp) return str; } +#undef FUNC_NAME + + +/* Copy LEN characters at START from the Scheme string OBJ to memory + at STR. START is an index into OBJ; zero means the beginning of + the string. STR has already been allocated by the caller. + + If START + LEN is off the end of OBJ, silently truncate the source + region to fit the string. If truncation occurs, the corresponding + area of STR is left unchanged. */ +#define FUNC_NAME "scm_c_substring2str" +char * +scm_c_substring2str (SCM obj, char *str, size_t start, size_t len) +{ + size_t src_length, effective_length; + + SCM_ASSERT (SCM_STRINGP (obj), obj, SCM_ARG2, FUNC_NAME); + src_length = SCM_STRING_LENGTH (obj); + effective_length = (len + start <= src_length) ? len : src_length - start; + memcpy (str, SCM_STRING_CHARS (obj) + start, effective_length); + scm_remember_upto_here_1 (obj); + return str; +} +#undef FUNC_NAME void |