/* See the end of this file for copyright and license terms. */ #pragma once #include /** * @brief Copy `n` bytes from `src` to `dest`. * * @param dest The destination * @param src The source * @param n The amount of bytes to copy * @returns A pointer to `dest` */ void *memcpy(void *dest, const void *src, size_t n); /** * @brief Starting from `ptr`, fill `n` bytes with the constant byte `c`. * * @param ptr The start of the memory region * @param c The byte to fill with * @param n The amount of bytes to write * @returns A pointer to `ptr` */ void *memset(void *ptr, int c, size_t n); /** * @brief Copy a memory area. * The two areas may overlap since the individual bytes are copied to a * temporary array first. * * @param dest The destination address * @param src The source address * @param n The amount of bytes to copy * @return a pointer to dest */ void *memmove(void *dest, const void *src, size_t n); /** * @brief Compare the two strings `s1` and `s2`. * * @param s1 The first string * @param s2 The second string * @returns `0` if both strings are equal, a positive value f `s1` is greater * than `s2`, and a negative value if `s1` is less than `s2` */ int strcmp(const char *s1, const char *s2); /** * @brief Copy a `NUL` terminated string from `src` to `dest`. * * @param dest The destination to copy to. The memory region must be able to * hold the entire string plus one byte for the terminator. * @param src The original string to copy from * @returns A pointer to the destination string */ char *strcpy(char *dest, const char *src); /** * @brief Copy a `NUL` terminated string from `src` to `dest`, but at most `n` characters. * Note that this may cause `dest` to miss a `NUL` terminator. * * @param dest The destination to copy to. The memory region must be able to * hold the entire string plus one byte for the terminator. * @param src The original string to copy from * @param n The amount of characters to copy at most * @returns A pointer to the destination string */ char *strncpy(char *dest, const char *src, size_t n); /** * @brief Compute the length of the `NUL` terminated string `s`. * * @param s The string * @returns The length of `s` without the `NUL` terminator */ size_t strlen(const char *s); #if _POSIX_C_SOURCE >= 200809L || _GAY_SOURCE >= 202109L /** * @brief Compute the length of the `NUL` terminated string `s`, but at most `maxlen` bytes. * * @param s The string * @param maxlen Maximum bytes after which to return * @returns The length of `s` without the `NUL` terminator, but at most `maxlen` */ size_t strnlen(const char *s, size_t maxlen); #endif /* * This file is part of GayBSD. * Copyright (c) 2021 fef . * * GayBSD is nonviolent software: you may only use, redistribute, and/or * modify it under the terms of the Cooperative Nonviolent Public License * (CNPL) as found in the LICENSE file in the source code root directory * or at ; either version 7 * of the license, or (at your option) any later version. * * GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent * permitted by applicable law. See the CNPL for details. */