compress.c 2.2 KB

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