diff options
author | Max Horn | 2009-03-24 12:14:22 +0000 |
---|---|---|
committer | Max Horn | 2009-03-24 12:14:22 +0000 |
commit | 608b839720a028b5ecffa5955b024387740583d7 (patch) | |
tree | 663bd1fcc7f958a93b5f96e75863639cc4f482b8 | |
parent | c1be6e1ed68fdb9826a5fe189f01c520238e37af (diff) | |
download | scummvm-rg350-608b839720a028b5ecffa5955b024387740583d7.tar.gz scummvm-rg350-608b839720a028b5ecffa5955b024387740583d7.tar.bz2 scummvm-rg350-608b839720a028b5ecffa5955b024387740583d7.zip |
SCI: moved sci_strndup to menubar.cpp
svn-id: r39661
-rw-r--r-- | engines/sci/gfx/menubar.cpp | 23 | ||||
-rw-r--r-- | engines/sci/sci_memory.cpp | 20 | ||||
-rw-r--r-- | engines/sci/sci_memory.h | 11 |
3 files changed, 23 insertions, 31 deletions
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() { diff --git a/engines/sci/sci_memory.cpp b/engines/sci/sci_memory.cpp index 7fa3a5d4aa..c7bd78c16e 100644 --- a/engines/sci/sci_memory.cpp +++ b/engines/sci/sci_memory.cpp @@ -95,24 +95,4 @@ char *sci_strdup(const char *src) { return (char*)res; } -char *sci_strndup(const char *src, size_t length) { - void *res; - char *strres; - size_t rlen = (int)MIN(strlen(src), length) + 1; - - if (!src) { - fprintf(stderr, "_SCI_STRNDUP() [%s (%s) : %u]\n", - __FILE__, "", __LINE__); - fprintf(stderr, " attempt to strndup NULL pointer\n"); - BREAKPOINT(); - } - ALLOC_MEM((res = malloc(rlen)), rlen, __FILE__, __LINE__, "") - - strres = (char *)res; - strncpy(strres, src, rlen); - strres[rlen - 1] = 0; - - return strres; -} - } // End of namespace Sci diff --git a/engines/sci/sci_memory.h b/engines/sci/sci_memory.h index d3bc4a16d9..8aec598876 100644 --- a/engines/sci/sci_memory.h +++ b/engines/sci/sci_memory.h @@ -75,17 +75,6 @@ extern char *sci_strdup(const char *src); ** See _SCI_MALLOC() for more information if call fails. */ - -extern char *sci_strndup(const char *src, size_t length); -/* 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. -*/ - } // End of namespace Sci #endif // SCI_SCI_MEMORY_H |