summaryrefslogtreecommitdiffstats
path: root/crypto/o_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/o_str.c')
-rw-r--r--crypto/o_str.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c
index f2f9404db0..e96f62a2e8 100644
--- a/crypto/o_str.c
+++ b/crypto/o_str.c
@@ -58,7 +58,10 @@
*/
#include <ctype.h>
+#include <limits.h>
#include <e_os.h>
+#include <openssl/crypto.h>
+#include "internal/cryptlib.h"
#include "internal/o_str.h"
#if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \
@@ -114,3 +117,81 @@ int OPENSSL_memcmp(const void *v1, const void *v2, size_t n)
return ret;
}
+
+char *CRYPTO_strdup(const char *str, const char* file, int line)
+{
+ char *ret;
+
+ if (str == NULL)
+ return NULL;
+ ret = CRYPTO_malloc(strlen(str) + 1, file, line);
+ if (ret != NULL)
+ strcpy(ret, str);
+ return ret;
+}
+
+char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line)
+{
+ const char *cp;
+ size_t maxlen;
+ char *ret;
+
+ if (str == NULL)
+ return NULL;
+
+ /* Get length. */
+ for (cp = str, maxlen = s; maxlen-- != 0 && *cp != '\0'; ++cp)
+ continue;
+ maxlen = cp - str;
+
+ ret = CRYPTO_malloc(maxlen + 1, file, line);
+ if (ret) {
+ memcpy(ret, str, maxlen);
+ ret[maxlen] = '\0';
+ }
+ return ret;
+}
+
+void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)
+{
+ void *ret;
+
+ if (data == NULL || siz >= INT_MAX)
+ return NULL;
+
+ ret = CRYPTO_malloc(siz, file, line);
+ if (ret == NULL) {
+ CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
+ return memcpy(ret, data, siz);
+}
+
+size_t OPENSSL_strnlen(const char *str, size_t maxlen)
+{
+ const char *p;
+
+ for (p = str; maxlen-- != 0 && *p != '\0'; ++p) ;
+
+ return p - str;
+}
+
+size_t OPENSSL_strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t l = 0;
+ for (; size > 1 && *src; size--) {
+ *dst++ = *src++;
+ l++;
+ }
+ if (size)
+ *dst = '\0';
+ return l + strlen(src);
+}
+
+size_t OPENSSL_strlcat(char *dst, const char *src, size_t size)
+{
+ size_t l = 0;
+ for (; size > 0 && *dst; size--, dst++)
+ l++;
+ return l + OPENSSL_strlcpy(dst, src, size);
+}