str_list.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * @brief Kamailio core :: Simple str type list and helper functions
  23. * @ingroup core
  24. * Module: @ref core
  25. */
  26. #include "str.h"
  27. #include "mem/mem.h"
  28. #include "str_list.h"
  29. /**
  30. * @brief Add a new allocated list element to an existing list
  31. *
  32. * Add a new allocated list element to an existing list, the allocation is done
  33. * from the private memory pool
  34. * @param s input character
  35. * @param len length of input character
  36. * @param last existing list
  37. * @param total length of total characters in list
  38. * @return extended list
  39. */
  40. struct str_list *append_str_list(char *s, int len, struct str_list **last, int *total)
  41. {
  42. struct str_list *new;
  43. new = pkg_malloc(sizeof(struct str_list));
  44. if (!new) {
  45. PKG_MEM_ERROR;
  46. return 0;
  47. }
  48. new->s.s = s;
  49. new->s.len = len;
  50. new->next = 0;
  51. (*last)->next = new;
  52. *last = new;
  53. *total += len;
  54. return new;
  55. }