[BusyBox] purging strdup_substr

Matt Kraai kraai at alumni.carnegiemellon.edu
Thu Jul 5 12:22:57 UTC 2001


Howdy,

The following removes strdup_substr entirely.  It was inspired by
an earlier simplification from Vladimir Oleynik.  I'll commit this
shortly unless I hear an objection.

Matt
-------------- next part --------------
Index: sed.c
===================================================================
RCS file: /var/cvs/busybox/sed.c,v
retrieving revision 1.71
diff -u -r1.71 sed.c
--- sed.c	2001/06/21 19:41:35	1.71
+++ sed.c	2001/07/05 18:15:26
@@ -223,7 +223,7 @@
 	idx = index_of_next_unescaped_regexp_delim(sed_cmd, substr, ++idx);
 	if (idx == -1)
 		error_msg_and_die("bad format in substitution expression");
-	match = strdup_substr(substr, oldidx, idx);
+	match = xstrndup(substr + oldidx, idx - oldidx);
 
 	/* determine the number of back references in the match string */
 	/* Note: we compute this here rather than in the do_subst_command()
@@ -242,7 +242,7 @@
 	idx = index_of_next_unescaped_regexp_delim(sed_cmd, substr, ++idx);
 	if (idx == -1)
 		error_msg_and_die("bad format in substitution expression");
-	sed_cmd->replace = strdup_substr(substr, oldidx, idx);
+	sed_cmd->replace = xstrndup(substr + oldidx, idx - oldidx);
 
 	/* process the flags */
 	while (substr[++idx]) {
Index: libbb/dirname.c
===================================================================
RCS file: /var/cvs/busybox/libbb/dirname.c,v
retrieving revision 1.2
diff -u -r1.2 dirname.c
--- libbb/dirname.c	2001/06/29 18:59:32	1.2
+++ libbb/dirname.c	2001/07/05 18:15:53
@@ -45,5 +45,5 @@
 	if (s < path)
 		return xstrdup (".");
 	else
-		return strdup_substr (path, 0, s - path + 1);
+		return xstrndup (path, s - path + 1);
 }
Index: libbb/strdup_substr.c
===================================================================
RCS file: strdup_substr.c
diff -N strdup_substr.c
--- /tmp/cvs1Rxyb5	Thu Jul  5 12:19:18 2001
+++ /dev/null	Mon Nov 13 12:19:20 2000
@@ -1,34 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Mini strdup_substr function.
- *
- * Copyright (C) 2001  Mark Whitley.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* Return a substring of STR, starting at index START and ending at END,
- * allocated on the heap.  */
-
-#include "libbb.h"
-
-char *strdup_substr(const char *str, int start, int end)
-{
-	int size = end - start + 1;
-	char *newstr = xmalloc(size);
-	memcpy(newstr, str+start, size-1);
-	newstr[size-1] = '\0';
-	return newstr;
-}
Index: libbb/libbb.h
===================================================================
RCS file: /var/cvs/busybox/libbb/libbb.h,v
retrieving revision 1.47
diff -u -r1.47 libbb.h
--- libbb/libbb.h	2001/06/26 16:36:26	1.47
+++ libbb/libbb.h	2001/07/05 18:16:01
@@ -254,10 +254,6 @@
 
 char *dirname (const char *path);
 
-static inline char *strdup_substr (const char *s, int start, int end)
-{
-        return xstrndup (s+start, end-start);
-}
 int make_directory (char *path, mode_t mode, int flags);
 
 #define CT_AUTO	0


More information about the busybox mailing list