fileinfo.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "setup.h"
  23. #include <stdlib.h>
  24. #include "strdup.h"
  25. #include "fileinfo.h"
  26. #define _MPRINTF_REPLACE /* use our functions only */
  27. #include <curl/mprintf.h>
  28. #include "curl_memory.h"
  29. /* The last #include file should be: */
  30. #include "memdebug.h"
  31. struct curl_fileinfo *Curl_fileinfo_alloc(void)
  32. {
  33. struct curl_fileinfo *tmp = malloc(sizeof(struct curl_fileinfo));
  34. if(!tmp)
  35. return NULL;
  36. memset(tmp, 0, sizeof(struct curl_fileinfo));
  37. return tmp;
  38. }
  39. void Curl_fileinfo_dtor(void *user, void *element)
  40. {
  41. struct curl_fileinfo *finfo = element;
  42. (void) user;
  43. if(!finfo)
  44. return;
  45. if(finfo->b_data){
  46. free(finfo->b_data);
  47. }
  48. free(finfo);
  49. }
  50. struct curl_fileinfo *Curl_fileinfo_dup(const struct curl_fileinfo *src)
  51. {
  52. struct curl_fileinfo *ptr = malloc(sizeof(struct curl_fileinfo));
  53. if(!ptr)
  54. return NULL;
  55. *ptr = *src;
  56. ptr->b_data = malloc(src->b_size);
  57. if(!ptr->b_data) {
  58. free(ptr);
  59. return NULL;
  60. }
  61. else {
  62. memcpy(ptr->b_data, src->b_data, src->b_size);
  63. return ptr;
  64. }
  65. }