Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: uamqp/deps/umock-c/src/umockstring.c
- Revision:
- 0:f7f1f0d76dd6
diff -r 000000000000 -r f7f1f0d76dd6 uamqp/deps/umock-c/src/umockstring.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/uamqp/deps/umock-c/src/umockstring.c Thu Aug 23 06:52:14 2018 +0000
@@ -0,0 +1,40 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+#include <stddef.h>
+#include <string.h>
+#include "umockalloc.h"
+#include "umockstring.h"
+#include "umock_log.h"
+
+char* umockstring_clone(const char* source)
+{
+ char* result;
+
+ if (source == NULL)
+ {
+ /* Codes_UMOCK_STRING_01_005: [ If `umockstring_clone` is called with a NULL `source`, it shall return NULL. ]*/
+ UMOCK_LOG("umockstring_clone called with NULL source");
+ result = NULL;
+ }
+ else
+ {
+ size_t string_length = strlen(source);
+
+ /* Codes_UMOCK_STRING_01_001: [ `umockstring_clone` shall allocate memory for the cloned string (including the NULL terminator). ]*/
+ /* Codes_UMOCK_STRING_01_003: [ On success `umockstring_clone` shall return a pointer to the newly allocated memory containing the copy of the string. ]*/
+ result = (char*)umockalloc_malloc(string_length + 1);
+ if (result == NULL)
+ {
+ /* Codes_UMOCK_STRING_01_004: [ If allocating the memory fails, `umockstring_clone` shall return NULL. ]*/
+ UMOCK_LOG("Error allocating memory for string clone");
+ }
+ else
+ {
+ /* Codes_UMOCK_STRING_01_002: [ `umockstring_clone` shall copy the string to the newly allocated memory (including the NULL terminator). ]*/
+ (void)memcpy(result, source, string_length + 1);
+ }
+ }
+
+ return result;
+}