str.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Header file for str.c
  3. *
  4. * Copyright 2022 and 2023 Odin Kroeger.
  5. *
  6. * This file is part of suCGI.
  7. *
  8. * suCGI is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU Affero General Public License as published
  10. * by the Free Software Foundation, either version 3 of the License,
  11. * or (at your option) any later version.
  12. *
  13. * suCGI is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
  16. * Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with suCGI. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #if !defined(STR_H)
  22. #define STR_H
  23. #include <stdlib.h>
  24. #include "attr.h"
  25. #include "types.h"
  26. /*
  27. * Split the given string at the first occurence of any of the given bytes,
  28. * and copy the substring up to, but not including, that byte to the memory
  29. * area pointed to by "head" and return a pointer to the substring that
  30. * starts after the separator in the memory area pointed to by "tail".
  31. *
  32. * The memory area pointed to by "head" must be of the given size;
  33. * the substring before the separator must be shorter than that size.
  34. *
  35. * Neither substring is meaningful if an error occurs.
  36. *
  37. * Return value:
  38. * OK Success.
  39. * ERR_LEN The substring before the separator is too long.
  40. */
  41. _read_only(1) _read_only(2) _write_only(4, 3) _nonnull(1, 2, 4, 5) _nodiscard
  42. Error str_split(const char *str, const char *sep,
  43. size_t size, char *head, const char **tail);
  44. #endif /* !defined(STR_H) */