/* ******** nrrdContentSet ** ** Kind of like sprintf, but for the content string of the nrrd. ** ** Whether or not we write a new content for an old nrrd ("nin") with ** NULL content is decided here, according to ** nrrdStateAlwaysSetContent. ** ** Does the string allocation and some attempts at error detection. ** Does allow nout==nin, which requires some care. */ int nrrdContentSet_va(Nrrd *nout, const char *func, const Nrrd *nin, const char *format, ...) { static const char me[]="nrrdContentSet_va"; va_list ap; char *content; if (!(nout && func && nin && format)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (nrrdStateDisableContent) { /* we kill content always */ nout->content = (char *)airFree(nout->content); return 0; } if (!nin->content && !nrrdStateAlwaysSetContent) { /* there's no input content, and we're not supposed to invent any content, so after freeing nout's content we're done */ nout->content = (char *)airFree(nout->content); return 0; } /* we copy the input nrrd content first, before blowing away the output content, in case nout == nin */ content = _nrrdContentGet(nin); va_start(ap, format); if (_nrrdContentSet_nva(nout, func, content, format, ap)) { biffAddf(NRRD, "%s:", me); va_end(ap); free(content); return 1; } va_end(ap); free(content); return 0; }
int _nrrdContentSet_va(Nrrd *nout, const char *func, char *content, const char *format, ...) { static const char me[]="_nrrdContentSet_va"; va_list ap; va_start(ap, format); if (_nrrdContentSet_nva(nout, func, content, format, ap)) { biffAddf(NRRD, "%s:", me); free(content); return 1; } va_end(ap); /* free(content); */ return 0; }
int _nrrdContentSet_va(Nrrd *nout, const char *func, char *content, const char *format, ...) { char me[]="_nrrdContentSet_va", err[BIFF_STRLEN]; va_list ap; va_start(ap, format); if (_nrrdContentSet_nva(nout, func, content, format, ap)) { sprintf(err, "%s:", me); biffAdd(NRRD, err); free(content); return 1; } va_end(ap); /* free(content); */ return 0; }