diff options
-rw-r--r-- | include/string.h | 13 | ||||
-rw-r--r-- | src/string/strset.c | 39 |
2 files changed, 52 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h index b3b3e10..b38e849 100644 --- a/include/string.h +++ b/include/string.h @@ -254,6 +254,19 @@ void* memccpy(void* restrict, const void* restrict, int, size_t); * one character passed the last written character. */ void* memcmove(void*, const void*, int, size_t); + +/** + * Override a NUL byte-terminated memory segment + * with a repeated character. + * + * This is a slibc extension. + * + * @param str The beginning of the memory segment. + * @param c The character (8 bits wide.) + * @return `str` is returned. + */ +char* strset(char* str, int c); + __GCC_ONLY(__attribute__((__returns_nonnull__, __nonnull__))); #endif /** diff --git a/src/string/strset.c b/src/string/strset.c new file mode 100644 index 0000000..c1eca65 --- /dev/null +++ b/src/string/strset.c @@ -0,0 +1,39 @@ +/** + * slibc — Yet another C library + * Copyright © 2015 Mattias Andrée (maandree@member.fsf.org) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include <string.h> + + + +/** + * Override a NUL byte-terminated memory segment + * with a repeated character. + * + * This is a slibc extension. + * + * @param str The beginning of the memory segment. + * @param c The character (8 bits wide.) + * @return `str` is returned. + */ +char* strset(char* str, int c) +{ + char* s = segment; + while (*s) + *s++ = (char)c; + return segment; +} + |