Beispiel #1
0
/*
******** 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;
}
Beispiel #2
0
/*
******** 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;
}
Beispiel #3
0
char *
biffMsgStrGet(const biffMsg *msg) {
  char *ret;

  if (biffMsgNoop == msg) {
    return NULL;
  }
  ret = biffMsgStrAlloc(msg);
  biffMsgStrSet(ret, msg);
  return ret;
}
Beispiel #4
0
/*
******** 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;
}