[DRMAA-WG] C binding -- string lengths
Roger Brobst
rogerb at cadence.com
Fri Oct 24 13:57:59 CDT 2008
> How would you implement the string copying in drmaa_init()?
> One would probably use the following code:
>
> int
> drmaa_init(..., char *err_diag, size_t err_diag_len)
> {
> strncpy(err_diag, SRC, err_diag_len)
> }
I would not use use strncpy because
if the string fits into the buffer,
I see no reason to zero-fill the remainder of the buffer;
if the string doesn't fit,
the implementation should not copy an unterminated string
into the buffer.
Assuming I wasn't doing any form of error checking, I would use
int
drmaa_init(..., char *err_diag, size_t err_diag_len)
{
*err_diag = '\0', strncat( err_diag, SRC, err_diag_len )
}
More information about the drmaa-wg
mailing list