2
0

sbstdinc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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: sbstdinc.c $TOG: sbstdinc.c /main/5 1999/10/14 15:06:26 mgreess $
  25. * Language: C
  26. *
  27. * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
  28. *
  29. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  30. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  31. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  32. * (c) Copyright 1993, 1994 Novell, Inc. *
  33. */
  34. #define SBSTDINC_H_NO_REDEFINE
  35. #include <bms/sbport.h> /* NOTE: sbport.h must be the first include. */
  36. #include <stdarg.h>
  37. static XeChar XESTRING_SAFE_NULL[1] = {(XeChar)0};
  38. /************************************************************************/
  39. /* Routines from <string.h> */
  40. /************************************************************************/
  41. XeString Xestrcat(XeString s1, ConstXeString s2)
  42. {
  43. if (!s1) return XeString_NULL;
  44. if (!s2) return s1;
  45. return (XeString) strcat(s1, s2);
  46. }
  47. XeString Xestrncat(XeString s1, ConstXeString s2, size_t n)
  48. {
  49. if (!s1) return XeString_NULL;
  50. if (!s2) return s1;
  51. return (XeString) strncat(s1, s2, n);
  52. }
  53. int Xestrcmp(ConstXeString s1, ConstXeString s2)
  54. {
  55. if (s1 == s2) return 0;
  56. {
  57. const XeChar * p1 = (s1) ? s1 : XESTRING_SAFE_NULL;
  58. const XeChar * p2 = (s2) ? s2 : XESTRING_SAFE_NULL;
  59. return strcmp(p1, p2);
  60. }
  61. }
  62. int Xestrncmp(ConstXeString s1, ConstXeString s2, size_t n)
  63. {
  64. if (s1 == s2) return 0;
  65. {
  66. ConstXeString p1 = (s1) ? s1 : XESTRING_SAFE_NULL;
  67. ConstXeString p2 = (s2) ? s2 : XESTRING_SAFE_NULL;
  68. return strncmp( (char *) p1, (char *) p2, n);
  69. }
  70. }
  71. XeString Xestrcpy(XeString s1, ConstXeString s2)
  72. {
  73. if (!s1) return s1;
  74. if (!s2) {
  75. *s1 = (XeChar)0;
  76. return s1;
  77. }
  78. return (XeString) strcpy(s1, s2);
  79. }
  80. XeString Xestrncpy(XeString s1, ConstXeString s2, size_t n)
  81. {
  82. if (!s1) return s1;
  83. if (!s2 && n) {
  84. *s1 = (XeChar)0;
  85. return s1;
  86. }
  87. return (XeString) strncpy(s1, s2, n);
  88. }
  89. int Xestrcoll(ConstXeString s1, ConstXeString s2)
  90. {
  91. if (s1 == s2) return 0;
  92. {
  93. XeString p1 = (s1) ? (XeString) s1 : XESTRING_SAFE_NULL;
  94. XeString p2 = (s2) ? (XeString) s2 : XESTRING_SAFE_NULL;
  95. return strcoll(p1, p2);
  96. }
  97. }
  98. size_t Xestrxfrm(XeString s1, ConstXeString s2, size_t n)
  99. {
  100. return strxfrm(s1, s2, n);
  101. }
  102. XeString Xestrchr(ConstXeString s, int c)
  103. {
  104. if (!s) return XeString_NULL;
  105. return (XeString) strchr(s, c);
  106. }
  107. XeString Xestrrchr(ConstXeString s, int c)
  108. {
  109. if (!s) return XeString_NULL;
  110. return (XeString) strrchr(s, c);
  111. }
  112. XeString Xestrpbrk(ConstXeString s1, ConstXeString s2)
  113. {
  114. if (!s1) return XeString_NULL;
  115. if (!s2) return XeString_NULL;
  116. return (XeString) strpbrk(s1, s2);
  117. }
  118. XeString Xestrstr(ConstXeString s1, ConstXeString s2)
  119. {
  120. if (!s1) return XeString_NULL;
  121. if (!s2) return XeString_NULL;
  122. return (XeString) strstr(s1, s2);
  123. }
  124. XeString Xestrtok(XeString s1, ConstXeString s2)
  125. {
  126. /* s1 is null except after the first call */
  127. if (!s2) return XeString_NULL;
  128. return (XeString) strtok(s1, s2);
  129. }
  130. size_t Xestrlen(ConstXeString const s)
  131. {
  132. if (!s) return (size_t)0;
  133. return strlen((char *) s);
  134. }
  135. XeString Xestrdup(ConstXeString s)
  136. {
  137. if (!s) return XeString_NULL;
  138. return (XeString) strdup(s);
  139. }