1 /* @(#) pf_clib.c 96/12/18 1.12 */
\r
2 /***************************************************************
\r
3 ** Duplicate functions from stdlib for PForth based on 'C'
\r
5 ** This code duplicates some of the code in the 'C' lib
\r
6 ** because it reduces the dependency on foreign libraries
\r
7 ** for monitor mode where no OS is available.
\r
10 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
\r
12 ** The pForth software code is dedicated to the public domain,
\r
13 ** and any third party may reproduce, distribute and modify
\r
14 ** the pForth software code or any derivative works thereof
\r
15 ** without any compensation or license. The pForth software
\r
16 ** code is provided on an "as is" basis without any warranty
\r
17 ** of any kind, including, without limitation, the implied
\r
18 ** warranties of merchantability and fitness for a particular
\r
19 ** purpose and their equivalents under the laws of any jurisdiction.
\r
21 ****************************************************************
\r
22 ** 961124 PLB Advance pointers in pfCopyMemory() and pfSetMemory()
\r
23 ***************************************************************/
\r
28 /* Count chars until NUL. Replace strlen() */
\r
29 #define NUL ((char) 0)
\r
30 cell_t pfCStringLength( const char *s )
\r
33 while( *s++ != NUL ) len++;
\r
37 /* void *memset (void *s, cell_t c, size_t n); */
\r
38 void *pfSetMemory( void *s, cell_t c, cell_t n )
\r
40 uint8_t *p = s, byt = (uint8_t) c;
\r
41 while( (n--) > 0) *p++ = byt;
\r
45 /* void *memccpy (void *s1, const void *s2, cell_t c, size_t n); */
\r
46 void *pfCopyMemory( void *s1, const void *s2, cell_t n)
\r
49 const uint8_t *p2 = s2;
\r
50 while( (n--) > 0) *p1++ = *p2++;
\r
54 #endif /* PF_NO_CLIB */
\r
56 char pfCharToUpper( char c )
\r
58 return (char) ( ((c>='a') && (c<='z')) ? (c - ('a' - 'A')) : c );
\r
61 char pfCharToLower( char c )
\r
63 return (char) ( ((c>='A') && (c<='Z')) ? (c + ('a' - 'A')) : c );
\r