You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buffer.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* This file is part of Netsukuku
  2. * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
  3. *
  4. * This source code is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as published
  6. * by the Free Software Foundation; either version 2 of the License,
  7. * or (at your option) any later version.
  8. *
  9. * This source code is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * Please refer to the GNU Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Public License along with
  15. * this source code; if not, write to:
  16. * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * --
  19. * buffer.c: various functions to manipulate buffers
  20. */
  21. #ifndef BUFFER_H
  22. #define BUFFER_H
  23. /*
  24. * In bzero(3):
  25. * <<4.3BSD. This function [bzero] is deprecated -- use memset in new
  26. * programs.>>
  27. */
  28. #define setzero(_p, _sz) memset((_p), 0, (_sz))
  29. /*
  30. * memput
  31. *
  32. * It copies `__sz' bytes from `__src' to `__dst' and then increments the `__dst'
  33. * pointer of `__sz' bytes.
  34. *
  35. * *WARNING*
  36. * Do NOT put expression in `__dst', and `__sz', f.e.
  37. * *WRONG CODE*
  38. * memput(buf++, src, (size+=sizeof(src));
  39. *
  40. * *CORRECT CODE*
  41. * buf++; size+=sizeof(src);
  42. * memput(buf, src, size);
  43. * *WARNING*
  44. */
  45. #define memput(__dst, __src, __sz) \
  46. ({ \
  47. void *_bufret=memcpy((__dst), (__src), (__sz)); \
  48. (__dst)+=(__sz); \
  49. _bufret; \
  50. })
  51. /*
  52. * memget
  53. *
  54. * the same of memput(), but it increments `__src' instead.
  55. */
  56. #define memget(__dst, __src, __sz) \
  57. ({ \
  58. void *_bufret=memcpy((__dst), (__src), (__sz)); \
  59. (__src)+=(__sz); \
  60. _bufret; \
  61. })
  62. /* use of hardcoded `_src' and `_dst' variable names */
  63. #define bufput(_src, _sz) (memput(buf, (_src), (_sz)))
  64. #define bufget(_dst, _sz) (memget((_dst), buf, (_sz)))
  65. /*\
  66. * * * * Functions declaration * * *
  67. \*/
  68. int is_bufzero(const void *a, int sz);
  69. #endif /*BUFFER_H */