gets but safer
This is like
gets. It is a drop in for
gets. It is smarter though.
gets_safe, which is aliased to
gets for convenience, takes an optional length argument, but it also uses GCC and Clang's
__builtin_object_size builtin to calculate the length.
The length will not always be calculated properly, but for static arrays and
malloc'd pointers in the current block with a fixed size (only with optimizations), it will usually pick up on it.
This also has a safety feature: If it can properly calculate the length and the supplied length is larger than the one it calculated, it will be an error. Additionally, when both the optional length parameter are omitted and the length cannot be calculated at compile time, it is an error.