3
0

xregcomp.c 768 B

12345678910111213141516171819202122232425262728293031
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) many different people.
  6. * If you wrote this, please acknowledge your work.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  9. */
  10. #include "libbb.h"
  11. #include "xregex.h"
  12. char* FAST_FUNC regcomp_or_errmsg(regex_t *preg, const char *regex, int cflags)
  13. {
  14. int ret = regcomp(preg, regex, cflags);
  15. if (ret) {
  16. int errmsgsz = regerror(ret, preg, NULL, 0);
  17. char *errmsg = xmalloc(errmsgsz);
  18. regerror(ret, preg, errmsg, errmsgsz);
  19. return errmsg;
  20. }
  21. return NULL;
  22. }
  23. void FAST_FUNC xregcomp(regex_t *preg, const char *regex, int cflags)
  24. {
  25. char *errmsg = regcomp_or_errmsg(preg, regex, cflags);
  26. if (errmsg) {
  27. bb_error_msg_and_die("bad regex '%s': %s", regex, errmsg);
  28. }
  29. }