smb_buffer.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*****************************************************************************
  2. * __________________ _________ _____ _____ .__ ._.
  3. * \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. * | | \| ` \/ / Y \ / | | \ ___/ \|
  6. * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. * \/ \/ \/ \/ )/ \/ \/ \/
  8. *
  9. * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
  10. *
  11. * Author: Julien 'Lta' BALLET <contact@lta.io>
  12. *
  13. * liBDSM is released under LGPLv2.1 (or later) and is also available
  14. * under a commercial license.
  15. *****************************************************************************
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation; either version 2.1 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  29. *****************************************************************************/
  30. #include <assert.h>
  31. #include <stdlib.h>
  32. #ifdef HAVE_ALLOCA_H
  33. # include <alloca.h>
  34. #endif
  35. #include "smb_buffer.h"
  36. void smb_buffer_init(smb_buffer *buf, void *data, size_t size)
  37. {
  38. assert(buf != NULL);
  39. buf->data = data;
  40. buf->size = size;
  41. }
  42. int smb_buffer_alloc(smb_buffer *buf, size_t size)
  43. {
  44. assert(buf != NULL);
  45. buf->data = malloc(size);
  46. if (buf->data) {
  47. buf->size = size;
  48. return (1);
  49. } else
  50. return (0);
  51. }
  52. void smb_buffer_free(smb_buffer *buf)
  53. {
  54. if (buf == NULL || buf->data == NULL)
  55. return;
  56. free(buf->data);
  57. smb_buffer_init(buf, NULL, 0);
  58. }