The code looks fine to me, though you don't need to include stdint.h. It is basically identical to what is in FreeBSD too.
In the man page example: if (p = wcsdup(L"foobar"), p == NULL) { I think it is best to either write this as: if ((p = wcsdup(L"foobar")) == NULL) { or just split it into two lines. Using the comma operator that way is correct but likely to confuse some readers. Also, what is that 'L' doing there before the "foobar"? Is it some sort of wide char thing I'm not aware of? - todd