xregcomp.c 744 B

1234567891011121314151617181920212223242526272829303132
  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 tarball for details.
  9. */
  10. #include "libbb.h"
  11. #include "xregex.h"
  12. char* 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 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("xregcomp: %s", errmsg);
  28. }
  29. }