forked from KolibriOS/kolibrios
kolibri-libc:
Move to folder with tcc. Part 1 git-svn-id: svn://kolibrios.org@8793 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
14
programs/develop/ktcc/trunk/libc.obj/source/string/memccpy.c
Normal file
14
programs/develop/ktcc/trunk/libc.obj/source/string/memccpy.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <string.h>
|
||||
|
||||
void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
|
||||
{
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
||||
c = (unsigned char)c;
|
||||
for (; n && (*d=*s)!=c; n--, s++, d++);
|
||||
|
||||
tail:
|
||||
if (n) return d+1;
|
||||
return 0;
|
||||
}
|
24
programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c
Normal file
24
programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* memchr( const void *, int, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memchr( const void * s, int c, size_t n )
|
||||
{
|
||||
const unsigned char * p = ( const unsigned char * ) s;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
if ( *p == ( unsigned char ) c )
|
||||
{
|
||||
return ( void * ) p;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
26
programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c
Normal file
26
programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* memcmp( const void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int memcmp( const void * s1, const void * s2, size_t n )
|
||||
{
|
||||
const unsigned char * p1 = ( const unsigned char * ) s1;
|
||||
const unsigned char * p2 = ( const unsigned char * ) s2;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
if ( *p1 != *p2 )
|
||||
{
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
20
programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c
Normal file
20
programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* memcpy( void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memcpy( void * s1, const void * s2, size_t n )
|
||||
{
|
||||
char * dest = ( char * ) s1;
|
||||
const char * src = ( const char * ) s2;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
33
programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c
Normal file
33
programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* memmove( void *, const void *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void * memmove( void * s1, const void * s2, size_t n )
|
||||
{
|
||||
char * dest = ( char * ) s1;
|
||||
const char * src = ( const char * ) s2;
|
||||
|
||||
if ( dest <= src )
|
||||
{
|
||||
while ( n-- )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
src += n;
|
||||
dest += n;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*--dest = *--src;
|
||||
}
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
20
programs/develop/ktcc/trunk/libc.obj/source/string/memset.c
Normal file
20
programs/develop/ktcc/trunk/libc.obj/source/string/memset.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* memset( void *, int, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void * memset( void * s, int c, size_t n )
|
||||
{
|
||||
unsigned char * p = ( unsigned char * ) s;
|
||||
|
||||
while ( n-- )
|
||||
{
|
||||
*p++ = ( unsigned char ) c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
27
programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c
Normal file
27
programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* strcat( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strcat( char * s1, const char * s2 )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
if ( *s1 )
|
||||
{
|
||||
while ( *++s1 )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
}
|
||||
|
||||
while ( ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
20
programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c
Normal file
20
programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* strchr( const char *, int )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strchr( const char * s, int c )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( *s == ( char ) c )
|
||||
{
|
||||
return ( char * ) s;
|
||||
}
|
||||
} while ( *s++ );
|
||||
|
||||
return NULL;
|
||||
}
|
14
programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c
Normal file
14
programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* strcmp( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
int strcmp(const char * s1, const char * s2)
|
||||
{
|
||||
return _ksys_strcmp(s1, s2);
|
||||
}
|
13
programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c
Normal file
13
programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* strcoll( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strcoll( const char * s1, const char * s2 )
|
||||
{
|
||||
/* FIXME: This should access _PDCLIB_lc_collate. */
|
||||
return strcmp( s1, s2 );
|
||||
}
|
19
programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c
Normal file
19
programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* strcpy( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strcpy( char * s1, const char * s2 )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
30
programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c
Normal file
30
programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* strcspn( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strcspn( const char * s1, const char * s2 )
|
||||
{
|
||||
size_t len = 0;
|
||||
const char * p;
|
||||
|
||||
while ( s1[len] )
|
||||
{
|
||||
p = s2;
|
||||
|
||||
while ( *p )
|
||||
{
|
||||
if ( s1[len] == *p++ )
|
||||
{
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
10
programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c
Normal file
10
programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char* strdup(const char *str)
|
||||
{
|
||||
char *buf = malloc(strlen(str) + 1);
|
||||
buf[strlen(str)] = '\0';
|
||||
strcpy(buf, str);
|
||||
return buf;
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
int _errno;
|
||||
|
||||
char* strerror(int err)
|
||||
{
|
||||
char *msg;
|
||||
switch(err){
|
||||
case 0: msg = "No errors"; break;
|
||||
case EPERM: msg = "Operation not permitted"; break;
|
||||
case ENOENT: msg = "No such file or directory"; break;
|
||||
case ESRCH: msg = "No such process"; break;
|
||||
case EINTR: msg = "Interrupted system call"; break;
|
||||
case EIO: msg = "Input/output error"; break;
|
||||
case ENXIO: msg = "Device not configured"; break;
|
||||
case E2BIG: msg = "Argument list too long"; break;
|
||||
case ENOEXEC: msg = "Exec format error"; break;
|
||||
case EBADF: msg = "Bad file descriptor"; break;
|
||||
case ECHILD: msg = "No child processes"; break;
|
||||
case EDEADLK: msg = "Resource deadlock avoided"; break;
|
||||
case ENOMEM: msg = "Cannot allocate memory"; break;
|
||||
case EACCES: msg = "Permission denied"; break;
|
||||
case EFAULT: msg = "Bad address"; break;
|
||||
case ENOTBLK: msg = "Block device required"; break;
|
||||
case EBUSY: msg = "Device / Resource busy"; break;
|
||||
case EEXIST: msg = "File exists"; break;
|
||||
case EXDEV: msg = "Cross-device link"; break;
|
||||
case ENODEV: msg = "Operation not supported by device"; break;
|
||||
case ENOTDIR: msg = "Not a directory"; break;
|
||||
case EISDIR: msg = "Is a directory"; break;
|
||||
case EINVAL: msg = "Invalid argument"; break;
|
||||
case ENFILE: msg = "Too many open files in system"; break;
|
||||
case EMFILE: msg = "Too many open files"; break;
|
||||
case ENOTTY: msg = "Inappropriate ioctl for device"; break;
|
||||
case ETXTBSY: msg = "Text file busy"; break;
|
||||
case EFBIG: msg = "File too large"; break;
|
||||
case ENOSPC: msg = "No space left on device"; break;
|
||||
case ESPIPE: msg = "Illegal seek"; break;
|
||||
case EROFS: msg = "Read-only file system"; break;
|
||||
case EMLINK: msg = "Too many links"; break;
|
||||
case EPIPE: msg = "Broken pipe"; break;
|
||||
|
||||
// math software
|
||||
case EDOM: msg = "Numerical argument out of domain"; break;
|
||||
case ERANGE: msg = "Result too large"; break;
|
||||
|
||||
// should be rearranged
|
||||
case EHOSTDOWN: msg = "Host is down"; break;
|
||||
case EHOSTUNREACH: msg = "No route to host"; break;
|
||||
case ENOTEMPTY: msg = "Directory not empty"; break;
|
||||
|
||||
// quotas & mush
|
||||
case EPROCLIM: msg = "Too many processes"; break;
|
||||
case EUSERS: msg = "Too many users"; break;
|
||||
case EDQUOT: msg = "Disc quota exceeded"; break;
|
||||
|
||||
// Intelligent device errors
|
||||
case EPWROFF: msg = "Device power is off"; break;
|
||||
case EDEVERR: msg = "Device error, e.g. paper out"; break;
|
||||
case EOVERFLOW: msg = "Value too large to be stored in data type"; break;
|
||||
|
||||
// Socket errors
|
||||
case ENOBUFS: msg = "Broken buffer"; break;
|
||||
case EINPROGRESS: msg = "Operation now in progress"; break;
|
||||
case EOPNOTSUPP: msg = "Operation not supported on transport endpoint"; break;
|
||||
case EWOULDBLOCK: msg = "Operation would block"; break;
|
||||
case ENOTCONN: msg = "Transport endpoint is not connected"; break;
|
||||
case EALREADY: msg = "Operation already in progress"; break;
|
||||
case EMSGSIZE: msg = "Message too long"; break;
|
||||
case EADDRINUSE: msg = "Address already in use"; break;
|
||||
case ECONNREFUSED: msg = "Connection refused"; break;
|
||||
case ECONNRESET: msg = "Connection reset by peer"; break;
|
||||
case EISCONN: msg = "Transport endpoint is already connected"; break;
|
||||
case ETIMEDOUT: msg = "Connection timed out"; break;
|
||||
case ECONNABORTED: msg = "Software caused connection abort"; break;
|
||||
default: msg = "Unknown error"; break;
|
||||
}
|
||||
return msg;
|
||||
}
|
19
programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c
Normal file
19
programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* strlen( const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen( const char * s )
|
||||
{
|
||||
size_t rc = 0;
|
||||
|
||||
while ( s[rc] )
|
||||
{
|
||||
++rc;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
29
programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c
Normal file
29
programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* strncat( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strncat( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( *s1 )
|
||||
{
|
||||
++s1;
|
||||
}
|
||||
|
||||
while ( n && ( *s1++ = *s2++ ) )
|
||||
{
|
||||
--n;
|
||||
}
|
||||
|
||||
if ( n == 0 )
|
||||
{
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
26
programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c
Normal file
26
programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* strncmp( const char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int strncmp( const char * s1, const char * s2, size_t n )
|
||||
{
|
||||
while ( n && *s1 && ( *s1 == *s2 ) )
|
||||
{
|
||||
++s1;
|
||||
++s2;
|
||||
--n;
|
||||
}
|
||||
|
||||
if ( n == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
|
||||
}
|
||||
}
|
29
programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c
Normal file
29
programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* strncpy( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strncpy( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
char * rc = s1;
|
||||
|
||||
while ( n && ( *s1++ = *s2++ ) )
|
||||
{
|
||||
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
|
||||
to check it again for >0 in the next loop below, so we must not risk
|
||||
underflow.
|
||||
*/
|
||||
--n;
|
||||
}
|
||||
|
||||
/* Checking against 1 as we missed the last --n in the loop above. */
|
||||
while ( n-- > 1 )
|
||||
{
|
||||
*s1++ = '\0';
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
30
programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c
Normal file
30
programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* strpbrk( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strpbrk( const char * s1, const char * s2 )
|
||||
{
|
||||
const char * p1 = s1;
|
||||
const char * p2;
|
||||
|
||||
while ( *p1 )
|
||||
{
|
||||
p2 = s2;
|
||||
|
||||
while ( *p2 )
|
||||
{
|
||||
if ( *p1 == *p2++ )
|
||||
{
|
||||
return ( char * ) p1;
|
||||
}
|
||||
}
|
||||
|
||||
++p1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
27
programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c
Normal file
27
programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* strrchr( const char *, int )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strrchr( const char * s, int c )
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
while ( s[i++] )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ( s[--i] == ( char ) c )
|
||||
{
|
||||
return ( char * ) s + i;
|
||||
}
|
||||
} while ( i );
|
||||
|
||||
return NULL;
|
||||
}
|
15
programs/develop/ktcc/trunk/libc.obj/source/string/strrev.c
Normal file
15
programs/develop/ktcc/trunk/libc.obj/source/string/strrev.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strrev(char *p)
|
||||
{
|
||||
char *q = p, *res = p, z;
|
||||
while(q && *q) ++q; /* find eos */
|
||||
for(--q; p < q; ++p, --q)
|
||||
{
|
||||
z = *p;
|
||||
*p = *q;
|
||||
*q = z;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
37
programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c
Normal file
37
programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* strspn( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strspn( const char * s1, const char * s2 )
|
||||
{
|
||||
size_t len = 0;
|
||||
const char * p;
|
||||
|
||||
while ( s1[ len ] )
|
||||
{
|
||||
p = s2;
|
||||
|
||||
while ( *p )
|
||||
{
|
||||
if ( s1[len] == *p )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
if ( ! *p )
|
||||
{
|
||||
return len;
|
||||
}
|
||||
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
34
programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c
Normal file
34
programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* strstr( const char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char * strstr( const char * s1, const char * s2 )
|
||||
{
|
||||
const char * p1 = s1;
|
||||
const char * p2;
|
||||
|
||||
while ( *s1 )
|
||||
{
|
||||
p2 = s2;
|
||||
|
||||
while ( *p2 && ( *p1 == *p2 ) )
|
||||
{
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
if ( ! *p2 )
|
||||
{
|
||||
return ( char * ) s1;
|
||||
}
|
||||
|
||||
++s1;
|
||||
p1 = s1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
30
programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c
Normal file
30
programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* strtok( char *, const char * )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char* strtok(char* s, const char* delim)
|
||||
{
|
||||
static char* savep;
|
||||
char* res;
|
||||
|
||||
if(s)
|
||||
savep = NULL;
|
||||
else
|
||||
s = savep;
|
||||
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
s += strspn(s, delim);
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
res = s;
|
||||
s += strcspn(s, delim);
|
||||
savep = s + 1;
|
||||
*s = '\0';
|
||||
return res;
|
||||
}
|
||||
|
26
programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c
Normal file
26
programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* strxfrm( char *, const char *, size_t )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strxfrm( char * s1, const char * s2, size_t n )
|
||||
{
|
||||
size_t len = strlen( s2 );
|
||||
|
||||
if ( len < n )
|
||||
{
|
||||
/* Cannot use strncpy() here as the filling of s1 with '\0' is not part
|
||||
of the spec.
|
||||
*/
|
||||
/* FIXME: This should access _PDCLIB_lc_collate. */
|
||||
while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) )
|
||||
{
|
||||
/* EMPTY */
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
Reference in New Issue
Block a user