From 608b839720a028b5ecffa5955b024387740583d7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 24 Mar 2009 12:14:22 +0000 Subject: SCI: moved sci_strndup to menubar.cpp svn-id: r39661 --- engines/sci/gfx/menubar.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'engines/sci/gfx') diff --git a/engines/sci/gfx/menubar.cpp b/engines/sci/gfx/menubar.cpp index 7a01cac7c9..242bba3f42 100644 --- a/engines/sci/gfx/menubar.cpp +++ b/engines/sci/gfx/menubar.cpp @@ -36,6 +36,29 @@ namespace Sci { + +/* Copies a string into a newly allocated memory part, up to a certain length. +** Parameters: (char *) src: The source string +** (int) length: The maximum length of the string (not counting +** a trailing \0). +** Returns : (char *) The resulting copy, allocated with sci_malloc(). +** To free this string, use the free() command. +** See _SCI_MALLOC() for more information if call fails. +*/ +char *sci_strndup(const char *src, size_t length) { + assert(src); + + size_t rlen = (int)MIN(strlen(src), length) + 1; + char *strres = (char *)malloc(rlen); + assert(strres); + + strncpy(strres, src, rlen); + strres[rlen - 1] = 0; + + return strres; +} + + #define SIZE_INF 32767 Menu::Menu() { -- cgit v1.2.3