forked from KolibriOS/kolibrios
Clib string & memory functions
git-svn-id: svn://kolibrios.org@553 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
45
programs/develop/open watcom/trunk/clib/memory/bcmp.c
Normal file
45
programs/develop/open watcom/trunk/clib/memory/bcmp.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK int bcmp( const void *s1, const void *s2, size_t n )
|
||||
/************************************************************/
|
||||
{
|
||||
if( memcmp( s1, s2, n ) == 0 ) {
|
||||
return( 0 );
|
||||
} else {
|
||||
return( 1 );
|
||||
}
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/memory/bcopy.c
Normal file
41
programs/develop/open watcom/trunk/clib/memory/bcopy.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK void bcopy( const void *s1, void *s2, size_t n )
|
||||
/********************************************************/
|
||||
{
|
||||
memmove( s2, s1, n );
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/memory/bzero.c
Normal file
41
programs/develop/open watcom/trunk/clib/memory/bzero.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
_WCRTLINK void bzero( void *s, size_t n )
|
||||
/***************************************/
|
||||
{
|
||||
memset( s, 0, n );
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/fmemccpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/fmemccpy.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemccpy( void _WCFAR *d, const void _WCFAR *s, int c, size_t cnt )
|
||||
{
|
||||
char _WCFAR *dst = d;
|
||||
const char _WCFAR *src = s;
|
||||
for(;;) {
|
||||
if( cnt == 0 ) break;
|
||||
*dst = *src;
|
||||
++dst;
|
||||
if( *src == c ) return( dst );
|
||||
++src;
|
||||
--cnt;
|
||||
}
|
||||
return( NULL );
|
||||
}
|
56
programs/develop/open watcom/trunk/clib/memory/fmemchr.c
Normal file
56
programs/develop/open watcom/trunk/clib/memory/fmemchr.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fmemchr().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include "xstring.h"
|
||||
|
||||
/* locate the first occurrence of c in the initial n characters of the
|
||||
object pointed to by s.
|
||||
If the character c is not found, NULL is returned.
|
||||
*/
|
||||
|
||||
#undef _fmemchr
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemchr( const void _WCFAR *vs, int c, size_t n )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemchr( vs, c, n ) );
|
||||
#else
|
||||
const char _WCFAR *s = vs;
|
||||
while( n ) {
|
||||
if( *s == c ) return( (void _WCFAR *)s );
|
||||
++s;
|
||||
--n;
|
||||
}
|
||||
return( NULL );
|
||||
#endif
|
||||
}
|
52
programs/develop/open watcom/trunk/clib/memory/fmemcmp.c
Normal file
52
programs/develop/open watcom/trunk/clib/memory/fmemcmp.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
#undef _fmemcmp
|
||||
|
||||
_WCRTLINK int _fmemcmp( const void _WCFAR *v1,
|
||||
const void _WCFAR *v2, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemcmp( v1, v2, len ) );
|
||||
#else
|
||||
const unsigned char _WCFAR *s1 = v1;
|
||||
const unsigned char _WCFAR *s2 = v2;
|
||||
for( ; len; --len ) {
|
||||
if( *s1 != *s2 ) return( *s1 - *s2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
#endif
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/fmemcpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/fmemcpy.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "xstring.h"
|
||||
#undef _fmemcpy
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemcpy( void _WCFAR *dst, const void _WCFAR *s, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemcpy( dst, s, len ) );
|
||||
#else
|
||||
const char _WCFAR *src = s;
|
||||
char _WCFAR *p;
|
||||
for( p = dst; len; --len ) {
|
||||
*p++ = *src++;
|
||||
}
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
54
programs/develop/open watcom/trunk/clib/memory/fmemicmp.c
Normal file
54
programs/develop/open watcom/trunk/clib/memory/fmemicmp.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
_WCRTLINK int _fmemicmp( const void _WCFAR *v1, const void _WCFAR *v2, size_t len )
|
||||
{
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
const unsigned char _WCFAR *s1;
|
||||
const unsigned char _WCFAR *s2;
|
||||
|
||||
for( s1 = v1, s2 = v2 ; len; --len ) {
|
||||
c1 = *s1;
|
||||
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
|
||||
c2 = *s2;
|
||||
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
|
||||
if( c1 != c2 ) return( c1 - c2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
}
|
166
programs/develop/open watcom/trunk/clib/memory/fmemmove.c
Normal file
166
programs/develop/open watcom/trunk/clib/memory/fmemmove.c
Normal file
@@ -0,0 +1,166 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__386__)
|
||||
|
||||
#if defined(__FLAT__)
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x06 /* push es */\
|
||||
0x8e 0xc2 /* mov es,dx */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg esi,eax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0x66 0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
0x07 /* pop es */\
|
||||
parm [dx edi] [si eax] [ecx] \
|
||||
modify exact [edi esi ecx eax];
|
||||
#else
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg esi,eax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0x66 0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es edi] [si eax] [ecx] \
|
||||
modify exact [edi esi ecx eax];
|
||||
#endif
|
||||
|
||||
#elif defined(M_I86)
|
||||
#if defined(__SMALL_DATA__)
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0xfd /* std */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
#else
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0xfd /* std */\
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */\
|
||||
0x96 /* xchg si,ax */\
|
||||
0x8e 0xd8 /* mov ds,ax */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */\
|
||||
parm [es di] [si ax] [cx] \
|
||||
modify exact [di si cx ax];
|
||||
#endif
|
||||
#else
|
||||
#error platform not supported
|
||||
#endif
|
||||
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemmove( void _WCFAR *t, const void _WCFAR *f, size_t len )
|
||||
{
|
||||
char _WCFAR *to = t;
|
||||
const char _WCFAR *from = f;
|
||||
if( from == to ) {
|
||||
return( to );
|
||||
}
|
||||
if( from < to && from + len > to ) { /* if buffers are overlapped*/
|
||||
#if defined(__HUGE__) || defined(__386__)
|
||||
to += len;
|
||||
from += len;
|
||||
while( len != 0 ) {
|
||||
to--;
|
||||
from--;
|
||||
*to = *from;
|
||||
len--;
|
||||
}
|
||||
#else
|
||||
movebwd(( to + len ) - 1, ( from + len ) - 1, len );
|
||||
#endif
|
||||
} else {
|
||||
movefwd( to, from, len );
|
||||
}
|
||||
return( to );
|
||||
}
|
||||
|
51
programs/develop/open watcom/trunk/clib/memory/fmemset.c
Normal file
51
programs/develop/open watcom/trunk/clib/memory/fmemset.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include "xstring.h"
|
||||
|
||||
#undef _fmemset
|
||||
|
||||
_WCRTLINK void _WCFAR *_fmemset( void _WCFAR *dst, int c, size_t len )
|
||||
{
|
||||
|
||||
#if defined(__INLINE_FUNCTIONS__)
|
||||
return( _inline__fmemset( dst, c, len ) );
|
||||
#else
|
||||
char _WCFAR *p;
|
||||
for( p = dst; len; --len ) {
|
||||
*p++ = c;
|
||||
}
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/memory/memccpy.c
Normal file
49
programs/develop/open watcom/trunk/clib/memory/memccpy.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
|
||||
_WCRTLINK void *memccpy( void *d, const void *s, int c, size_t cnt )
|
||||
{
|
||||
char *dst = d;
|
||||
const char *src = s;
|
||||
for(;;) {
|
||||
if( cnt == 0 ) break;
|
||||
*dst = *src;
|
||||
++dst;
|
||||
if( *src == c ) return( dst );
|
||||
++src;
|
||||
--cnt;
|
||||
}
|
||||
return( NULL );
|
||||
}
|
59
programs/develop/open watcom/trunk/clib/memory/memchr.c
Normal file
59
programs/develop/open watcom/trunk/clib/memory/memchr.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memchr() and wmemchr().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
/* locate the first occurrence of c in the initial n characters of the
|
||||
object pointed to by s.
|
||||
If the character c is not found, NULL is returned.
|
||||
*/
|
||||
|
||||
_WCRTLINK VOID_WC_TYPE *__F_NAME(memchr,wmemchr)( const VOID_WC_TYPE *s, INT_WC_TYPE c, size_t n )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
return( _inline_memchr( s, c, n ) );
|
||||
#else
|
||||
const CHAR_TYPE *cs = s;
|
||||
|
||||
while( n ) {
|
||||
if( *cs == c ) {
|
||||
return( (VOID_WC_TYPE *)cs );
|
||||
}
|
||||
++cs;
|
||||
--n;
|
||||
}
|
||||
return( NULL );
|
||||
#endif
|
||||
}
|
56
programs/develop/open watcom/trunk/clib/memory/memcmp.c
Normal file
56
programs/develop/open watcom/trunk/clib/memory/memcmp.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memcmp() and wmemcmp().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(memcmp,wmemcmp)( const VOID_WC_TYPE *in_s1, const VOID_WC_TYPE *in_s2, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
return( _inline_memcmp( in_s1, in_s2, len ) );
|
||||
#else
|
||||
const CHAR_TYPE *s1 = in_s1;
|
||||
const CHAR_TYPE *s2 = in_s2;
|
||||
|
||||
for( ; len; --len ) {
|
||||
if( *s1 != *s2 ) {
|
||||
return( *s1 - *s2 );
|
||||
}
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
#endif
|
||||
}
|
52
programs/develop/open watcom/trunk/clib/memory/memcpy.c
Normal file
52
programs/develop/open watcom/trunk/clib/memory/memcpy.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memcpy() and wmemcpy().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
|
||||
_WCRTLINK VOID_WC_TYPE *__F_NAME(memcpy,wmemcpy)( VOID_WC_TYPE *in_dst, const VOID_WC_TYPE *in_src, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
return( _inline_memcpy( in_dst, in_src, len ) );
|
||||
#else
|
||||
CHAR_TYPE *dst = in_dst;
|
||||
const CHAR_TYPE *src = in_src;
|
||||
|
||||
for( ; len; --len ) {
|
||||
*dst++ = *src++;
|
||||
}
|
||||
return( in_dst );
|
||||
#endif
|
||||
}
|
75
programs/develop/open watcom/trunk/clib/memory/memcpy_s.c
Normal file
75
programs/develop/open watcom/trunk/clib/memory/memcpy_s.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memcpy_s() - bounds-checking memcpy().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(memcpy_s,wmemcpy_s)( VOID_WC_TYPE * __restrict s1,
|
||||
rsize_t s1max,
|
||||
const VOID_WC_TYPE * __restrict s2,
|
||||
rsize_t n )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
// Verify runtime-constraints
|
||||
// s1 not NULL
|
||||
// s2 not NULL
|
||||
// s1max <= RSIZE_MAX
|
||||
// n <= RSIZE_MAX
|
||||
// n <= s1max
|
||||
// s1 and s2 no overlap
|
||||
if( __check_constraint_nullptr_msg( msg, s1 ) &&
|
||||
__check_constraint_nullptr_msg( msg, s2 ) &&
|
||||
__check_constraint_maxsize_msg( msg, s1max ) &&
|
||||
__check_constraint_maxsize_msg( msg, n ) &&
|
||||
__check_constraint_a_gt_b_msg( msg, n, s1max ) &&
|
||||
__check_constraint_overlap_msg( msg, s1, s1max, s2, n ) ) {
|
||||
|
||||
// now it's safe to use memcpy
|
||||
__F_NAME(memcpy,wmemcpy)( s1, s2, n );
|
||||
rc = 0;
|
||||
} else {
|
||||
// Runtime-constraints violated, zero out destination array
|
||||
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
|
||||
__F_NAME(memset,wmemset)( s1, 0, s1max );
|
||||
}
|
||||
// Now call the handler
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
|
||||
return( rc );
|
||||
}
|
54
programs/develop/open watcom/trunk/clib/memory/memicmp.c
Normal file
54
programs/develop/open watcom/trunk/clib/memory/memicmp.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
_WCRTLINK int memicmp( const void *in_s1, const void *in_s2, size_t len )
|
||||
{
|
||||
const unsigned char * s1 = (const unsigned char *)in_s1;
|
||||
const unsigned char * s2 = (const unsigned char *)in_s2;
|
||||
unsigned char c1;
|
||||
unsigned char c2;
|
||||
|
||||
for( ; len; --len ) {
|
||||
c1 = *s1;
|
||||
c2 = *s2;
|
||||
if( c1 >= 'A' && c1 <= 'Z' ) c1 += 'a' - 'A';
|
||||
if( c2 >= 'A' && c2 <= 'Z' ) c2 += 'a' - 'A';
|
||||
if( c1 != c2 ) return( c1 - c2 );
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return( 0 ); /* both operands are equal */
|
||||
}
|
74
programs/develop/open watcom/trunk/clib/memory/memmov_s.c
Normal file
74
programs/develop/open watcom/trunk/clib/memory/memmov_s.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memmove_s() - bounds-checking memmove().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(memmove_s,wmemmove_s)( VOID_WC_TYPE * __restrict s1,
|
||||
rsize_t s1max,
|
||||
const VOID_WC_TYPE * __restrict s2,
|
||||
rsize_t n )
|
||||
/*******************************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
|
||||
// Verify runtime-constraints
|
||||
// s1 not NULL
|
||||
// s2 not NULL
|
||||
// s1max <= RSIZE_MAX
|
||||
// n <= RSIZE_MAX
|
||||
// n <= s1max
|
||||
if( __check_constraint_nullptr_msg( msg, s1 ) &&
|
||||
__check_constraint_nullptr_msg( msg, s2 ) &&
|
||||
__check_constraint_maxsize_msg( msg, s1max ) &&
|
||||
__check_constraint_maxsize_msg( msg, n ) &&
|
||||
__check_constraint_a_gt_b_msg( msg, n, s1max ) ) {
|
||||
|
||||
/* now it's safe to use memmove */
|
||||
__F_NAME(memmove,wmemmove)( s1, s2, n );
|
||||
rc = 0;
|
||||
} else {
|
||||
// Runtime-constraints violated, zero out destination array
|
||||
if( (s1 != NULL) && __lte_rsizmax( s1max ) ) {
|
||||
__F_NAME(memset,wmemset)( s1, 0, s1max );
|
||||
}
|
||||
// Now call the handler
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
|
||||
return( rc );
|
||||
}
|
167
programs/develop/open watcom/trunk/clib/memory/memmove.c
Normal file
167
programs/develop/open watcom/trunk/clib/memory/memmove.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memmove().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__386__)
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x06 /* push es */\
|
||||
0x8e 0xc2 /* mov es,dx */\
|
||||
0x51 /* push ecx */\
|
||||
0xc1 0xe9 0x02 /* shr ecx,2 */\
|
||||
0xf3 0xa5 /* rep movsd */\
|
||||
0x59 /* pop ecx */\
|
||||
0x83 0xe1 0x03 /* and ecx,3 */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x07 /* pop es */\
|
||||
parm [dx edi] [esi] [ecx] \
|
||||
modify exact [edi esi ecx];
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0x06 /* push es */\
|
||||
0x8e 0xc2 /* mov es,dx */\
|
||||
0xfd /* std */\
|
||||
0x4e /* dec esi */\
|
||||
0x4f /* dec edi */\
|
||||
0xd1 0xe9 /* shr ecx,1 */\
|
||||
0x66 0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc ecx,ecx */\
|
||||
0x46 /* inc esi */\
|
||||
0x47 /* inc edi */\
|
||||
0x66 0xf3 0xa4 /* rep movsb */\
|
||||
0x07 /* pop es */\
|
||||
0xfc /* cld */\
|
||||
parm [dx edi] [esi] [ecx] \
|
||||
modify exact [edi esi ecx];
|
||||
#define HAVE_MOVEFWBW
|
||||
|
||||
#elif defined(M_I86) && defined(__SMALL_DATA__)
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0xfd /* std */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
parm [es di] [si] [cx] \
|
||||
modify exact [di si cx];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCNEAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
parm [es di] [si] [cx] \
|
||||
modify exact [di si cx];
|
||||
#define HAVE_MOVEFWBW
|
||||
|
||||
#elif defined(M_I86) && defined(__BIG_DATA__)
|
||||
extern void movebwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movebwd = \
|
||||
0x1e /* push ds */ \
|
||||
0x8e 0xda /* mov ds,dx */ \
|
||||
0xfd /* std */\
|
||||
0x4e /* dec si */\
|
||||
0x4f /* dec di */\
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0x46 /* inc si */\
|
||||
0x47 /* inc di */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0xfc /* cld */\
|
||||
0x1f /* pop ds */ \
|
||||
parm [es di] [dx si] [cx] \
|
||||
modify exact [di si cx];
|
||||
|
||||
extern void movefwd( char _WCFAR *dst, const char _WCFAR *src, unsigned len);
|
||||
#pragma aux movefwd = \
|
||||
0x1e /* push ds */ \
|
||||
0x8e 0xda /* mov ds,dx */ \
|
||||
0xd1 0xe9 /* shr cx,1 */\
|
||||
0xf3 0xa5 /* rep movsw */\
|
||||
0x11 0xc9 /* adc cx,cx */\
|
||||
0xf3 0xa4 /* rep movsb */\
|
||||
0x1f /* pop ds */ \
|
||||
parm [es di] [dx si] [cx] \
|
||||
modify exact [di si cx];
|
||||
#define HAVE_MOVEFWBW
|
||||
|
||||
#else
|
||||
// no pragma for non-x86
|
||||
#endif
|
||||
|
||||
|
||||
_WCRTLINK void *memmove( void *toStart, const void *fromStart, size_t len )
|
||||
{
|
||||
const char *from = fromStart;
|
||||
char *to = toStart;
|
||||
|
||||
if( from == to ) {
|
||||
return( to );
|
||||
}
|
||||
if( from < to && from + len > to ) { /* if buffers are overlapped*/
|
||||
#if defined( __HUGE__ ) || !defined( HAVE_MOVEFWBW )
|
||||
to += len;
|
||||
from += len;
|
||||
while( len != 0 ) {
|
||||
*--to = *--from;
|
||||
len--;
|
||||
}
|
||||
#else
|
||||
movebwd(( to + len ) - 1, ( from + len ) - 1, len );
|
||||
#endif
|
||||
} else {
|
||||
#if !defined( HAVE_MOVEFWBW )
|
||||
while( len != 0 ) {
|
||||
*to++ = *from++;
|
||||
len--;
|
||||
}
|
||||
#else
|
||||
movefwd( to, from, len );
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__HUGE__) || !defined( HAVE_MOVEFWBW )
|
||||
return( toStart );
|
||||
#else
|
||||
return( to );
|
||||
#endif
|
||||
}
|
73
programs/develop/open watcom/trunk/clib/memory/memset.c
Normal file
73
programs/develop/open watcom/trunk/clib/memory/memset.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of memset() and wmemset().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "xstring.h"
|
||||
|
||||
|
||||
#if defined(__386__)
|
||||
extern void __STOSB( void *, int, unsigned );
|
||||
#pragma aux __STOSB "*" parm [eax] [edx] [ecx];
|
||||
|
||||
extern void *__set386( void *, int, unsigned );
|
||||
#pragma aux __set386 = \
|
||||
"push EAX" /* save return value*/\
|
||||
"mov DH,DL" /* duplicate byte value thru EDX */\
|
||||
"shl EDX,8" /* ... */\
|
||||
"mov DL,DH" /* ... */\
|
||||
"shl EDX,8" /* ... */\
|
||||
"mov DL,DH" /* ... */\
|
||||
"call __STOSB" /* do store */\
|
||||
"pop EAX" /* restore return value*/\
|
||||
parm [eax] [edx] [ecx] \
|
||||
value [eax];
|
||||
#endif
|
||||
|
||||
_WCRTLINK VOID_WC_TYPE *__F_NAME(memset,wmemset)( VOID_WC_TYPE *dst, INT_WC_TYPE c, size_t len )
|
||||
{
|
||||
#if defined(__INLINE_FUNCTIONS__) && !defined(__WIDECHAR__) && defined(_M_IX86)
|
||||
#if defined(__386__)
|
||||
return( __set386( dst, c, len ) );
|
||||
#else
|
||||
return( _inline_memset( dst, c, len ) );
|
||||
#endif
|
||||
#else
|
||||
CHAR_TYPE *p;
|
||||
|
||||
for( p = dst; len; --len ) {
|
||||
*p++ = c;
|
||||
}
|
||||
return( dst );
|
||||
#endif
|
||||
}
|
289
programs/develop/open watcom/trunk/clib/memory/memtest.c
Normal file
289
programs/develop/open watcom/trunk/clib/memory/memtest.c
Normal file
@@ -0,0 +1,289 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* MEMTEST.C
|
||||
* Non-exhaustive test of the C library memory manipulation functions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
#include <i86.h>
|
||||
#endif
|
||||
#ifdef __SW_BW
|
||||
#include <wdefwin.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define VERIFY( exp ) if( !(exp) ) { \
|
||||
printf( "%s: ***FAILURE*** at line %d of %s.\n",\
|
||||
ProgramName, __LINE__, \
|
||||
strlwr(__FILE__) ); \
|
||||
NumErrors++; \
|
||||
exit(-1); \
|
||||
}
|
||||
|
||||
void TestCompare( void );
|
||||
void TestCompareF( void );
|
||||
void TestCopy( void );
|
||||
void TestCopyF( void );
|
||||
void TestOverlap( void );
|
||||
void TestOverlapF( void );
|
||||
void TestMisc( void );
|
||||
|
||||
|
||||
char ProgramName[128]; /* executable filename */
|
||||
int NumErrors = 0; /* number of errors */
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Program entry point.
|
||||
****/
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
#ifdef __SW_BW
|
||||
FILE *my_stdout;
|
||||
my_stdout = freopen( "tmp.log", "a", stdout );
|
||||
if( my_stdout == NULL ) {
|
||||
fprintf( stderr, "Unable to redirect stdout\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** Initialize ***/
|
||||
strcpy( ProgramName, strlwr(argv[0]) ); /* store filename */
|
||||
|
||||
/*** Test various functions ***/
|
||||
TestCompare(); /* comparing stuff */
|
||||
TestCopy(); /* copying stuff */
|
||||
TestOverlap(); /* test overlapping copy */
|
||||
TestMisc(); /* other stuff */
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
TestCompareF();
|
||||
TestCopyF();
|
||||
TestOverlapF();
|
||||
#endif
|
||||
|
||||
/*** Print a pass/fail message and quit ***/
|
||||
if( NumErrors!=0 ) {
|
||||
printf( "%s: SUCCESS.\n", ProgramName );
|
||||
return( EXIT_SUCCESS );
|
||||
}
|
||||
printf( "Tests completed (%s).\n", strlwr( argv[0] ) );
|
||||
#ifdef __SW_BW
|
||||
{
|
||||
fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) );
|
||||
fclose( my_stdout );
|
||||
_dwShutDown();
|
||||
}
|
||||
#endif
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memcmp(), memicmp(), and memchr().
|
||||
****/
|
||||
|
||||
void TestCompare( void )
|
||||
{
|
||||
char buf[80];
|
||||
char * ptr;
|
||||
int status;
|
||||
|
||||
strcpy( buf, "Foo !" ); /* initialize string */
|
||||
|
||||
status = memcmp( buf, "Foo", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = memcmp( buf, "Foo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
status = memicmp( buf, "FOO", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = memicmp( buf, "fOo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
ptr = memchr( buf, '~', 6 ); /* try to find a tilde */
|
||||
VERIFY( ptr == NULL );
|
||||
|
||||
ptr = memchr( buf, '!', 6 ); /* find the '!' */
|
||||
VERIFY( ptr == buf+4 );
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestCompareF( void )
|
||||
{
|
||||
char buf[80];
|
||||
char __far * ptr;
|
||||
int status;
|
||||
|
||||
strcpy( buf, "Foo !" ); /* initialize string */
|
||||
|
||||
status = _fmemcmp( buf, "Foo", 3 ); /* compare */
|
||||
VERIFY( status == 0 );
|
||||
|
||||
status = _fmemcmp( buf, "Foo!", 4 ); /* compare */
|
||||
VERIFY( status != 0 );
|
||||
|
||||
ptr = _fmemchr( buf, '~', 6 ); /* try to find a tilde */
|
||||
VERIFY( ptr == NULL );
|
||||
|
||||
ptr = _fmemchr( buf, '!', 6 ); /* find the '!' */
|
||||
VERIFY( ptr == buf+4 );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memcpy(), memccpy(), and movedata().
|
||||
****/
|
||||
|
||||
void TestCopy( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
|
||||
memccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
|
||||
VERIFY( !memcmp(bufA, "Hello", 5) ); /* ensure copied ok */
|
||||
|
||||
memcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
|
||||
VERIFY( !strcmp(bufA, bufB) ); /* ensure copied ok */
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestCopyF( void )
|
||||
{
|
||||
char __far bufA[80], bufB[80];
|
||||
char __far testStr[] = "Foo Bar Goober Blah";
|
||||
|
||||
strcpy( bufB, "Hello, world!" ); /* initialize bufB */
|
||||
_fmemccpy( bufA, bufB, 'o', strlen(bufB)+1 ); /* copy "Hello" to bufA */
|
||||
VERIFY( !_fmemcmp(bufA, "Hello", 5) ); /* ensure copied ok */
|
||||
|
||||
_fmemcpy( bufA, bufB, strlen(bufB)+1 ); /* copy to bufA */
|
||||
VERIFY( !_fstrcmp(bufA, bufB) ); /* ensure copied ok */
|
||||
|
||||
movedata( FP_SEG(bufA), FP_OFF(bufA), /* copy data */
|
||||
FP_SEG(testStr), FP_OFF(testStr),
|
||||
_fstrlen(testStr) );
|
||||
VERIFY( !_fmemcmp(bufA, testStr, _fstrlen(testStr)) );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memmove().
|
||||
****/
|
||||
|
||||
void TestOverlap( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufA, " Hello, world!" ); /* initialize string */
|
||||
|
||||
memmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
|
||||
VERIFY( !strcmp(bufB, bufA) );
|
||||
|
||||
memmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
|
||||
VERIFY( !strcmp(bufA, "Hello, world!!") );
|
||||
|
||||
memmove( bufA+1, bufA, strlen(bufA+1) );
|
||||
VERIFY( !strcmp(bufA, "HHello, world!") );
|
||||
}
|
||||
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
void TestOverlapF( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
|
||||
strcpy( bufA, " Hello, world!" ); /* initialize string */
|
||||
|
||||
_fmemmove( bufB, bufA, strlen(bufA)+1 ); /* copy string */
|
||||
VERIFY( !strcmp(bufB, bufA) );
|
||||
|
||||
_fmemmove( bufA, bufA+1, strlen(bufA+1) ); /* shift one character over */
|
||||
VERIFY( !strcmp(bufA, "Hello, world!!") );
|
||||
|
||||
_fmemmove( bufA+1, bufA, strlen(bufA+1) );
|
||||
VERIFY( !strcmp(bufA, "HHello, world!") );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Test memset(), _fmemset(), and swab().
|
||||
****/
|
||||
|
||||
void TestMisc( void )
|
||||
{
|
||||
char bufA[80], bufB[80];
|
||||
void * addr;
|
||||
int count;
|
||||
|
||||
addr = memset( bufA, 0x00, 80 ); /* zero out memory */
|
||||
VERIFY( addr == bufA );
|
||||
|
||||
for( count=0; count<80; count++ ) /* ensure all zero bytes */
|
||||
VERIFY( bufA[count] == 0x00 );
|
||||
|
||||
#if defined(__386__) || defined(M_I86)
|
||||
{
|
||||
void __far * addrFar;
|
||||
addrFar = _fmemset( bufB, 0x00, 80 ); /* zero out memory */
|
||||
VERIFY( addrFar == bufB );
|
||||
|
||||
for( count=0; count<80; count++ ) { /* ensure all zero bytes */
|
||||
VERIFY( bufB[count] == 0x00 );
|
||||
}
|
||||
}
|
||||
#else
|
||||
memset( bufB, 0x00, 80 ); /* zero out memory */
|
||||
#endif
|
||||
|
||||
strcpy( bufA, "eHll,ow rodl" ); /* initialize string */
|
||||
swab( bufA, bufB, strlen(bufA) ); /* swap pairs of characters */
|
||||
VERIFY( !strcmp(bufB, "Hello, world") ); /* ensure swapped ok */
|
||||
}
|
46
programs/develop/open watcom/trunk/clib/memory/movedata.c
Normal file
46
programs/develop/open watcom/trunk/clib/memory/movedata.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of movedata().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
/* Inline variant must always be used, no equivalent exists */
|
||||
#ifndef __INLINE_FUNCTIONS__
|
||||
#define __INLINE_FUNCTIONS__
|
||||
#endif
|
||||
#include "xstring.h"
|
||||
|
||||
#undef movedata
|
||||
|
||||
|
||||
_WCRTLINK void movedata( unsigned fromseg, unsigned fromoff,
|
||||
unsigned toseg, unsigned tooff, unsigned len )
|
||||
{
|
||||
_inline_movedata( fromseg, fromoff, toseg, tooff, len );
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/memory/swab.c
Normal file
47
programs/develop/open watcom/trunk/clib/memory/swab.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
_WCRTLINK void swab( char *src, char *dst, int n )
|
||||
{
|
||||
char c;
|
||||
|
||||
for( n = n >> 1; n; --n ) {
|
||||
c = src[0]; /* 25-jun-90: just in case src and dst are the same */
|
||||
dst[0] = src[1];
|
||||
dst[1] = c;
|
||||
dst += 2;
|
||||
src += 2;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user