/* -*- Mode: C -*- Scheme48 Stubber C Support Library Copyright (c) 2009, Taylor R. Campbell Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the authors nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "scheme48.h" #include "s48-stubber.h" #include #include #include #include #include /* Signed and Unsigned Integers */ /* FIXME: This is completely bogus. */ s48_value s48_enter_signed_integer (signed long integer) { return (s48_enter_integer (integer)); } s48_value s48_enter_unsigned_integer (unsigned long integer) { return (s48_enter_integer (integer)); } signed long s48_extract_signed_integer (s48_value integer_s48) { return ((signed long) (s48_extract_integer (integer_s48))); } unsigned long s48_extract_unsigned_integer (s48_value integer_s48) { return ((unsigned long) (s48_extract_integer (integer_s48))); } char * s48_extract_and_copy_string (s48_value string_s48) { char *string = (s48_extract_string (string_s48)); /* Add on one to NUL-terminate. */ size_t length = (1 + (S48_STRING_LENGTH (string_s48))); char *copy = (malloc (length)); if (NULL == copy) s48_raise_out_of_memory_error (); else { (void) memcpy (copy, string, length); (copy [length]) = 0; } return (copy); } char * s48_extract_and_copy_byte_vector (s48_value bv_s48, size_t *length_loc) { char *bv = (s48_extract_byte_vector (bv_s48)); size_t length = (S48_BYTE_VECTOR_LENGTH (bv_s48)); char *copy = (malloc (length)); if (copy == NULL) s48_raise_out_of_memory_error (); else { (void) memcpy (copy, bv, length); (*length_loc) = length; } return (copy); } s48_value s48_enter_asciz_substring (const char *string, size_t offset, size_t size) { return (s48_enter_substring (((char *) (string + offset)), size)); } s48_value s48_enter_and_free_asciz_substring (char *string, size_t offset, size_t size) { s48_value string_s48 = (s48_enter_asciz_substring (string, offset, size)); free (string); return (string_s48); } s48_value s48_enter_byte_subvector (const char *bv, size_t offset, size_t size) { return (s48_enter_byte_vector (((char *) (bv + offset)), size)); } s48_value s48_enter_and_free_byte_subvector (char *bv, size_t offset, size_t size) { s48_value bv_s48 = (s48_enter_byte_subvector (bv, offset, size)); free (bv); return (bv_s48); }