xregex.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* xregex.c - regex functions with error messages
  2. Carl D. Worth
  3. Copyright (C) 2001 University of Southern California
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. */
  13. #include "xregex.h"
  14. #include "libbb/libbb.h"
  15. static void print_regcomp_err(const regex_t * preg, int err);
  16. int xregcomp(regex_t * preg, const char *regex, int cflags)
  17. {
  18. int err;
  19. err = regcomp(preg, regex, cflags);
  20. if (err) {
  21. print_regcomp_err(preg, err);
  22. }
  23. return err;
  24. }
  25. static void print_regcomp_err(const regex_t * preg, int err)
  26. {
  27. unsigned int size;
  28. char *error;
  29. size = regerror(err, preg, 0, 0);
  30. error = xcalloc(1, size);
  31. regerror(err, preg, error, size);
  32. opkg_msg(ERROR, "Internal error compiling regex: %s.", error);
  33. free(error);
  34. }