smb_buffer.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. #include <alloca.h>
  19. #include <assert.h>
  20. #include <stdlib.h>
  21. #include "bdsm/smb_buffer.h"
  22. void smb_buffer_init(smb_buffer *buf, void *data, size_t size)
  23. {
  24. assert(buf != NULL);
  25. buf->data = data;
  26. buf->size = size;
  27. }
  28. void smb_buffer_alloc(smb_buffer *buf, size_t size)
  29. {
  30. assert(buf != NULL);
  31. buf->data = malloc(size);
  32. buf->size = size;
  33. assert(buf->data != NULL);
  34. }
  35. void smb_buffer_free(smb_buffer *buf)
  36. {
  37. if (buf == NULL || buf->data == NULL)
  38. return;
  39. free(buf->data);
  40. smb_buffer_init(buf, NULL, 0);
  41. }