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.
56 lines
2.0 KiB
56 lines
2.0 KiB
5 years ago
|
/**
|
||
|
* Strcat variant respecting buffer capacity.
|
||
|
* Function signatures based on libbsd.
|
||
|
*
|
||
|
* Created by Ondřej Hruška on 2020/09/19.
|
||
|
*/
|
||
|
|
||
|
#ifndef STRLCAT_H
|
||
|
#define STRLCAT_H
|
||
|
|
||
|
#include <stddef.h>
|
||
|
|
||
|
/**
|
||
|
* Append a zero-terminated to a zero-terminated buffer.
|
||
|
*
|
||
|
* @param[out] dst - destination buffer
|
||
|
* @param[in] src - source string
|
||
|
* @param[in] capacity - destination buffer capacity
|
||
|
* @return The buffer size needed. If > size, then data loss occurred. Returns 0 if invalid arguments were supplied.
|
||
|
*/
|
||
|
size_t strlcat(char *__restrict__ dst, const char *__restrict__ src, size_t capacity);
|
||
|
|
||
|
/**
|
||
|
* Append at most N characters of a zero-terminated string to a zero-terminated buffer.
|
||
|
*
|
||
|
* @param[out] dst - destination buffer
|
||
|
* @param[in] src - source string
|
||
|
* @param[in] capacity - destination buffer capacity
|
||
|
* @param[in] num - number of bytes to write
|
||
|
* @return The buffer size needed. If > size, then data loss occurred. Returns 0 if invalid arguments were supplied.
|
||
|
*/
|
||
|
size_t strlncat(char *__restrict__ dst, const char *__restrict__ src, size_t capacity, size_t num);
|
||
|
|
||
|
/**
|
||
|
* Copy a zero-terminated string to a zero-terminated buffer.
|
||
|
*
|
||
|
* @param[out] dst - destination buffer
|
||
|
* @param[in] src - source string
|
||
|
* @param[in] capacity - destination buffer capacity
|
||
|
* @return The buffer size needed. If > size, then data loss occurred. Returns 0 if invalid arguments were supplied.
|
||
|
*/
|
||
|
size_t strlcpy(char *__restrict__ dst, const char *__restrict__ src, size_t capacity);
|
||
|
|
||
|
/**
|
||
|
* Copy at most N characters of a zero-terminated string to a zero-terminated buffer.
|
||
|
*
|
||
|
* @param[out] dst - destination buffer
|
||
|
* @param[in] src - source string
|
||
|
* @param[in] capacity - destination buffer capacity
|
||
|
* @param[in] num - number of bytes to write
|
||
|
* @return The buffer size needed. If > size, then data loss occurred. Returns 0 if invalid arguments were supplied.
|
||
|
*/
|
||
|
size_t strlncpy(char *__restrict__ dst, const char *__restrict__ src, size_t capacity, size_t num);
|
||
|
|
||
|
#endif //STRLCAT_H
|