2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2006 by Graue.
|
2023-03-31 12:53:31 +00:00
|
|
|
// Copyright (C) 2006-2023 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file string.c
|
|
|
|
/// \brief String functions that we need but are missing on some
|
|
|
|
/// operating systems.
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "doomdef.h"
|
|
|
|
|
2023-08-07 02:34:50 +00:00
|
|
|
#ifndef SRB2_HAVE_STRLCPY
|
2016-03-26 00:37:14 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Like the OpenBSD version, but it doesn't check for src not being a valid
|
|
|
|
// C string.
|
|
|
|
size_t strlcat(char *dst, const char *src, size_t siz)
|
|
|
|
{
|
|
|
|
size_t dstlen, n = siz;
|
|
|
|
char *p = dst;
|
|
|
|
|
|
|
|
dstlen = strlen(dst);
|
|
|
|
n -= dstlen;
|
|
|
|
p += dstlen;
|
|
|
|
|
|
|
|
while (n > 1 && *src != '\0')
|
|
|
|
{
|
|
|
|
*p++ = *src++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n >= 1)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return strlen(src) + dstlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t strlcpy(char *dst, const char *src, size_t siz)
|
|
|
|
{
|
|
|
|
if (siz == 0)
|
|
|
|
return strlen(dst);
|
|
|
|
|
|
|
|
dst[0] = '\0';
|
|
|
|
return strlcat(dst, src, siz);
|
|
|
|
}
|
2016-03-26 00:37:14 +00:00
|
|
|
|
|
|
|
#endif
|
2019-04-22 06:18:40 +00:00
|
|
|
|
|
|
|
#include "strcasestr.c"
|
2022-10-15 01:20:52 +00:00
|
|
|
|
|
|
|
int startswith(const char *path, const char *tag)
|
|
|
|
{
|
|
|
|
return !strncmp(path, tag, strlen(tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
int endswith(const char *base, const char *tag)
|
|
|
|
{
|
|
|
|
const size_t base_length = strlen(base);
|
|
|
|
const size_t tag_length = strlen(tag);
|
|
|
|
|
|
|
|
if (tag_length > base_length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !memcmp(&base[base_length - tag_length], tag, tag_length);
|
|
|
|
}
|
2024-03-09 17:08:02 +00:00
|
|
|
|
|
|
|
// strtok version that only skips over one delimiter at a time
|
|
|
|
char *xstrtok(char *line, const char *delims)
|
|
|
|
{
|
|
|
|
static char *saveline = NULL;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if(line != NULL)
|
|
|
|
saveline = line;
|
|
|
|
|
|
|
|
// see if we have reached the end of the line
|
|
|
|
if(saveline == NULL || *saveline == '\0')
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p = saveline; // save start of this token
|
|
|
|
|
|
|
|
saveline += strcspn(saveline, delims); // get the number of non-delims characters, go past delimiter
|
|
|
|
|
|
|
|
if(*saveline != '\0') // trash the delim if necessary
|
|
|
|
*saveline++ = '\0';
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|