Pelles C forum

C language => Windows questions => Topic started by: czerny on August 13, 2014, 10:27:38 AM

Title: wcsncpy_s and _TRUNCATE
Post by: czerny on August 13, 2014, 10:27:38 AM
The MS implementation of wcsncpy_s knows as the fourth parameter a constant _TRUNCATE.

I have found the following definition, but it makes not much sense to me:
Code: [Select]
#if !defined(_TRUNCATE)
#define _TRUNCATE ((size_t)-1)
#endif

Is the above definition right?

I expect, as the name implies, that the function shall truncate all chars which do not fit in the buffer.
I am right? Is the dest string nevertheless terminated by zero?
Title: Re: wcsncpy_s and _TRUNCATE
Post by: JohnF on August 13, 2014, 11:35:50 AM
From the MSDN web site.

These functions try to copy the first D characters of strSource to strDest, where D is the lesser of count and the length of strSource. If those D characters will fit within strDest (whose size is given as numberOfElements) and still leave room for a null terminator, then those characters are copied and a terminating null is appended; otherwise, strDest[0] is set to the null character and the invalid parameter handler is invoked, as described in Parameter Validation.
There is an exception to the above paragraph. If count is _TRUNCATE, then as much of strSource as will fit into strDest is copied while still leaving room for the terminating null which is always appended.

John
Title: Re: wcsncpy_s and _TRUNCATE
Post by: czerny on August 13, 2014, 12:12:13 PM
Now, after your post, I am able to google this same information without problems.  :( Thanks!