carb::memory::protectedStrncpy

Defined in carb/memory/Util.h

inline bool carb::memory::protectedStrncpy(char *dest, const char *source, size_t n)

Copies memory as via strncpy, but returns false if an access violation occurs while reading.

Thread Safety

This function is safe to call concurrently. However, this function makes no guarantees about the consistency of data copied when the data is modified while copied, only the attempting to read invalid memory will not result in an access violation.

Warning

This function is designed for safety, not performance, and may be very slow to execute.

Warning

The source and dest buffers may not overlap.

Parameters
  • dest – The destination buffer that will receive the memory. Must be at least n bytes in size.

  • source – The source buffer. Up to n bytes will be copied.

  • n – The maximum number of characters of source to copy to dest. If no NUL character was encountered in the first n - 1 characters of source, then dest[n - 1] will be a NUL character. This is a departure from strncpy() but similar to strncpy_s().

Returns

true if the memory was successfully copied; false otherwise. If false is returned, dest is in a valid but undefined state.