Forráskód Böngészése

Speed optimization

git-svn-id: https://klish.googlecode.com/svn/trunk@410 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 éve
szülő
commit
7595328a6d

+ 18 - 37
Makefile.in

@@ -246,8 +246,7 @@ liblub_la_DEPENDENCIES =
 am__liblub_la_SOURCES_DIST = lub/argv/argv__get_arg.c \
 	lub/argv/argv__get_argv.c lub/argv/argv__get_count.c \
 	lub/argv/argv__get_offset.c lub/argv/argv__get_quoted.c \
-	lub/argv/argv_delete.c lub/argv/argv_new.c \
-	lub/argv/argv_nextword.c lub/argv/argv_wordcount.c \
+	lub/argv/argv_new.c lub/argv/argv_nextword.c \
 	lub/argv/private.h lub/bintree/bintree_dump.c \
 	lub/bintree/bintree_find.c lub/bintree/bintree_findfirst.c \
 	lub/bintree/bintree_findlast.c lub/bintree/bintree_findnext.c \
@@ -313,11 +312,11 @@ am__liblub_la_SOURCES_DIST = lub/argv/argv__get_arg.c \
 	lub/partition/posix/posix_partition.c \
 	lub/partition/posix/private.h lub/string/string_cat.c \
 	lub/string/string_catn.c lub/string/string_dup.c \
-	lub/string/string_dupn.c lub/string/string_free.c \
-	lub/string/string_nocasecmp.c lub/string/string_nocasestr.c \
-	lub/string/string_suffix.c lub/string/string_escape.c \
-	lub/string/private.h lub/test/test.c lub/system/test.c \
-	lub/system/system_test.c lub/system/private.h
+	lub/string/string_free.c lub/string/string_nocasecmp.c \
+	lub/string/string_nocasestr.c lub/string/string_suffix.c \
+	lub/string/string_escape.c lub/string/private.h \
+	lub/test/test.c lub/system/test.c lub/system/system_test.c \
+	lub/system/private.h
 @LUBHEAP_TRUE@am__objects_1 = lub/heap/cache.lo \
 @LUBHEAP_TRUE@	lub/heap/cache_bucket.lo lub/heap/context.lo \
 @LUBHEAP_TRUE@	lub/heap/heap__get_max_free.lo \
@@ -381,8 +380,7 @@ am__liblub_la_SOURCES_DIST = lub/argv/argv__get_arg.c \
 am_liblub_la_OBJECTS = lub/argv/argv__get_arg.lo \
 	lub/argv/argv__get_argv.lo lub/argv/argv__get_count.lo \
 	lub/argv/argv__get_offset.lo lub/argv/argv__get_quoted.lo \
-	lub/argv/argv_delete.lo lub/argv/argv_new.lo \
-	lub/argv/argv_nextword.lo lub/argv/argv_wordcount.lo \
+	lub/argv/argv_new.lo lub/argv/argv_nextword.lo \
 	lub/bintree/bintree_dump.lo lub/bintree/bintree_find.lo \
 	lub/bintree/bintree_findfirst.lo \
 	lub/bintree/bintree_findlast.lo \
@@ -405,10 +403,10 @@ am_liblub_la_OBJECTS = lub/argv/argv__get_arg.lo \
 	lub/dblockpool/dblockpool_init.lo lub/dump/dump.lo \
 	$(am__objects_1) lub/string/string_cat.lo \
 	lub/string/string_catn.lo lub/string/string_dup.lo \
-	lub/string/string_dupn.lo lub/string/string_free.lo \
-	lub/string/string_nocasecmp.lo lub/string/string_nocasestr.lo \
-	lub/string/string_suffix.lo lub/string/string_escape.lo \
-	lub/test/test.lo lub/system/test.lo lub/system/system_test.lo
+	lub/string/string_free.lo lub/string/string_nocasecmp.lo \
+	lub/string/string_nocasestr.lo lub/string/string_suffix.lo \
+	lub/string/string_escape.lo lub/test/test.lo \
+	lub/system/test.lo lub/system/system_test.lo
 liblub_la_OBJECTS = $(am_liblub_la_OBJECTS)
 liblubheap_la_LIBADD =
 am__liblubheap_la_SOURCES_DIST = lubheap/posix/sysheap.c
@@ -772,9 +770,8 @@ libclish_la_LIBADD = \
 
 liblub_la_SOURCES = lub/argv/argv__get_arg.c lub/argv/argv__get_argv.c \
 	lub/argv/argv__get_count.c lub/argv/argv__get_offset.c \
-	lub/argv/argv__get_quoted.c lub/argv/argv_delete.c \
-	lub/argv/argv_new.c lub/argv/argv_nextword.c \
-	lub/argv/argv_wordcount.c lub/argv/private.h \
+	lub/argv/argv__get_quoted.c lub/argv/argv_new.c \
+	lub/argv/argv_nextword.c lub/argv/private.h \
 	lub/bintree/bintree_dump.c lub/bintree/bintree_find.c \
 	lub/bintree/bintree_findfirst.c lub/bintree/bintree_findlast.c \
 	lub/bintree/bintree_findnext.c \
@@ -796,12 +793,11 @@ liblub_la_SOURCES = lub/argv/argv__get_arg.c lub/argv/argv__get_argv.c \
 	lub/dblockpool/dblockpool_init.c lub/dblockpool/private.h \
 	lub/dump/dump.c lub/dump/private.h $(am__append_1) \
 	lub/string/string_cat.c lub/string/string_catn.c \
-	lub/string/string_dup.c lub/string/string_dupn.c \
-	lub/string/string_free.c lub/string/string_nocasecmp.c \
-	lub/string/string_nocasestr.c lub/string/string_suffix.c \
-	lub/string/string_escape.c lub/string/private.h \
-	lub/test/test.c lub/system/test.c lub/system/system_test.c \
-	lub/system/private.h
+	lub/string/string_dup.c lub/string/string_free.c \
+	lub/string/string_nocasecmp.c lub/string/string_nocasestr.c \
+	lub/string/string_suffix.c lub/string/string_escape.c \
+	lub/string/private.h lub/test/test.c lub/system/test.c \
+	lub/system/system_test.c lub/system/private.h
 liblub_la_LIBADD = -lpthread
 @LUBHEAP_TRUE@liblubheap_la_SOURCES = lubheap/posix/sysheap.c
 libtinyrl_la_LIBADD = liblub.la
@@ -1193,14 +1189,10 @@ lub/argv/argv__get_offset.lo: lub/argv/$(am__dirstamp) \
 	lub/argv/$(DEPDIR)/$(am__dirstamp)
 lub/argv/argv__get_quoted.lo: lub/argv/$(am__dirstamp) \
 	lub/argv/$(DEPDIR)/$(am__dirstamp)
-lub/argv/argv_delete.lo: lub/argv/$(am__dirstamp) \
-	lub/argv/$(DEPDIR)/$(am__dirstamp)
 lub/argv/argv_new.lo: lub/argv/$(am__dirstamp) \
 	lub/argv/$(DEPDIR)/$(am__dirstamp)
 lub/argv/argv_nextword.lo: lub/argv/$(am__dirstamp) \
 	lub/argv/$(DEPDIR)/$(am__dirstamp)
-lub/argv/argv_wordcount.lo: lub/argv/$(am__dirstamp) \
-	lub/argv/$(DEPDIR)/$(am__dirstamp)
 lub/bintree/$(am__dirstamp):
 	@$(MKDIR_P) lub/bintree
 	@: > lub/bintree/$(am__dirstamp)
@@ -1463,8 +1455,6 @@ lub/string/string_catn.lo: lub/string/$(am__dirstamp) \
 	lub/string/$(DEPDIR)/$(am__dirstamp)
 lub/string/string_dup.lo: lub/string/$(am__dirstamp) \
 	lub/string/$(DEPDIR)/$(am__dirstamp)
-lub/string/string_dupn.lo: lub/string/$(am__dirstamp) \
-	lub/string/$(DEPDIR)/$(am__dirstamp)
 lub/string/string_free.lo: lub/string/$(am__dirstamp) \
 	lub/string/$(DEPDIR)/$(am__dirstamp)
 lub/string/string_nocasecmp.lo: lub/string/$(am__dirstamp) \
@@ -1764,14 +1754,10 @@ mostlyclean-compile:
 	-rm -f lub/argv/argv__get_offset.lo
 	-rm -f lub/argv/argv__get_quoted.$(OBJEXT)
 	-rm -f lub/argv/argv__get_quoted.lo
-	-rm -f lub/argv/argv_delete.$(OBJEXT)
-	-rm -f lub/argv/argv_delete.lo
 	-rm -f lub/argv/argv_new.$(OBJEXT)
 	-rm -f lub/argv/argv_new.lo
 	-rm -f lub/argv/argv_nextword.$(OBJEXT)
 	-rm -f lub/argv/argv_nextword.lo
-	-rm -f lub/argv/argv_wordcount.$(OBJEXT)
-	-rm -f lub/argv/argv_wordcount.lo
 	-rm -f lub/bintree/bintree_dump.$(OBJEXT)
 	-rm -f lub/bintree/bintree_dump.lo
 	-rm -f lub/bintree/bintree_find.$(OBJEXT)
@@ -1960,8 +1946,6 @@ mostlyclean-compile:
 	-rm -f lub/string/string_catn.lo
 	-rm -f lub/string/string_dup.$(OBJEXT)
 	-rm -f lub/string/string_dup.lo
-	-rm -f lub/string/string_dupn.$(OBJEXT)
-	-rm -f lub/string/string_dupn.lo
 	-rm -f lub/string/string_escape.$(OBJEXT)
 	-rm -f lub/string/string_escape.lo
 	-rm -f lub/string/string_free.$(OBJEXT)
@@ -2062,10 +2046,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv__get_count.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv__get_offset.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv__get_quoted.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv_delete.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv_new.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv_nextword.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@lub/argv/$(DEPDIR)/argv_wordcount.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/bintree/$(DEPDIR)/bintree_dump.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/bintree/$(DEPDIR)/bintree_find.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/bintree/$(DEPDIR)/bintree_findfirst.Plo@am__quote@
@@ -2160,7 +2142,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_cat.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_catn.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_dup.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_dupn.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_escape.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_free.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@lub/string/$(DEPDIR)/string_nocasecmp.Plo@am__quote@

+ 14 - 14
bin/konfd.c

@@ -276,10 +276,10 @@ int main(int argc, char **argv)
 				while ((str = konf_buftree_parse(&bufs, i))) {
 					char *answer;
 					if (!(answer = process_query(i, conf, str)))
-						answer = lub_string_dup("-e");
-					lub_string_free(str);
+						answer = strdup("-e");
+					free(str);
 					answer_send(i, answer);
-					lub_string_free(answer);
+					free(answer);
 				}
 			}
 		}
@@ -528,8 +528,8 @@ struct options *opts_init(void)
 	opts = malloc(sizeof(*opts));
 	assert(opts);
 	opts->debug = 0; /* daemonize by default */
-	opts->socket_path = lub_string_dup(KONFD_SOCKET_PATH);
-	opts->pidfile = lub_string_dup(KONFD_PIDFILE);
+	opts->socket_path = strdup(KONFD_SOCKET_PATH);
+	opts->pidfile = strdup(KONFD_PIDFILE);
 	opts->chroot = NULL;
 	opts->uid = getuid();
 	opts->gid = getgid();
@@ -542,11 +542,11 @@ struct options *opts_init(void)
 void opts_free(struct options *opts)
 {
 	if (opts->socket_path)
-		lub_string_free(opts->socket_path);
+		free(opts->socket_path);
 	if (opts->pidfile)
-		lub_string_free(opts->pidfile);
+		free(opts->pidfile);
 	if (opts->chroot)
-		lub_string_free(opts->chroot);
+		free(opts->chroot);
 	free(opts);
 }
 
@@ -581,19 +581,19 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		switch (opt) {
 		case 's':
 			if (opts->socket_path)
-				lub_string_free(opts->socket_path);
-			opts->socket_path = lub_string_dup(optarg);
+				free(opts->socket_path);
+			opts->socket_path = strdup(optarg);
 			break;
 		case 'p':
 			if (opts->pidfile)
-				lub_string_free(opts->pidfile);
-			opts->pidfile = lub_string_dup(optarg);
+				free(opts->pidfile);
+			opts->pidfile = strdup(optarg);
 			break;
 		case 'r':
 #ifdef HAVE_CHROOT
 			if (opts->chroot)
-				lub_string_free(opts->chroot);
-			opts->chroot = lub_string_dup(optarg);
+				free(opts->chroot);
+			opts->chroot = strdup(optarg);
 #else
 			syslog(LOG_ERR, "The --chroot option is not supported\n");
 			return -1;

+ 5 - 5
konf/net/net.c

@@ -38,7 +38,7 @@ konf_client_t *konf_client_new(const char *path)
 		return NULL;
 
 	this->sock = -1; /* socket is not created yet */
-	this->path = lub_string_dup(path);
+	this->path = strdup(path);
 
 	return this;
 }
@@ -50,7 +50,7 @@ void konf_client_free(konf_client_t *this)
 		return;
 	if (this->sock != -1)
 		konf_client_disconnect(this);
-	lub_string_free(this->path);
+	free(this->path);
 
 	free(this);
 }
@@ -125,10 +125,10 @@ konf_buf_t * konf_client_recv_data(konf_client_t * this, konf_buf_t *buf)
 			konf_buf_add(data, str, strlen(str) + 1);
 			if (strlen(str) == 0) {
 				processed = 1;
-				lub_string_free(str);
+				free(str);
 				break;
 			}
-			lub_string_free(str);
+			free(str);
 		}
 	} while ((!processed) && (konf_buf_read(buf)) > 0);
 	if (!processed) {
@@ -202,7 +202,7 @@ int konf_client_recv_answer(konf_client_t * this, konf_buf_t **data)
 		while ((str = konf_buf_parse(buf))) {
 			konf_buf_t *tmpdata = NULL;
 			retval = process_answer(this, str, buf, &tmpdata);
-			lub_string_free(str);
+			free(str);
 			if (retval < 0) {
 				konf_buf_delete(buf);
 				return retval;

+ 10 - 9
konf/query/query.c

@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <errno.h>
@@ -54,7 +55,7 @@ void konf_query_add_pwd(konf_query_t *this, char *str)
 	assert(tmp);
 	this->pwd = tmp;
 	/* insert reference to the pwd component */
-	this->pwd[this->pwdc++] = lub_string_dup(str);
+	this->pwd[this->pwdc++] = strdup(str);
 }
 
 /*-------------------------------------------------------- */
@@ -62,13 +63,13 @@ void konf_query_free(konf_query_t *this)
 {
 	unsigned i;
 
-	lub_string_free(this->pattern);
-	lub_string_free(this->line);
-	lub_string_free(this->lower_line);
-	lub_string_free(this->path);
+	free(this->pattern);
+	free(this->line);
+	free(this->lower_line);
+	free(this->path);
 	if (this->pwdc > 0) {
 		for (i = 0; i < this->pwdc; i++)
-			lub_string_free(this->pwd[i]);
+			free(this->pwd[i]);
 		free(this->pwd);
 	}
 
@@ -159,14 +160,14 @@ int konf_query_parse(konf_query_t *this, int argc, char **argv)
 			break;
 			}
 		case 'r':
-			this->pattern = lub_string_dup(optarg);
+			this->pattern = strdup(optarg);
 			break;
 		case 'l':
-			this->line = lub_string_dup(optarg);
+			this->line = strdup(optarg);
 			this->lower_line = lub_string_tolower(optarg);
 			break;
 		case 'f':
-			this->path = lub_string_dup(optarg);
+			this->path = strdup(optarg);
 			break;
 		case 'i':
 			this->splitter = BOOL_FALSE;

+ 5 - 5
konf/tree/tree.c

@@ -44,7 +44,7 @@ static void konf_tree_init(konf_tree_t * this, const char *line,
 	unsigned short priority)
 {
 	/* set up defaults */
-	this->line = lub_string_dup(line);
+	this->line = strdup(line);
 	this->lower_line = lub_string_tolower(line);
 	this->priority = priority;
 	this->seq_num = 0;
@@ -73,9 +73,9 @@ static void konf_tree_fini(konf_tree_t * this)
 	lub_list_free(this->list);
 
 	/* free our memory */
-	lub_string_free(this->line);
+	free(this->line);
 	this->line = NULL;
-	lub_string_free(this->lower_line);
+	free(this->lower_line);
 	this->lower_line = NULL;
 }
 
@@ -235,11 +235,11 @@ konf_tree_t *konf_tree_find_conf(konf_tree_t * this,
 				break;
 		}
 		if (!strcmp(conf->lower_line, lower_line)) {
-			lub_string_free(lower_line);
+			free(lower_line);
 			return conf;
 		}
 	} while ((iter = lub_list_node__get_next(iter)));
-	lub_string_free(lower_line);
+	free(lower_line);
 
 	return NULL;
 }

+ 4 - 3
lub/argv/argv__get_argv.c

@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <ctype.h>
+#include <string.h>
 
 #include "lub/string.h"
 #include "private.h"
@@ -50,9 +51,9 @@ char **lub_argv__get_argv(const lub_argv_t * this, const char *argv0)
 	result = malloc(sizeof(char *) * (this->argc + 1 + a));
 
 	if (argv0)
-		result[0] = lub_string_dup(argv0);
+		result[0] = strdup(argv0);
 	for (i = 0; i < this->argc; i++)
-		result[i + a] = lub_string_dup(this->argv[i].arg);
+		result[i + a] = strdup(this->argv[i].arg);
 	result[i + a] = NULL;
 
 	return result;
@@ -67,7 +68,7 @@ void lub_argv__free_argv(char **argv)
 		return;
 
 	for (i = 0; argv[i]; i++)
-		lub_string_free(argv[i]);
+		free(argv[i]);
 	free(argv);
 }
 

+ 0 - 26
lub/argv/argv_delete.c

@@ -1,26 +0,0 @@
-/*
- * argv_delete.c
- */
-#include "private.h"
-#include "lub/string.h"
-
-#include <stdlib.h>
-/*--------------------------------------------------------- */
-static void lub_argv_fini(lub_argv_t * this)
-{
-	unsigned i;
-
-	for (i = 0; i < this->argc; i++)
-		lub_string_free(this->argv[i].arg);
-	free(this->argv);
-	this->argv = NULL;
-}
-
-/*--------------------------------------------------------- */
-void lub_argv_delete(lub_argv_t * this)
-{
-	lub_argv_fini(this);
-	free(this);
-}
-
-/*--------------------------------------------------------- */

+ 19 - 1
lub/argv/argv_new.c

@@ -69,7 +69,25 @@ void lub_argv_add(lub_argv_t * this, const char *text)
 	arg = realloc(this->argv, sizeof(lub_arg_t) * (this->argc + 1));
 	assert(arg);
 	this->argv = arg;
-	(this->argv[this->argc++]).arg = lub_string_dup(text);
+	(this->argv[this->argc++]).arg = strdup(text);
+}
+
+/*--------------------------------------------------------- */
+static void lub_argv_fini(lub_argv_t * this)
+{
+	unsigned i;
+
+	for (i = 0; i < this->argc; i++)
+		free(this->argv[i].arg);
+	free(this->argv);
+	this->argv = NULL;
+}
+
+/*--------------------------------------------------------- */
+void lub_argv_delete(lub_argv_t * this)
+{
+	lub_argv_fini(this);
+	free(this);
 }
 
 /*--------------------------------------------------------- */

+ 19 - 0
lub/argv/argv_nextword.c

@@ -61,3 +61,22 @@ const char *lub_argv_nextword(const char *string,
 }
 
 /*--------------------------------------------------------- */
+unsigned lub_argv_wordcount(const char *line)
+{
+	const char *word;
+	unsigned result = 0;
+	size_t len = 0, offset = 0;
+	bool_t quoted;
+
+	for (word = lub_argv_nextword(line, &len, &offset, &quoted);
+		*word;
+		word = lub_argv_nextword(word + len, &len, &offset, &quoted)) {
+		/* account for the terminating quotation mark */
+		len += (BOOL_TRUE == quoted) ? 1 : 0;
+		result++;
+	}
+
+	return result;
+}
+
+/*--------------------------------------------------------- */

+ 0 - 26
lub/argv/argv_wordcount.c

@@ -1,26 +0,0 @@
-/*
- * argv_wordcount.c
- *
- */
-#include "private.h"
-
-/*--------------------------------------------------------- */
-unsigned lub_argv_wordcount(const char *line)
-{
-	const char *word;
-	unsigned result = 0;
-	size_t len = 0, offset = 0;
-	bool_t quoted;
-
-	for (word = lub_argv_nextword(line, &len, &offset, &quoted);
-		*word;
-		word = lub_argv_nextword(word + len, &len, &offset, &quoted)) {
-		/* account for the terminating quotation mark */
-		len += (BOOL_TRUE == quoted) ? 1 : 0;
-		result++;
-	}
-
-	return result;
-}
-
-/*--------------------------------------------------------- */

+ 0 - 2
lub/argv/module.am

@@ -4,10 +4,8 @@ liblub_la_SOURCES +=                            \
                     lub/argv/argv__get_count.c	\
                     lub/argv/argv__get_offset.c	\
                     lub/argv/argv__get_quoted.c	\
-                    lub/argv/argv_delete.c	\
                     lub/argv/argv_new.c		\
                     lub/argv/argv_nextword.c	\
-                    lub/argv/argv_wordcount.c	\
                     lub/argv/private.h
 
 

+ 0 - 1
lub/string/module.am

@@ -1,7 +1,6 @@
 liblub_la_SOURCES +=	lub/string/string_cat.c	\
 			lub/string/string_catn.c	\
 			lub/string/string_dup.c	\
-			lub/string/string_dupn.c	\
 			lub/string/string_free.c	\
 			lub/string/string_nocasecmp.c	\
 			lub/string/string_nocasestr.c	\

+ 21 - 6
lub/string/string_dup.c

@@ -1,17 +1,32 @@
 /*
  * string_dup.c
  */
+#include <stdlib.h>
+#include <string.h>
+
 #include "private.h"
 
-#include <string.h>
 /*--------------------------------------------------------- */
 char *lub_string_dup(const char *string)
 {
-	char *result = NULL;
-	if (NULL != string) {
-		lub_string_cat(&result, string);
-	}
-	return result;
+	if (!string)
+		return NULL;
+	return strdup(string);
+}
+
+/*--------------------------------------------------------- */
+char *lub_string_dupn(const char *string, unsigned int len)
+{
+	char *res = NULL;
+
+	if (!string)
+		return res;
+	res = malloc(len + 1);
+	strncpy(res, string, len);
+	res[len] = '\0';
+
+	return res;
 }
 
+
 /*--------------------------------------------------------- */

+ 0 - 23
lub/string/string_dupn.c

@@ -1,23 +0,0 @@
-/*
- * string_dupn.c
- */
-#include "private.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-/*--------------------------------------------------------- */
-char *lub_string_dupn(const char *string, unsigned length)
-{
-	char *result = NULL;
-	if (NULL != string) {
-		result = malloc(length + 1);
-		if (NULL != result) {
-			strncpy(result, string, length);
-			result[length] = '\0';
-		}
-	}
-	return result;
-}
-
-/*--------------------------------------------------------- */