1
0

CString.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "util/CString.h"
  16. #include "util/Bits.h"
  17. #include <string.h>
  18. #if defined(Illumos) || defined(__sun)
  19. #define _XPG4_2
  20. #endif
  21. #include <strings.h>
  22. unsigned long CString_strlen(const char* str)
  23. {
  24. return strlen(str);
  25. }
  26. int CString_strcmp(const char* a, const char* b)
  27. {
  28. return strcmp(a,b);
  29. }
  30. int CString_strncmp(const char* a, const char *b, size_t n)
  31. {
  32. return strncmp(a, b, n);
  33. }
  34. char* CString_strchr(const char* a, int b)
  35. {
  36. return strchr(a,b);
  37. }
  38. char* CString_strrchr(const char* a, int b)
  39. {
  40. return strrchr(a,b);
  41. }
  42. int CString_strcasecmp(const char *a, const char *b)
  43. {
  44. return strcasecmp(a,b);
  45. }
  46. char* CString_strstr(const char* haystack, const char* needle)
  47. {
  48. return strstr(haystack,needle);
  49. }
  50. char* CString_strcpy(char* restrict dest, const char* restrict src)
  51. {
  52. return strcpy(dest, src);
  53. }
  54. char* CString_safeStrncpy(char* restrict dest, const char *restrict src, size_t n)
  55. {
  56. char* ret = strncpy(dest, src, n);
  57. dest[n - 1] = '\0';
  58. return ret;
  59. }
  60. char* CString_strdup(const char* string, struct Allocator* alloc)
  61. {
  62. int len = CString_strlen(string);
  63. char* out = Allocator_calloc(alloc, len+1, 1);
  64. Bits_memcpy(out, string, len);
  65. return out;
  66. }