/* Chart miscellaneous C code headers. Copyright 2005, 2006 Kevin Ryde This file is part of Chart. Chart is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Chart is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Chart; see the file COPYING. If not, write to the Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /*---------------------------------------------------------------------------*/ /* guile 1.8 C stuff make available in guile 1.6 */ #if SCM_MAJOR_VERSION == 1 && SCM_MINOR_VERSION == 6 #define scm_is_false(obj) SCM_FALSEP (obj) #define scm_is_true(obj) SCM_NFALSEP (obj) #define scm_to_int(scm) scm_num2int (scm, SCM_ARGn, "chart C code") #define scm_to_uint(scm) scm_num2uint (scm, SCM_ARGn, "chart C code") #define scm_from_int(n) scm_int2num (n) /* as supported by scm_to_locale_stringn() below */ #define scm_is_string(obj) (SCM_STRINGP (obj) || SCM_SUBSTRP (obj)) #define scm_from_locale_string(str) scm_makfrom0str(str) /* This code is inculded in both misc.c and zlib.c. It's duplicated in the two modules because according to libtool having one module call functions in another isn't portable. */ static void * scm_malloc (size_t size) { char *p = scm_must_malloc (size, "chart"); scm_done_free (size); return p; } static char * scm_to_locale_stringn (SCM str, size_t *lenp) #define FUNC_NAME "scm_to_locale_stringn" { const char *c_str; size_t c_len; char *ret; /* ordinary strings and shared substrings */ SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, "scm_to_locale_stringn", "string"); c_str = SCM_ROCHARS (str); c_len = SCM_STRING_LENGTH (str); if (lenp == NULL) { if (memchr (c_str, '\0', c_len)) scm_misc_error (FUNC_NAME, "string contains #\\nul character: ~S", scm_list_1 (str)); } else *lenp = c_len; ret = scm_malloc (c_len + 1); memcpy (ret, c_str, c_len); scm_remember_upto_here_1 (str); ret[c_len] = '\0'; return ret; } #undef FUNC_NAME static char * scm_to_locale_string (SCM obj) { return scm_to_locale_stringn (obj, NULL); } #endif /*---------------------------------------------------------------------------*/ /* misc helpers */ #define FREE_KEEP_ERRNO(ptr) \ do { \ int __old_errno = errno; \ free (ptr); \ errno = __old_errno; \ } while (0)