str_list.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of sip-router, a free SIP server.
  5. *
  6. * sip-router 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. * sip-router 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 Simple str type list and helper functions
  23. */
  24. #include "str.h"
  25. #include "mem/mem.h"
  26. #include "str_list.h"
  27. /**
  28. * @brief Add a new allocated list element to an existing list
  29. *
  30. * Add a new allocated list element to an existing list, the allocation is done
  31. * from the private memory pool
  32. * @param s input character
  33. * @param len length of input character
  34. * @param last existing list
  35. * @param total length of total characters in list
  36. * @return extended list
  37. */
  38. struct str_list *append_str_list(char *s, int len, struct str_list **last, int *total)
  39. {
  40. struct str_list *new;
  41. new = pkg_malloc(sizeof(struct str_list));
  42. if (!new) {
  43. PKG_MEM_ERROR;
  44. return 0;
  45. }
  46. new->s.s = s;
  47. new->s.len = len;
  48. new->next = 0;
  49. (*last)->next = new;
  50. *last = new;
  51. *total += len;
  52. return new;
  53. }