From e08c13b34414280a6fda76ae9a843e07e447e03a Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 8 Nov 2012 19:04:55 +0100 Subject: [PATCH] Add strxfrm(3). --- libc/Makefile | 1 + libc/include/string.h | 2 +- libc/strxfrm.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 libc/strxfrm.cpp diff --git a/libc/Makefile b/libc/Makefile index 4672bfd1..e6d695d0 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -120,6 +120,7 @@ strspn.o \ strstr.o \ strtok.o \ strtok_r.o \ +strxfrm.o \ ungetc.o \ vfscanf.o \ vsscanf.o \ diff --git a/libc/include/string.h b/libc/include/string.h index f6d01ba8..40173bf0 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -61,6 +61,7 @@ size_t strspn(const char*, const char*); char* strstr(const char*, const char*); char* strtok(char* restrict, const char* restrict); char* strtok_r(char* restrict, const char* restrict, char** restrict); +size_t strxfrm(char* restrict, const char* restrict, size_t); /* TODO: These are not implemented in sortix libc yet. */ #if defined(__SORTIX_SHOW_UNIMPLEMENTED) @@ -68,7 +69,6 @@ int strcoll_l(const char*, const char*, locale_t); char* strerror_l(int, locale_t); int strerror_r(int, char*, size_t); char* strsignal(int); -size_t strxfrm(char* restrict, const char* restrict, size_t); size_t strxfrm_l(char* restrict, const char* restrict, size_t, locale_t); #endif diff --git a/libc/strxfrm.cpp b/libc/strxfrm.cpp new file mode 100644 index 00000000..995746aa --- /dev/null +++ b/libc/strxfrm.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + strxfrm.cpp + Transform a string such that the result of strcmp is the same as strcoll. + +*******************************************************************************/ + +#include + +extern "C" size_t strxfrm(char* dest, const char* src, size_t n) +{ + size_t srclen = strlen(src); + strncpy(dest, src, n); + return srclen; +}