cpr_get.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* $MirOS: contrib/hosted/fwcf/cpr_get.c,v 1.4 2007/03/09 22:35:13 tg Exp $ */
  2. /*-
  3. * Copyright (c) 2006, 2007
  4. * Thorsten Glaser <tg@mirbsd.de>
  5. *
  6. * Licensee is hereby permitted to deal in this work without restric-
  7. * tion, including unlimited rights to use, publicly perform, modify,
  8. * merge, distribute, sell, give away or sublicence, provided all co-
  9. * pyright notices above, these terms and the disclaimer are retained
  10. * in all redistributions or reproduced in accompanying documentation
  11. * or other materials provided with binary redistributions.
  12. *
  13. * Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
  14. * express, or implied, to the maximum extent permitted by applicable
  15. * law, without malicious intent or gross negligence; in no event may
  16. * licensor, an author or contributor be held liable for any indirect
  17. * or other damage, or direct damage except proven a consequence of a
  18. * direct error of said person and intended use of this work, loss or
  19. * other issues arising in any way out of its use, even if advised of
  20. * the possibility of such damage or existence of a defect.
  21. */
  22. #include <sys/param.h>
  23. #include <err.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "defs.h"
  27. #include "compress.h"
  28. fwcf_compressor *
  29. compressor_get(u_int8_t algo)
  30. {
  31. fwcf_compressor *list;
  32. if ((list = compress_enumerate()) == NULL)
  33. errx(1, "compress_enumerate");
  34. if (list[algo].name == NULL)
  35. errx(1, "compression algorithm %02Xh not loaded", algo);
  36. if (list[algo].init())
  37. errx(1, "cannot initialise %s compression", list[algo].name);
  38. return (&(list[algo]));
  39. }
  40. int
  41. compressor_getbyname(const char *s)
  42. {
  43. fwcf_compressor *cl;
  44. int i;
  45. if ((cl = compress_enumerate()) == NULL)
  46. errx(1, "no compression algorithms found");
  47. for (i = 1; i < 256; ++i)
  48. if (cl[i].name != NULL)
  49. if (!strcasecmp(cl[i].name, s))
  50. return (i);
  51. return (0);
  52. }