/* ******** biffGet() ** ** creates a string which records all the errors at given key and ** returns it. Returns NULL in case of error. This function should ** be considered a glorified strdup(): it is the callers responsibility ** to free() this string later */ char * biffGet(const char *key) { static const char me[]="biffGet"; char *ret; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { static const char err[]="[%s] No information for this key!"; size_t errlen; fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); errlen = strlen(err)+strlen(key)+1; ret = AIR_CALLOC(errlen, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); exit(1); } #if defined(WIN32) || defined(_WIN32) _snprintf(ret, errlen, err, key); #else snprintf(ret, errlen, err, key); #endif return ret; } ret = AIR_CALLOC(biffMsgStrlen(msg)+1, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); exit(1); } biffMsgStrSet(ret, msg); return ret; }
/* ******** biffGet() ** ** creates a string which records all the errors at given key and ** returns it. Returns NULL in case of error. This function should ** be considered a glorified strdup(): it is the callers responsibility ** to free() this string later */ char * /*Teem: allocates char* */ /* this comment is an experiment */ biffGet(const char *key) { static const char me[]="biffGet"; char *ret; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { static const char err[]="[%s] No information for this key!"; size_t errlen; fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); errlen = strlen(err)+strlen(key)+1; ret = AIR_CALLOC(errlen, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); return NULL; /* exit(1); */ } snprintf(ret, errlen, err, key); return ret; } ret = AIR_CALLOC(biffMsgStrlen(msg)+1, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); return NULL; /* exit(1); */ } biffMsgStrSet(ret, msg); return ret; }
char * biffMsgStrGet(const biffMsg *msg) { char *ret; if (biffMsgNoop == msg) { return NULL; } ret = biffMsgStrAlloc(msg); biffMsgStrSet(ret, msg); return ret; }
/* ******** biffSetStr() ** ** for when you want to allocate the buffer for the biff string, this is ** how you get the error message itself */ void biffSetStr(char *str, const char *key) { static const char me[]="biffSetStr"; biffMsg *msg; if (!str) { fprintf(stderr, "%s: ERROR: got NULL buffer for \"%s\"\n", me, key); return; } _bmsgStart(); msg = _bmsgFind(key); if (!msg) { fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); return; } biffMsgStrSet(str, msg); return; }