The Challenge of Writing Correct System Calls
If you are a veteran of using Windows APIs, you might be familiar with some patterns. One of them is the dual return value:
Documentation: somefunc(), will return some value other than 0 upon success. On failure, it will return 0, and you can then call GetLastError() to find out which error actually occured…
In some cases, 0 means error. In some cases, 0 means success, and anything else is actually the error. In some cases they return BOOL, and some BOOLEAN (completely different!).
Another pattern is the “pass me a buffer, and a size…”
int somefunc(char *buff, int sizeofbuff)
Documentation: Pass in a buffer, and the size of the buffer. If the ‘sizebuff’ == 0, then the return value will indicate how many bytes need to be allocated in the buffer, so you can call the function again.
A slight variant is this one:
int somefunc(char *buff…
View original post 741 more words