libc/wchar: Add wcsxfrm() - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit aef615310c0729e97e4ad5a2e4206266660679a2
 (DIR) parent 09245abd272928c778c739e2402517a464b1a678
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Wed, 26 Mar 2025 14:14:28 +0100
       
       libc/wchar: Add wcsxfrm()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcsxfrm.c            |      13 +++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0060-wcsxfrm.c   |      27 +++++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 43 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -136,6 +136,7 @@ COMMON_OBJS =\
                wchar/wcschr.$O\
                wchar/wcsrchr.$O\
                wchar/wcsstr.$O\
       +        wchar/wcsxfrm.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
 (DIR) diff --git a/src/libc/wchar/wcsxfrm.c b/src/libc/wchar/wcsxfrm.c
       @@ -0,0 +1,13 @@
       +#include <wchar.h>
       +
       +#undef wcsxfrm
       +
       +size_t
       +wcsxfrm(wchar_t *dst, const wchar_t *src, size_t n)
       +{
       +        size_t len = wcslen(src);
       +
       +        if (len < n)
       +                wcscpy(dst, src);
       +        return len;
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -56,4 +56,5 @@
        0057-wcschr
        0058-wcsrchr
        0059-wcsstr
       +0060-wcsxfrm
        test.log
 (DIR) diff --git a/tests/libc/execute/0060-wcsxfrm.c b/tests/libc/execute/0060-wcsxfrm.c
       @@ -0,0 +1,27 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        wchar_t buf[40];
       +        size_t n;
       +
       +        puts("testing");
       +
       +        assert(wcsxfrm(buf, L"test", 40) == 4);
       +        assert(wcsxfrm(buf, L"", 0) == 0);
       +        assert(wcsxfrm(NULL, L"abc", 0) > 0);
       +
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -55,3 +55,4 @@
        0057-wcschr
        0058-wcsrchr
        0059-wcsstr
       +0060-wcsxfrm