1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/libc/string.c

54 lines
933 B
C
Raw Normal View History

2022-09-21 16:26:32 +02:00
/*
* Copyright (C) 2022 ML!PA Consulting GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file
*
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*/
#include <errno.h>
#include "string_utils.h"
ssize_t strscpy(char *dest, const char *src, size_t count)
{
const char *start = dest;
if (!count) {
return -E2BIG;
}
while (--count && *src) {
*dest++ = *src++;
}
*dest = 0;
if (*src == 0) {
return dest - start;
} else {
return -E2BIG;
}
}
const void *memchk(const void *data, uint8_t c, size_t len)
{
const uint8_t *end = (uint8_t *)data + len;
for (const uint8_t *d = data; d != end; ++d) {
if (c != *d) {
return d;
}
}
return NULL;
}
2022-09-21 16:26:32 +02:00
/** @} */