compress.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* $MirOS: contrib/hosted/fwcf/compress.c,v 1.7 2006/09/23 23:46:35 tg Exp $ */
  2. /*-
  3. * Copyright (c) 2006
  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 "defs.h"
  26. #include "compress.h"
  27. static void compress_initialise(void);
  28. static fwcf_compressor *fwcf_compressors = NULL;
  29. int
  30. compress_register(fwcf_compressor *e)
  31. {
  32. compress_initialise();
  33. if (e == NULL)
  34. return (1);
  35. if ((e->init == NULL) || (e->compress == NULL) ||
  36. (e->decompress == NULL) || (e->name == NULL))
  37. return (1);
  38. if (fwcf_compressors[e->code].name != NULL)
  39. return (2);
  40. fwcf_compressors[e->code] = *e;
  41. return (0);
  42. }
  43. fwcf_compressor *
  44. compress_enumerate(void)
  45. {
  46. int i;
  47. fwcf_compressor *rv = NULL;
  48. compress_initialise();
  49. for (i = 0; i < 256; ++i)
  50. if (fwcf_compressors[i].name != NULL) {
  51. if (fwcf_compressors[i].code == i)
  52. rv = fwcf_compressors;
  53. else
  54. errx(1, "fwcf compressor registry invalid");
  55. }
  56. return (rv);
  57. }
  58. static void
  59. compress_initialise(void)
  60. {
  61. if (fwcf_compressors != NULL)
  62. return;
  63. if ((fwcf_compressors = calloc(256, sizeof (fwcf_compressor))) == NULL)
  64. err(1, "calloc");
  65. }