From: Alberto G. <ag...@ig...> - 2013-01-04 01:41:37
|
On Fri, Jan 04, 2013 at 12:07:13AM +0000, Stuart Brady wrote: > > fwrite( "fmfconv created AU file (http://fuse-emulator.sourceforge.net)\n", 64, 1, snd ); > I'll admit that there's often no right answer when using C's string > handling functions, but I would probably have opted for having a > const fixed-length buffer, larger than required by a fair margin, > and then relying on the compiler/OS ensuring uninitialised global > storage is zeroes (as this is perfectly safe to do), and then > calculating the length as something like wsize = strlen(buf) + 1 + > 7; wsize -= wsize % 8; with a comment explaining that this rounds > up to the nearest multiple of 8 *after* including space for the > null-terminator, and that the uninitialised bytes will be zeroed. Isn't it easier to do something like this? const char str[] = "fmfconv created AU file ..."; unsigned len = sizeof(str); /* Includes the null terminator */ fwrite(str, len, 1, snd); /* Pad with zeroes until the next multiple of 8 */ if (len % 8 != 0) { const char zeroes[7] = { 0 }; fwrite(zeroes, 8 - len % 8, 1, snd); } Berto |