diff options
author | trimill <trimill@trimillxyz.org> | 2024-01-29 21:10:29 -0500 |
---|---|---|
committer | trimill <trimill@trimillxyz.org> | 2024-01-29 21:10:29 -0500 |
commit | 417d5b17b8054a73c2a41ae4aabefb4654e05fad (patch) | |
tree | 3dbd424270d1dd56843d3a11dbf34854e62bd2d6 /include | |
parent | pic done (diff) | |
download | corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.tar.gz corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.tar.bz2 corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.zip |
refactor, improve exception message
Diffstat (limited to 'include')
-rw-r--r-- | include/lib.h | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/include/lib.h b/include/lib.h index 43b95a6..1b6d1f4 100644 --- a/include/lib.h +++ b/include/lib.h @@ -1,92 +1,111 @@ #pragma once +#include <stddef.h> + /** * The memcmp() function compares the first n bytes (each interpreted as unsigned char) of the memory * areas s1 and s2. */ -extern int memcmp(const void *restrict s1, const void *restrict s2, unsigned long n); +int memcmp(const void *restrict s1, const void *restrict s2, unsigned long n); /** * The memcpy() function copies n bytes from memory area src to memory area dest. * The memory areas must not overlap. */ -extern void *memcpy(void *restrict dest, const void *restrict src, unsigned long n); +void *memcpy(void *restrict dest, const void *restrict src, unsigned long n); /** * The memmove() function copies n bytes from memory area src to memory area dest. The memory areas * may overlap: copying takes place as though the bytes in src are first copied into a temporary array * that does not overlap src or dest, and the bytes are then copied from the temporary array to dest. */ -extern void *memmove(void *dest, const void *src, unsigned long n); +void *memmove(void *dest, const void *src, unsigned long n); /** * The memset() function fills the first n bytes of the memory area pointed to by s with the constant * byte c. */ -extern void *memset(void *restrict dest, int c, unsigned long n); +void *memset(void *restrict dest, int c, unsigned long n); /** * The strcmp() function compares the two strings s1 and s2. The locale is not taken into account * (for a locale-aware comparison, see strcoll(3)). The comparison is done using unsigned characters. */ -extern int strncmp(const char *restrict s1, const char *restrict s2, unsigned long n); +int strncmp(const char *restrict s1, const char *restrict s2, unsigned long n); /** * Copys the string pointed to by src , into a string at the buffer pointer to by dest. * The dest buffer must be long enough to hold src. */ -extern char *strcpy(char *restrict dest, const char *restrict src); +char *strcpy(char *restrict dest, const char *restrict src); /** * Copys the string pointed to by src , into a string at the buffer pointer to by dest. * The dest buffer must be long enough to hold src or size n. */ -extern char *strncpy(char *restrict dest, const char *restrict src, unsigned long n); +char *strncpy(char *restrict dest, const char *restrict src, unsigned long n); + +/** + * Calculates the length of the string pointed to by str, excluding + * the terminating null byte + * @param str - the string pointer + * @returns the length of the string in bytes + */ +size_t strlen(const char *str); + +/** + * Concatenate the string pointed to by src after the string pointed + * to by dst. + * @param dst - the pointer to the destination string + * @param src - the pointer to the source string + * @returns dst + */ +char *strcat(char *restrict dst, const char *restrict src); /** * @returns 1 if c is a space */ -extern int isspace(int c); +int isspace(int c); /** * @returns 1 if c is a digit (0 - 9) */ -extern int isdigit(int c); +int isdigit(int c); /** * converts single digit int to base 36 * @param i - int * @returns c - base 36 char */ -extern char itoc(int i); +char itoc(int i); /** * converts single base 36 chat into int * @param c - base 36 char * @returns i - int */ -extern int ctoi(char c); +int ctoi(char c); /** * Converts the initial portiion of the string pointed to by s to int. * @param s - the string to convert * @returns the number inside s or 0 on error */ -extern int atoi(const char* s); +int atoi(const char* s); /** * Converts the initial portiion of the string pointed to by s to long. * @param s - the string to convert * @returns the number inside s or 0 on error */ -extern long int atol(const char* s); +long int atol(const char* s); /** * Converts the initial portiion of the string pointed to by s to long long. * @param s - the string to convert * @returns the number inside s or 0 on error */ -extern long long int atoll(const char* s); +long long int atoll(const char* s); /** * Converts a integer to asci inside a string with a given radix (base). @@ -94,7 +113,7 @@ extern long long int atoll(const char* s); * @param buffer - the string buffer * @param radix - the base to convert */ -extern char *itoa(int n, char *buffer, int radix); +char *itoa(int n, char *buffer, int radix); /** * Converts a long to asci inside a string with a given radix (base). @@ -102,7 +121,7 @@ extern char *itoa(int n, char *buffer, int radix); * @param buffer - the string buffer * @param radix - the base to convert */ -extern char *ltoa(long int n, char *buffer, int radix); +char *ltoa(long int n, char *buffer, int radix); /** * Converts a unsigned integer to asci inside a string with a given radix (base). @@ -110,7 +129,7 @@ extern char *ltoa(long int n, char *buffer, int radix); * @param buffer - the string buffer * @param radix - the base to convert */ -extern char *utoa(unsigned int n, char *buffer, int radix); +char *utoa(unsigned int n, char *buffer, int radix); /** * Converts a unsigned long to asci inside a string with a given radix (base). @@ -118,7 +137,7 @@ extern char *utoa(unsigned int n, char *buffer, int radix); * @param buffer - the string buffer * @param radix - the base to convert */ -extern char *ultoa(unsigned long int n, char *buffer, int radix); +char *ultoa(unsigned long int n, char *buffer, int radix); /** * Converts the string in str to an int value based on the given base. @@ -128,7 +147,7 @@ extern char *ultoa(unsigned long int n, char *buffer, int radix); * @param base - the base to convert to * @returns 0 on error or success, error if endptr is still equal to str */ -extern int strtoi(const char *str, char **endptr, int base); +int strtoi(const char *str, char **endptr, int base); /** * Converts the string in str to an long value based on the given base. @@ -138,7 +157,7 @@ extern int strtoi(const char *str, char **endptr, int base); * @param base - the base to convert to * @returns 0 on error or success, error if endptr is still equal to str */ -extern long int strtol(const char *str, char **endptr, int base); +long int strtol(const char *str, char **endptr, int base); /** * Converts the string in str to an long long value based on the given base. @@ -148,4 +167,4 @@ extern long int strtol(const char *str, char **endptr, int base); * @param base - the base to convert to * @returns 0 on error or success, error if endptr is still equal to str */ -extern long long int strtoll(const char *str, char **endptr, int base); +long long int strtoll(const char *str, char **endptr, int base); |