c_null.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $MirOS: contrib/hosted/fwcf/c_null.c,v 1.5 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 <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include "defs.h"
  27. #include "compress.h"
  28. __RCSID("$MirOS: contrib/hosted/fwcf/c_null.c,v 1.5 2006/09/23 23:46:35 tg Exp $");
  29. static void c_null_load(void) __attribute__((constructor));
  30. static int c_init(void);
  31. static int c_compress(char **, char *, size_t)
  32. __attribute__((bounded (string, 2, 3)));
  33. static int c_decompress(char *, size_t, char *, size_t)
  34. __attribute__((bounded (string, 1, 2)))
  35. __attribute__((bounded (string, 3, 4)));
  36. static fwcf_compressor c_null = {
  37. c_init, /* init */
  38. c_compress, /* compress */
  39. c_decompress, /* decompress */
  40. "null", /* name */
  41. 0 /* code */
  42. };
  43. static void
  44. c_null_load(void)
  45. {
  46. if (compress_register(&c_null))
  47. fputs("warning: cannot register compressor 'null'!\n", stderr);
  48. }
  49. static int
  50. c_init(void)
  51. {
  52. return (0);
  53. }
  54. static int
  55. c_compress(char **dst, char *src, size_t len)
  56. {
  57. if ((*dst = malloc(len)) == NULL)
  58. return (-1);
  59. memcpy(*dst, src, len);
  60. return (len);
  61. }
  62. static int
  63. c_decompress(char *dst, size_t dstlen, char *src, size_t srclen)
  64. {
  65. size_t len = MIN(srclen, dstlen);
  66. memmove(dst, src, len);
  67. return (len);
  68. }