diff --git a/include/ucore/dstr.h b/include/ucore/dstr.h index 083de2f..e71c397 100644 --- a/include/ucore/dstr.h +++ b/include/ucore/dstr.h @@ -47,7 +47,7 @@ void uc_dstr_destroy(struct DStr *str); * * @return 0 if success, != 0 if allocation fails */ -int uc_dstr_copy(struct DStr *dest, const struct DStr *src); +int uc_dstr_copy(struct DStr *restrict dest, const struct DStr *restrict src); /** * @return the available/unused tail bytes in the string. @@ -95,7 +95,7 @@ char *uc_dstr_put(struct DStr *str, size_t len); * @param is_x ctype.h compatible function to use as a filter. * @return number of chars appended */ -size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c)); +size_t uc_dstr_put_str_filter(struct DStr *str, const char *restrict s, int (*is_x)(int c)); /* Append a string of the give size. * (The nul terminator is not appended) @@ -104,14 +104,14 @@ size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c * @param len bytes to append (not including the nul terminator) * @return 0 on success (!= 0 if an allocation fail) */ -int uc_dstr_put_str_sz(struct DStr *str, const char *s, size_t len); +int uc_dstr_put_str_sz(struct DStr *str, const char *restrict s, size_t len); /* Append a string. * (The nul terminator is not appended) * * @return 0 on success (!= 0 if an allocation fail) */ -int uc_dstr_put_str(struct DStr *str, const char *s); +int uc_dstr_put_str(struct DStr *str, const char *restrict s); /* Append a single char. * @@ -122,7 +122,7 @@ int uc_dstr_put_char(struct DStr *str, char c); /* Make the DStr take ownership of the given dynamically allocated string. * Any existing string in the DStr is freed. */ -void uc_dstr_own(struct DStr *str, char *s); +void uc_dstr_own(struct DStr *str, char *restrict s); /** Release the managed string. * The caller is now responsible for managing/free'ing the returned string. @@ -133,7 +133,7 @@ void uc_dstr_own(struct DStr *str, char *s); char *uc_dstr_steal(struct DStr *str); /** Swap the A and B DStr */ -void uc_str_swap(struct DStr *a, struct DStr *b); +void uc_str_swap(struct DStr *restrict a, struct DStr *restrict b); /** Replace all occurences in the DStr * (This may be used to replace any embedded nul bytes too) @@ -149,10 +149,10 @@ size_t uc_dstr_replace(struct DStr *str, char f, char r); void uc_dstr_trim(struct DStr *str); /** Append formatted string (just as sprintf)*/ -int uc_dstr_sprintf(struct DStr *str, const char *fmt, ...) __attribute__((format(printf,2,3))); +int uc_dstr_sprintf(struct DStr *str, const char *restrict fmt, ...) __attribute__((format(printf,2,3))); /** va_list variant */ -int uc_dstr_vsprintf(struct DStr *str, const char *fmt, va_list ap_)__attribute__((format(printf,2,0))); +int uc_dstr_vsprintf(struct DStr *str, const char *restrict fmt, va_list ap_)__attribute__((format(printf,2,0))); #ifdef __cplusplus } diff --git a/include/ucore/mbuf.h b/include/ucore/mbuf.h index c73cd36..73dc17e 100644 --- a/include/ucore/mbuf.h +++ b/include/ucore/mbuf.h @@ -125,7 +125,7 @@ struct MBuf *uc_mbuf_copy_data(struct MBuf *mbuf); * @param headroom the headroom in the buffer * @param flags The appropriate UC_MBUF_FLAGS */ -void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags); +void uc_mbuf_init(struct MBuf *mbuf, uint8_t *restrict buf, uint32_t len, uint32_t headroom, uint32_t flags); /** Zero out all the data in this mbuf, including the headroom * diff --git a/include/ucore/string.h b/include/ucore/string.h index 7914f01..f1269fb 100644 --- a/include/ucore/string.h +++ b/include/ucore/string.h @@ -18,7 +18,7 @@ extern "C" { * @param out where to store result. Must hold at least len * 2 + 1 * @return returns one past the end of the converted data */ -char* uc_hex_encode(const uint8_t *in, size_t len, char *out); +char* uc_hex_encode(const uint8_t *restrict in, size_t len, char *restrict out); /** Decode hex. Will stop at the first non-convertible hex-digit * spaces(' ','\t,'\r','\n') in input are skipped @@ -32,11 +32,11 @@ char* uc_hex_encode(const uint8_t *in, size_t len, char *out); * @param out where to store result. Must hold at least maxlen/2 + 1 * @return returns one past the end of the converted data */ -uint8_t* uc_hex_decode(const char *in, size_t maxlen,uint8_t *out); +uint8_t* uc_hex_decode(const char *restrict in, size_t maxlen,uint8_t *restrict out); /** As uc_hex_encode , but inserts the @delim string between each converted * byte (each 2 hex chars) */ -char* uc_hex_encode_delim(const uint8_t *in, size_t inlen, char *out, int outlen, const char *delim); +char* uc_hex_encode_delim(const uint8_t *restrict in, size_t inlen, char *restrict out, int outlen, const char *restrict delim); /** * Convert the string to lowercase, calls tolower() on each char. @@ -67,7 +67,7 @@ void uc_str_toupper(char *s); * if the number of ASCII digits is odd. This would usually be 0x0 or 0xf. * @return the number of bytes written to bcdout */ -size_t uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler); +size_t uc_ascii2bcd(const char *restrict ascii, unsigned char *restrict bcdout, unsigned char filler); /** Convert the BCD digits to ascii. * The resulting ascii string is 0 terminated. @@ -77,7 +77,7 @@ size_t uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char fill * @param asciiout buffer to place ASCII in, must be UC_ASCII_LEN(bcdlen)+1 big * @return the number of characters written to bcdout (this will always be UC_ASCII_LEN(bcdlen) */ -size_t uc_bcd2ascii(const unsigned char *bcd, size_t bcdlen, char *asciiout); +size_t uc_bcd2ascii(const unsigned char *restrict bcd, size_t bcdlen, char *restrict asciiout); /** uc_sprintb for converting the values into ascii bit representation * e.g. 0x3 -> "00000011". The result must be able to hold the max number @@ -111,7 +111,7 @@ char * uc_human_bytesz_bin(uint64_t bytes, char *result, size_t result_len); * is normally the size of the dst buffer) * return strlen(src) which may be larger than the no. of bytes copied. */ -size_t uc_strlcpy(char *dst, const char *src, size_t max); +size_t uc_strlcpy(char *restrict dst, const char *restrict src, size_t max); #ifdef __cplusplus } diff --git a/include/ucore/strvec.h b/include/ucore/strvec.h index c854161..f4be722 100644 --- a/include/ucore/strvec.h +++ b/include/ucore/strvec.h @@ -52,7 +52,7 @@ int uc_strv_check_expand(struct UCStrv *strv); * @param str String to append, the string will be copied. * @return 0 on success, otherwise failure **/ -int uc_strv_append(struct UCStrv *strv, const char *str); +int uc_strv_append(struct UCStrv *strv, const char *restrict str); /** * Append a string to the strvec, nocopy variang. @@ -63,7 +63,7 @@ int uc_strv_append(struct UCStrv *strv, const char *str); * @param str the string to append * @return 0 on success, otherwise failure **/ -int uc_strv_append_nocopy(struct UCStrv *strv, char *str); +int uc_strv_append_nocopy(struct UCStrv *strv, char *restrict str); /** * Append a NULL pointer to the UCStrv, (cnt is not increased, @@ -98,7 +98,7 @@ void uc_strv_destroy(struct UCStrv *strv); * 0 to just append the same pointer in b to a * @return 0 on success, != 0 if appending/allocation fails */ -int uc_strv_append_all(struct UCStrv *a, struct UCStrv *b, int copy); +int uc_strv_append_all(struct UCStrv *restrict a, struct UCStrv *restrict b, int copy); #ifdef __cplusplus } diff --git a/include/ucore/val_str.h b/include/ucore/val_str.h index 9e180b5..9ee6cae 100644 --- a/include/ucore/val_str.h +++ b/include/ucore/val_str.h @@ -48,6 +48,6 @@ const char *uc_val_2_str_bs(unsigned int val, * @param array array to search * @return the string associated with @val or null */ -const char *uc_str_2_str(const char *val, const struct UCStrStr *array); +const char *uc_str_2_str(const char *restrict val, const struct UCStrStr *array); #endif diff --git a/src/bcd.c b/src/bcd.c index 4cfb9ff..7590656 100644 --- a/src/bcd.c +++ b/src/bcd.c @@ -4,7 +4,7 @@ #include "ucore/string.h" size_t -uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler) +uc_ascii2bcd(const char *restrict ascii, unsigned char *restrict bcdout, unsigned char filler) { unsigned char *bcdp = bcdout; int shift = 0; @@ -36,7 +36,7 @@ uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler) static const char hex[] = "0123456789ABCDEF"; size_t -uc_bcd2ascii(const unsigned char *bcd, size_t bcdlen, char *asciiout) +uc_bcd2ascii(const unsigned char *restrict bcd, size_t bcdlen, char *restrict asciiout) { size_t i; size_t idx = 0; diff --git a/src/dstr.c b/src/dstr.c index a9ddf4d..99be0bc 100644 --- a/src/dstr.c +++ b/src/dstr.c @@ -106,7 +106,7 @@ char *uc_dstr_put(struct DStr *str, size_t len) return start; } -size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c)) +size_t uc_dstr_put_str_filter(struct DStr *str, const char *restrict s, int (*is_x)(int c)) { size_t len = strlen(s); size_t i; @@ -128,7 +128,7 @@ size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c return idx; } -int uc_dstr_put_str_sz(struct DStr *str, const char *s, size_t len) +int uc_dstr_put_str_sz(struct DStr *str, const char *restrict s, size_t len) { char *start = uc_dstr_put(str, len); @@ -140,7 +140,7 @@ int uc_dstr_put_str_sz(struct DStr *str, const char *s, size_t len) return 0; } -int uc_dstr_put_str(struct DStr *str, const char *s) +int uc_dstr_put_str(struct DStr *str, const char *restrict s) { size_t len = strlen(s); @@ -159,7 +159,7 @@ int uc_dstr_put_char(struct DStr *str, char c) return 0; } -void uc_dstr_own(struct DStr *str, char *s) +void uc_dstr_own(struct DStr *str, char *restrict s) { size_t len = strlen(s); @@ -181,7 +181,7 @@ char *uc_dstr_steal(struct DStr *str) return s; } -void uc_str_swap(struct DStr *a, struct DStr *b) +void uc_str_swap(struct DStr *restrict a, struct DStr *restrict b) { struct DStr tmp; @@ -236,7 +236,7 @@ void uc_dstr_trim(struct DStr *str) } } -int uc_dstr_sprintf(struct DStr *str, const char *fmt, ...) +int uc_dstr_sprintf(struct DStr *str, const char *restrict fmt, ...) { va_list ap; int rc; @@ -248,7 +248,7 @@ int uc_dstr_sprintf(struct DStr *str, const char *fmt, ...) return rc; } -int uc_dstr_vsprintf(struct DStr *str, const char *fmt, va_list ap_) +int uc_dstr_vsprintf(struct DStr *str, const char *restrict fmt, va_list ap_) { va_list ap; int rc; diff --git a/src/hex.c b/src/hex.c index b2a162d..1b01ad9 100644 --- a/src/hex.c +++ b/src/hex.c @@ -8,7 +8,7 @@ static const char hx_chars[] = "0123456789ABCDEF" ; char* -uc_hex_encode(const uint8_t *in, size_t len, char *out) +uc_hex_encode(const uint8_t *restrict in, size_t len, char *restrict out) { unsigned int i, t; @@ -28,7 +28,7 @@ uc_hex_encode(const uint8_t *in, size_t len, char *out) } char* -uc_hex_encode_delim(const uint8_t *in, size_t inlen, char *out, int outlen, const char *delim) +uc_hex_encode_delim(const uint8_t *restrict in, size_t inlen, char *restrict out, int outlen, const char *restrict delim) { size_t i; char *outp = out; @@ -76,7 +76,7 @@ static inline int char_to_bin(char c) } uint8_t* -uc_hex_decode(const char *in, size_t maxlen,uint8_t *out) +uc_hex_decode(const char *restrict in, size_t maxlen,uint8_t *restrict out) { size_t i, t; diff --git a/src/mbuf.c b/src/mbuf.c index 4dd52e1..b4ab023 100644 --- a/src/mbuf.c +++ b/src/mbuf.c @@ -40,7 +40,7 @@ uint8_t *uc_mbuf_pull(struct MBuf *mbuf, uint32_t size) return data; } -void uc_mbuf_init(struct MBuf *mbuf, uint8_t *buf, uint32_t len, uint32_t headroom, uint32_t flags) +void uc_mbuf_init(struct MBuf *mbuf, uint8_t *restrict buf, uint32_t len, uint32_t headroom, uint32_t flags) { mbuf->bufstart = buf; mbuf->p1 = mbuf->p2 = mbuf->p3 = mbuf->p4 = NULL; diff --git a/src/strlcpy.c b/src/strlcpy.c index dc67290..6f9682a 100644 --- a/src/strlcpy.c +++ b/src/strlcpy.c @@ -1,6 +1,6 @@ #include -size_t uc_strlcpy(char *dst, const char *src, size_t max) +size_t uc_strlcpy(char *restrict dst, const char *restrict src, size_t max) { size_t len = strlen(src); diff --git a/src/strvec.c b/src/strvec.c index 276a0be..1e9f00a 100644 --- a/src/strvec.c +++ b/src/strvec.c @@ -36,7 +36,7 @@ int uc_strv_check_expand(struct UCStrv *strv) return rc; } -int uc_strv_append(struct UCStrv *strv, const char *str) +int uc_strv_append(struct UCStrv *strv, const char *restrict str) { int rc; char *dup; @@ -57,7 +57,7 @@ int uc_strv_append(struct UCStrv *strv, const char *str) return 0; } -int uc_strv_append_nocopy(struct UCStrv *strv, char *str) +int uc_strv_append_nocopy(struct UCStrv *strv, char *restrict str) { int rc; rc = uc_strv_check_expand(strv); @@ -105,7 +105,7 @@ void uc_strv_destroy(struct UCStrv *strv) strv->strings = NULL; } -int uc_strv_append_all(struct UCStrv *a, struct UCStrv *b, int copy) +int uc_strv_append_all(struct UCStrv *restrict a, struct UCStrv *restrict b, int copy) { size_t i; int rc; diff --git a/src/val_str.c b/src/val_str.c index 4ff0fe0..ea92321 100644 --- a/src/val_str.c +++ b/src/val_str.c @@ -47,7 +47,7 @@ const char *uc_val_2_str_bs(unsigned int val, return found; } -const char *uc_str_2_str(const char *val, const struct UCStrStr *array) +const char *uc_str_2_str(const char *restrict val, const struct UCStrStr *array) { const char *found = NULL;