Mercurial > ecos
changeset 1542:f8ef9a4bea92
* include/string.h: Prototype strdup().
* include/stringsupp.hxx: Prototype __strdup().
externC -> __externC while I'm here.
* src/strdup.cxx: New file implementing strdup()/__strdup().
* cdl/string.cdl: Build strdup.cxx if CYGINT_ISO_MALLOC.
* src/strtok.cxx (strtok): Use correct thread data type.
| author | jlarmour |
|---|---|
| date | Mon, 15 Mar 2004 15:22:00 +0000 |
| parents | 871b38a618f4 |
| children | 8e86927fb409 |
| files | packages/language/c/libc/string/current/ChangeLog packages/language/c/libc/string/current/cdl/string.cdl packages/language/c/libc/string/current/include/string.h packages/language/c/libc/string/current/include/stringsupp.hxx packages/language/c/libc/string/current/src/strdup.cxx packages/language/c/libc/string/current/src/strtok.cxx |
| diffstat | 6 files changed, 152 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/language/c/libc/string/current/ChangeLog +++ b/packages/language/c/libc/string/current/ChangeLog @@ -1,3 +1,13 @@ +2004-02-20 Jonathan Larmour <jifl@eCosCentric.com> + + * include/string.h: Prototype strdup(). + * include/stringsupp.hxx: Prototype __strdup(). + externC -> __externC while I'm here. + * src/strdup.cxx: New file implementing strdup()/__strdup(). + * cdl/string.cdl: Build strdup.cxx if CYGINT_ISO_MALLOC. + + * src/strtok.cxx (strtok): Use correct thread data type. + 2003-02-24 Jonathan Larmour <jifl@eCosCentric.com> * cdl/string.cdl: Fix doc link.
--- a/packages/language/c/libc/string/current/cdl/string.cdl +++ b/packages/language/c/libc/string/current/cdl/string.cdl @@ -158,6 +158,15 @@ cdl_package CYGPKG_LIBC_STRING { } } + cdl_option CYGFUN_LIBC_STRING_STRDUP { + display "strdup" + active_if CYGINT_ISO_MALLOC + calculated 1 + compile strdup.cxx + description " + This option indicates whether strdup() is to be supported." + } + cdl_component CYGPKG_LIBC_STRING_OPTIONS { display "C library string functions build options" flavor none
--- a/packages/language/c/libc/string/current/include/string.h +++ b/packages/language/c/libc/string/current/include/string.h @@ -150,6 +150,12 @@ strtok_r( char *, const char *, char ** extern size_t strlen( const char * ); +// NB This is a BSD function +#ifndef __STRICT_ANSI__ +extern char * +strdup( const char * ); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif
--- a/packages/language/c/libc/string/current/include/stringsupp.hxx +++ b/packages/language/c/libc/string/current/include/stringsupp.hxx @@ -68,8 +68,8 @@ #ifndef CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST // Masks for CYG_LIBC_STR_DETECTNULL below -externC const cyg_uint64 Cyg_libc_str_null_mask_1; -externC const cyg_uint64 Cyg_libc_str_null_mask_2; +__externC const cyg_uint64 Cyg_libc_str_null_mask_1; +__externC const cyg_uint64 Cyg_libc_str_null_mask_2; #endif @@ -111,15 +111,15 @@ externC const cyg_uint64 Cyg_libc_str_nu // 7.11.2 Copying functions -externC void * +__externC void * __memmove( void *, const void *, size_t ); -externC char * +__externC char * __strcpy( char *, const char * ); -externC char * +__externC char * __strncpy( char *, const char *, size_t ); @@ -128,11 +128,11 @@ externC char * // 7.11.3 Concatenation functions -externC char * +__externC char * __strcat( char *, const char * ); -externC char * +__externC char * __strncat( char *, const char *, size_t ); @@ -140,23 +140,23 @@ externC char * // 7.11.4 Comparison functions -externC int +__externC int __memcmp( const void *, const void *, size_t ); -externC int +__externC int __strcmp( const char *, const char * ); -externC int +__externC int __strcoll( const char *, const char * ); -externC int +__externC int __strncmp( const char *, const char *, size_t ); -externC size_t +__externC size_t __strxfrm( char *, const char *, size_t ); @@ -165,40 +165,40 @@ externC size_t // 7.11.5 Search functions -externC void * +__externC void * __memchr( const void *, int , size_t ); -externC char * +__externC char * __strchr( const char *, int ); -externC size_t +__externC size_t __strcspn( const char *, const char * ); -externC char * +__externC char * __strpbrk( const char *, const char * ); -externC char * +__externC char * __strrchr( const char *, int ); -externC size_t +__externC size_t __strspn( const char *, const char * ); -externC char * +__externC char * __strstr( const char *, const char * ); -externC char * +__externC char * __strtok( char *, const char * ); // For POSIX 1003.1 section 8.3.3 strtok_r() -externC char * +__externC char * __strtok_r( char *, const char *, char ** ); @@ -206,9 +206,13 @@ externC char * // 7.11.6 Miscellaneous functions -externC size_t +__externC size_t __strlen( const char * ); +// NB This is a BSD function +__externC char * +__strdup( const char * ); + #endif // CYGONCE_LIBC_STRING_STRINGSUPP_HXX multiple inclusion protection // EOF stringsupp.hxx
new file mode 100644 --- /dev/null +++ b/packages/language/c/libc/string/current/src/strdup.cxx @@ -0,0 +1,96 @@ +//=========================================================================== +// +// strdup.cxx +// +// BSD strdup() routine +// +//=========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 2004 eCosCentric Ltd. +// +// eCos 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. +// +// eCos 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 eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//=========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): jlarmour +// Contributors: +// Date: 2004-02-17 +// Purpose: +// Description: +// Usage: +// +//####DESCRIPTIONEND#### +// +//=========================================================================== + +// CONFIGURATION + +#include <pkgconf/libc_string.h> // Configuration header + +// INCLUDES + +#include <cyg/infra/cyg_type.h> // Common type definitions +#include <cyg/infra/cyg_trac.h> // Tracing support +#include <cyg/infra/cyg_ass.h> // Assertion support +#include <string.h> // Header for this file +#include <stddef.h> // Compiler definitions such as size_t, NULL etc. +#include <stdlib.h> // malloc() +#include <cyg/libc/string/stringsupp.hxx> // Useful string function support and + // prototypes + +// EXPORTED SYMBOLS + +__externC char * +strdup( const char * ) CYGBLD_ATTRIB_WEAK_ALIAS(__strdup); + +// FUNCTIONS + +char * +__strdup( const char *s1 ) +{ + char *newstring; + size_t len; + + CYG_REPORT_FUNCNAMETYPE( "__strdup", "returning addr %08x" ); + CYG_REPORT_FUNCARG1( "s1=%08x", s1 ); + + CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" ); + + len = strlen( s1 ) + 1; + newstring = (char *)malloc( len ); + if ( newstring ) + { + memcpy( newstring, s1, len ); + } // if + + CYG_REPORT_RETVAL( newstring ); + + return newstring; +} // __strdup() + +// EOF strdup.cxx
--- a/packages/language/c/libc/string/current/src/strtok.cxx +++ b/packages/language/c/libc/string/current/src/strtok.cxx @@ -116,7 +116,9 @@ static int strtok_trace = CYGNUM_LIBC_ST // STATICS #ifdef CYGSEM_LIBC_STRING_PER_THREAD_STRTOK -static cyg_ucount32 strtok_data_index=CYGNUM_KERNEL_THREADS_DATA_MAX; +static Cyg_Thread::cyg_data_index +strtok_data_index=CYGNUM_KERNEL_THREADS_DATA_MAX; + static Cyg_Mutex strtok_data_mutex CYG_INIT_PRIORITY(LIBC); #else static char *cyg_libc_strtok_last; @@ -147,11 +149,11 @@ strtok( char *s1, const char *s2 ) strtok_data_mutex.lock(); if (CYGNUM_KERNEL_THREADS_DATA_MAX==strtok_data_index) { - // the kernel just throws an assert if this doesn't work // FIXME: Should use real CDL to pre-allocate a slot at compile // time to ensure there are enough slots strtok_data_index = self->new_data_index(); - + CYG_ASSERT(strtok_data_index >= 0, + "failed to allocate data index" ); } strtok_data_mutex.unlock(); } // if
