stringx.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * File: stringx.h $TOG: stringx.h /main/5 1999/10/15 17:23:52 mgreess $
  25. *
  26. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  27. * (c) Copyright 1993, 1994 International Business Machines Corp.
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. * (c) Copyright 1993, 1994 Novell, Inc.
  30. */
  31. #ifndef __STRINGX_H_
  32. #define __STRINGX_H_
  33. #include <stddef.h>
  34. #include <string.h>
  35. #include <codelibs/boolean.h>
  36. #define streq(a,b) (strcmp(a,b) == 0)
  37. /* private buffer variables */
  38. extern void *_strsep_privbuf;
  39. extern void *_strcmbn_privbuf;
  40. #if defined(__cplusplus)
  41. extern "C"
  42. {
  43. #endif
  44. #if defined(__cplusplus) || defined(__STDC__)
  45. #if !defined(sun)
  46. char *strnew(size_t len);
  47. void strfree(const char *s);
  48. #endif
  49. char *strstrx(char *s1, const char *s2);
  50. char *strrstrx(char *s1, const char *s2);
  51. int strwcmp(const char *pattern, const char *str);
  52. int strwcmpi(const char *pattern, const char *str);
  53. char *strwpat(const char *pattern);
  54. char *strend(const char *str);
  55. unsigned strhash(const char *key);
  56. unsigned strhashi(const char *key);
  57. char *strupper(char *str);
  58. char *strlower(char *str);
  59. #ifdef __cplusplus
  60. char *strtokx(char *&ptr, const char *sep);
  61. #else /* __STDC__ */
  62. char *strtokx(char **ptr, const char *sep);
  63. const char *strcmbn(const char **vec, const char *sep);
  64. #endif /* __STDC__ */
  65. #else /* C */
  66. extern void strfree();
  67. extern char *strstrx(), strrstrx();
  68. extern int strwcmp(), strwcmpi();
  69. extern char *strwpat();
  70. extern char *strend();
  71. extern char *strtokx();
  72. extern unsigned strhash();
  73. extern unsigned strhashi();
  74. extern char *strupper(), *strlower();
  75. #endif /* C */
  76. #if defined(__cplusplus)
  77. }
  78. #if defined(__aix) || defined(__linux__) || defined(CSRG_BASED)
  79. #include <stdlib.h>
  80. #else
  81. #include <malloc.h>
  82. #endif /* aix linux CSRG_BASED */
  83. inline char *strnew(size_t len) { return (char*)malloc(len + 1); }
  84. #if defined(sun) || defined(__sun)
  85. inline void strfree(const char *s)
  86. { if (s != NULL) free((char *)s); }
  87. #else
  88. inline void strfree(const char *s)
  89. #if defined(CSRG_BASED)
  90. { if (s != NULL) free((void *)s); }
  91. #else
  92. { if (s != NULL) free((void *)s); }
  93. #endif /* bsd */
  94. #endif
  95. #if defined(bsd)
  96. inline char *strdup(const char *s)
  97. { return strcpy((char*)malloc(strlen(s) + 1), s); }
  98. #endif
  99. /* private buffer funcs - we use inlines to handle default args properly */
  100. #else /* C || __STDC__ */
  101. #define strnew(len) ((char*)malloc((len) + 1))
  102. #define strbld strblds
  103. /* macros for funcs that work on top of privbuf versions */
  104. #endif /* C || __STDC__ */
  105. #endif /* __STRINGX_H_ */