From 070f2bc6df8dadda4483935ba3c026ec9d099903 Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sun, 27 Oct 2002 15:49:41 +0000 Subject: [PATCH] Group portability functions in this file. --- t/src/portability.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ t/src/portability.h | 32 ++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 t/src/portability.c create mode 100644 t/src/portability.h diff --git a/t/src/portability.c b/t/src/portability.c new file mode 100644 index 0000000..e44f7c3 --- /dev/null +++ b/t/src/portability.c @@ -0,0 +1,74 @@ +/* Test program for the Gedcom library. + Copyright (C) 2001, 2002 The Genes Development Team + This file is part of the Gedcom parser library. + Contributed by Peter Verthez , 2001. + + The Gedcom parser library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The Gedcom parser library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Gedcom parser library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* $Id$ */ +/* $Name$ */ + +#include "config.h" + +char* null_str = "(null)"; +char* non_null_ptr = "0x"; +char* null_ptr = "0x"; + +char* str_val(char* input) +{ + if (input) + return input; + else + return null_str; +} + +char* ptr_val(void* ptr) +{ + if (ptr) + return non_null_ptr; + else + return null_ptr; +} + +long int void_ptr_to_int(void* ptr) +{ + long int i; +#if SIZEOF_VOID_P == 4 + i = (int)ptr; +#else +# if SIZEOF_VOID_P == 8 + i = (long int)ptr; +# else +# error "Unhandled case for size of void pointer!" +# endif +#endif + return i; +} + +void* int_to_void_ptr(int i) +{ +#if SIZEOF_VOID_P == 4 + int t; +#else +# if SIZEOF_VOID_P == 8 + long int t; +# else +# error "Unhandled case for size of void pointer!" +# endif +#endif + t = i; + return (void*)t; +} diff --git a/t/src/portability.h b/t/src/portability.h new file mode 100644 index 0000000..0aa2bb9 --- /dev/null +++ b/t/src/portability.h @@ -0,0 +1,32 @@ +/* Header for test program for the Gedcom library. + Copyright (C) 2001, 2002 The Genes Development Team + This file is part of the Gedcom parser library. + Contributed by Peter Verthez , 2001. + + The Gedcom parser library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The Gedcom parser library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Gedcom parser library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* $Id$ */ +/* $Name$ */ + +#ifndef __PORTABILITY_H +#define __PORTABILITY_H + +long int void_ptr_to_int(void* ptr); +void* int_to_void_ptr(int t); +char* str_val(char* input); +char* ptr_val(void* ptr); + +#endif /* __PORTABILITY_H */ -- 2.30.2