summaryrefslogtreecommitdiff
path: root/src/common/strlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/strlib.c')
-rw-r--r--src/common/strlib.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 977dc8306..a683dc100 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -1,14 +1,15 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
+#include "../common/cbasetypes.h"
+#include "../common/malloc.h"
+#include "../common/utils.h"
+#include "strlib.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "strlib.h"
-#include "../common/cbasetypes.h"
-#include "../common/utils.h"
-#include "../common/malloc.h"
#define J_MAX_MALLOC_SIZE 65535
@@ -299,3 +300,13 @@ int config_switch(const char* str)
return (int)strtol(str, NULL, 0);
}
+
+/// always nul-terminates the string
+char* safestrncpy(char* dst, const char* src, size_t n)
+{
+ char* ret;
+ ret = strncpy(dst, src, n);
+ if( ret != NULL )
+ ret[n - 1] = '\0';
+ return ret;
+}