1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 * + Contributed by bellrise <bellrise.dev@gmail.com>
5 *
6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file.
8 */
9#ifndef _LIBC_STRING_H
10#define _LIBC_STRING_H
11
12#include <stddef.h>
13#include <sys/cdefs.h>
14#include <sys/types.h>
15
16__BEGIN_DECLS
17
18/* Set 'nbytes' to 'fill' starting from 'dest'. */
19void* memset(void* dest, int fill, size_t nbytes);
20
21/* Move 'nbytes' from 'src' to 'dest' */
22void* memmove(void* dest, const void* __restrict src, size_t nbytes);
23
24/* Copy 'nbytes' from 'src' to 'dest'. See the comment in the source file
25 about optimization and restricting pointers. */
26void* memcpy(void* __restrict dest, const void* __restrict src, size_t nbytes);
27
28/* Copy 'nbytes' from 'src' to 'dest', stopping if the current byte matches
29 'stop'. Note that the stop byte also gets copied over. */
30void* memccpy(void* dest, const void* __restrict src, int stop, size_t nbytes);
31
32/* Compare 'nbytes' from 'src1' and 'src2'. Return 0 if all the bytes match,
33 otherwise return the difference. */
34int memcmp(const void* src1, const void* src2, size_t nbytes);
35
36/* Calculate the string length starting from 'str'. */
37size_t strlen(const char* str);
38
39/* Copy 'src' into 'dest' until it finds a null byte in the source string.
40 Note that this is dangerous because it writes memory no matter the size
41 the 'dest' buffer is. */
42char* strcpy(char* dest, const char* src);
43int strcmp(const char* a, const char* b);
44int strncmp(const char* a, const char* b, size_t nbytes);
45
46/* Copy 'src' into 'dest' until it finds a null byte or reaches the 'nbytes'
47 limit provided by the user. This is the recommended way of copying strings,
48 instead of using regular strcpy. Note that this will fill the 'dest' buffer
49 with null bytes if the amount of copied bytes is lower than 'nbytes'. */
50char* strncpy(char* dest, const char* src, size_t nbytes);
51
52/* Returns a pointer to the first occurrence of character in the C string str. */
53char* strchr(const char* s, int c);
54
55__END_DECLS
56
57#endif // _LIBC_STRING_H