5 more simple patches for usr.bin/make
dillon at apollo.backplane.com
Sat Nov 13 11:48:50 PST 2004
:One thing you can improve is the use of static strings with write.
:E.g. instead of write(2, "BLA", 3); something either like
:const char msg_bla = "BLA";
:write(2, msg_bla, sizeof(msg_bla));
:#define WRITE(fd, str) write(fd, str, sizeof(str))
:would be useful, the hardwired string length is evil. Be careful though,
:the sizeof only works with char, not char * !
Well, remember that a string assignment to a char array includes
the terminating \0.. so that will not work quite the way you wrote
Just do this:
const char * const msg = "BLA";
write(fd, msg, strlen(msg));
GCC will calculate the strlen() for you at compile-time.
<dillon at xxxxxxxxxxxxx>
More information about the Submit