C and C++ web framework. http://rapida.vilor.one/docs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
786 B

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright 2022 Ivan Polyakov */
#include "utils.h"
#include <stdlib.h>
#include <string.h>
int count_char_entries(const char *str, char ch)
{
int cnt = 0;
while (*str) {
if (*str == ch) {
cnt++;
}
str++;
}
return cnt;
}
char *rpd_strdup(const char *src)
{
size_t size = strlen(src) + 1;
char *dest = (char *) malloc(sizeof(char) * size);
if (!dest) {
return NULL;
}
return memcpy(dest, src, size);
}
char *rpd_strsep(char **str, const char *sep)
{
char *s = *str, *end;
if (!s) {
return NULL;
}
end = s + strcspn(s, sep);
if (*end) {
*end++ = 0;
} else {
end = 0;
}
*str = end;
return s;
}