libosmocore[master]: utils: add osmo_strscpy() macro to use sizeof(dst)

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Jan 19 17:06:15 UTC 2017


Patch Set 5:

> yes but the array and sizeof are next to each other.

which makes sense, right? '...sizeof(a...'

 > http://stackoverflow.com/questions/19452971/array-size-macro-that-rejects-pointers

interesting :)
we depend on GNU-C anyway, do we?

 > #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 > 
 > with
 > 
 > #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
 > 
 > and
 > 
 > #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))

With this (slightly bulky) stuff in there, are you saying that osmo_strscpy() would be a good name after all?
Or maybe osmo_strbcpy() for "buffer"...

others have also used strzcpy and strbcpy names, but b meaning padding with "blank" (space?) and z meaning NUL, as it seems...
http://www.conetic.com/helpdoc/manpage/strzcpy.C.3.html
(whoever those people are)

so I guess osmo_strcpy_sizeof() is still most clear. Single letters are so ambiguous.

-- 
To view, visit https://gerrit.osmocom.org/1599
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ie973fc51835066540eba7ed2946ddf33a268b022
Gerrit-PatchSet: 5
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-HasComments: No


More information about the gerrit-log mailing list