Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

software/libbase: add strcat strncat

  • Loading branch information...
commit 8fa0198089fa26dcc47e2c7aceccca34a50a4e99 1 parent 20b137f
Sébastien Bourdeauducq authored May 31, 2012
2  software/include/base/string.h
@@ -29,6 +29,8 @@ char *strcpy(char *dest, const char *src);
29 29
 char *strncpy(char *dest, const char *src, size_t count);
30 30
 int strcmp(const char *cs, const char *ct);
31 31
 int strncmp(const char *cs, const char *ct, size_t count);
  32
+char *strcat(char *dest, const char *src);
  33
+char *strncat(char *dest, const char *src, size_t n);
32 34
 size_t strlen(const char *s);
33 35
 size_t strnlen(const char *s, size_t count);
34 36
 size_t strspn(const char *s, const char *accept);
42  software/libbase/libc.c
@@ -161,6 +161,48 @@ int strncmp(const char *cs, const char *ct, size_t count)
161 161
 }
162 162
 
163 163
 /**
  164
+ * strcat - Append one %NUL-terminated string to another
  165
+ * @dest: The string to be appended to
  166
+ * @src: The string to append to it
  167
+ */
  168
+char *strcat(char *dest, const char *src)
  169
+{
  170
+  char *tmp = dest;
  171
+
  172
+  while (*dest)
  173
+    dest++;
  174
+  while ((*dest++ = *src++) != '\0')
  175
+    ;
  176
+  return tmp;
  177
+}
  178
+
  179
+/**
  180
+ * strncat - Append a length-limited, %NUL-terminated string to another
  181
+ * @dest: The string to be appended to
  182
+ * @src: The string to append to it
  183
+ * @count: The maximum numbers of bytes to copy
  184
+ *
  185
+ * Note that in contrast to strncpy(), strncat() ensures the result is
  186
+ * terminated.
  187
+ */
  188
+char *strncat(char *dest, const char *src, size_t count)
  189
+{
  190
+  char *tmp = dest;
  191
+
  192
+  if (count) {
  193
+    while (*dest)
  194
+      dest++;
  195
+    while ((*dest++ = *src++) != 0) {
  196
+      if (--count == 0) {
  197
+        *dest = '\0';
  198
+        break;
  199
+      }
  200
+    }
  201
+  }
  202
+  return tmp;
  203
+}
  204
+
  205
+/**
164 206
  * strlen - Find the length of a string
165 207
  * @s: The string to be sized
166 208
  */

0 notes on commit 8fa0198

Please sign in to comment.
Something went wrong with that request. Please try again.