wildcard.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 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 "curl_setup.h"
  23. #include "wildcard.h"
  24. #include "llist.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. CURLcode Curl_wildcard_init(struct WildcardData *wc)
  32. {
  33. DEBUGASSERT(wc->filelist == NULL);
  34. /* now allocate only wc->filelist, everything else
  35. will be allocated if it is needed. */
  36. wc->filelist = Curl_llist_alloc(Curl_fileinfo_dtor);
  37. if(!wc->filelist) {;
  38. return CURLE_OUT_OF_MEMORY;
  39. }
  40. return CURLE_OK;
  41. }
  42. void Curl_wildcard_dtor(struct WildcardData *wc)
  43. {
  44. if(!wc)
  45. return;
  46. if(wc->tmp_dtor) {
  47. wc->tmp_dtor(wc->tmp);
  48. wc->tmp_dtor = ZERO_NULL;
  49. wc->tmp = NULL;
  50. }
  51. DEBUGASSERT(wc->tmp == NULL);
  52. if(wc->filelist) {
  53. Curl_llist_destroy(wc->filelist, NULL);
  54. wc->filelist = NULL;
  55. }
  56. if(wc->path) {
  57. free(wc->path);
  58. wc->path = NULL;
  59. }
  60. if(wc->pattern) {
  61. free(wc->pattern);
  62. wc->pattern = NULL;
  63. }
  64. wc->customptr = NULL;
  65. wc->state = CURLWC_INIT;
  66. }