[DRMAA-WG] C binding -- string lengths
piotr.domagalski at man.poznan.pl
Thu Oct 23 10:29:28 CDT 2008
As I've been lately looking at some example DRMAA code, e.g. the one
in the testsuite, it appeared to me that the size/length of buffer in
C binding is still a bit messy...
Almost all the example codes look like this:
drmaa_init(NULL, buf, sizeof(buf) - 1);
The third parameter is called err_diag_len. From DRMAA C Binding:
error_diagnosis – A buffer into which error diagnosis information will
error_diag_len – The size in characters of the error diagnosis string buffer.
So if error_diag_len is supposed to mean size of the string buffer why
sizeof(buf) is not used? Shouldn't it be called error_diag_size to be
I remember Hrabri saying that sizeof(buf) - 1 is to be used because
that is what programmers are used to. And I cannot agree with that.
This is what they use e.g. with strncpy() and it causes a *lot* of
confusion and errors (just man strncpy). Take a look at snprintf or
strftime which are supposed to get sizeof(buf), or strlcat/strlcpy
(not available in glibc) and it makes life a lot simpler -- you just
supply the total size of the buffer and don't worry about the output
being nul-terminated or not (it always is, even when the string is
I know it's a little detail but I like things being consistent :)
More information about the drmaa-wg