The normal APIs for creating values expect a zero-terminated string, so they cannot be used for creating a YANG leaf with the binary type.
Use the val_make_binary_obj function from ncx/val_util.h
Also check val_set_simval_binary in ncx/val.h
These functions take a buffer and buffer length as input and do not expect a zero-terminated string.
The val_make_binary_obj function shows an example usage of the val_set_simval_binary function.
/******************************************************************** * FUNCTION val_make_binary_obj * * Malloc and set a val_value_t as a NCX_BT_BINARY type * * INPUTS: * obj == object template to use set binary object * valstr == simple value encoded as a binary buffer * valstrlen == length of valstr (not zero-terminated) * res == address of return status * * OUTPUTS: * *res == return status * RETURNS: * malloced val struct filled in; NULL if malloc failed *********************************************************************/ val_value_t * val_make_binary_obj (obj_template_t *obj, const xmlChar *valstr, uint32 valstrlen, status_t *res) { assert(obj); assert(res); val_value_t *newval = val_new_value(); if (!newval) { *res = ERR_INTERNAL_MEM; return NULL; } val_init_from_template(newval, obj); *res = val_set_simval_binary(newval, valstr, valstrlen); if (*res != NO_ERR) { val_free_value(newval); newval = NULL; } return newval; } /* val_make_binary_obj */