libc/wchar: Add wcsncat() - 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 4ac2c9373b1004d4176807d0b106c97cbdab8163
 (DIR) parent 949d7de20391cbcb0a6ce10cf2080abb7914b6b5
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Tue, 25 Mar 2025 20:56:32 +0100
       
       libc/wchar: Add wcsncat()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcsncat.c            |      18 ++++++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0056-wcsncat.c   |      58 ++++++++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 79 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -132,6 +132,7 @@ COMMON_OBJS =\
                wchar/wcsncmp.$O\
                wchar/wcscpy.$O\
                wchar/wcscat.$O\
       +        wchar/wcsncat.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
 (DIR) diff --git a/src/libc/wchar/wcsncat.c b/src/libc/wchar/wcsncat.c
       @@ -0,0 +1,18 @@
       +#include <wchar.h>
       +
       +#undef wcsncat
       +
       +wchar_t *
       +wcsncat(wchar_t *restrict s1, const wchar_t *restrict s2, size_t n)
       +{
       +        wchar_t *ret;
       +
       +        for (ret = s1; *s1; ++s1)
       +                ;
       +        while (n-- > 0 && *s2)
       +                *s1++ = *s2++;
       +        *s1 = '\0';
       +
       +        return ret;
       +
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -52,4 +52,5 @@
        0053-wmemcmp
        0054-wcsncpy
        0055-wcscat
       +0056-wcsncat
        test.log
 (DIR) diff --git a/tests/libc/execute/0056-wcsncat.c b/tests/libc/execute/0056-wcsncat.c
       @@ -0,0 +1,58 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +test1
       +test2
       +test3
       +test4
       +test5
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        wchar_t *s, buf[40], buf2[40];
       +
       +        puts("testing");
       +
       +        puts("test1");
       +        wcscpy(buf, L"01234");
       +        s = wcsncat(buf, L"567", 8);
       +        assert(s == buf);
       +        assert(!wcscmp(s, L"01234567"));
       +
       +        puts("test2");
       +        wcscpy(buf, L"01234");
       +        s = wcsncat(buf, L"567", 2);
       +        assert(s == buf);
       +        assert(!wcscmp(s, L"0123456"));
       +
       +        puts("test3");
       +        wcscpy(buf, L"01234");
       +        wmemcpy(buf2, L"567", 3);
       +        s = wcsncat(buf, buf2, 3);
       +        assert(s == buf);
       +        assert(!wcscmp(s, L"01234567"));
       +
       +        puts("test4");
       +        wcscpy(buf, L"01234");
       +        s = wcsncat(buf, L"", 7);
       +        assert(s == buf);
       +        assert(!wcscmp(s, L"01234"));
       +
       +        puts("test5");
       +        wcscpy(buf, L"01234");
       +        s = wcsncat(buf, L"", 0);
       +        assert(s == buf);
       +        assert(!wcscmp(s, L"01234"));
       +
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -51,3 +51,4 @@
        0053-wmemcmp
        0054-wcsncpy
        0055-wcscat
       +0056-wcsncat