From 85db2023cb033928a190ac7fa6f05b5d6cbad14a Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Sat, 2 Jun 2007 20:19:40 +0000 Subject: * Displaying op names instead of numbers in script engine errors. * Fixed a bug introduced in the last rework of the fame ranking. * Created safestrncpy that ensures the string is nul-terminated. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10667 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/strlib.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/common/strlib.c') 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 #include #include -#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; +} -- cgit v1.2.3-70-g09d2