Newer
Older
rtlibc / inc / string.h
/* Copyright (C) Thornwave Labs Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
 */

#ifndef _RTLIBC_STRING_H
#define _RTLIBC_STRING_H


#include <stdint.h>
#include <stddef.h>


#define memzero(ptr, size) memset(ptr, 0, size)


#ifdef __cplusplus
extern "C"
{
#endif

//String manipulation functions

void strtrim(char **str, const char *trim);

size_t strlen(const char *str);
size_t strnlen(const char *str, size_t num);
size_t wstrlen(const uint16_t *str);

char* strcat(char *dest, const char *src);
char* strncat(char *dest, const char *src, size_t num);


char* strchr(const char *str, char c);
//char* strrchr(const char *str, char c);


//const char* strstr(const char *str1, const char *str2);
char* strstr(char *str1, const char *str2);
char* stristr(char *str1, const char *str2);



int strcmp(const char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, size_t num);

int stricmp(const char *str1, const char *str2);
#define strcasecmp stricmp

int strincmp(const char *str1, const char *str2, size_t num);


char* strcpy(char *dest, const char *src);
char* strncpy(char *dest, const char *src, size_t num);

size_t strspn(const char *str1, const char *str2);
size_t strcspn(const char *str1, const char *str2);


char* strdup(const char *s1);

char* strpbrk(char *str1, const char *str2);


char* strstr(char *str1, const char *str2);

char* strtok(char *str, const char *delim);
char* strtok_r(char *str, const char *delim, char **saveptr);

char* strtok_m(char *str, const char *delim, const char *token_markers);
char* strtok_rm(char *str, const char *delim, char **saveptr, const char *token_markers);



//memory functions
void* memcpy(void *dest, const void *src, size_t num);
void* memmove(void *dest, const void *src, size_t num);


void* memchr(void *ptr, uint8_t value, size_t num);

int memcmp(const void *ptr1, const void *ptr2, size_t num);


void* memset(void *ptr, uint8_t value, size_t num);


const char* strfile(const char *fullpath);

//get the path part with specified number of levels
//(0 means full path)
//positive means that many levels from the left (1 means root level "/")
//negative means full path less that meny levels from the end (-1 means all levels except last)
char* strpath(const char *fullpath, int level);


#ifdef __cplusplus
}
#endif


#endif