Browse Source

dpkg-split, dpkg: Use new str_match_end() function instead of ad-hoc code

Guillem Jover 12 years ago
parent
commit
97ffe228c9
2 changed files with 12 additions and 18 deletions
  1. 7 11
      dpkg-split/split.c
  2. 5 7
      src/packages.c

+ 7 - 11
dpkg-split/split.c

@@ -41,6 +41,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/path.h>
+#include <dpkg/string.h>
 #include <dpkg/subproc.h>
 #include <dpkg/buffer.h>
 #include <dpkg/ar.h>
@@ -255,17 +256,12 @@ do_split(const char *const *argv)
 	if (prefix && *argv)
 		badusage(_("--split takes at most a source filename and destination prefix"));
 	if (!prefix) {
-		char *palloc;
-		int l;
-
-		l = strlen(sourcefile);
-		palloc = nfmalloc(l + 1);
-		strcpy(palloc, sourcefile);
-		if (strcmp(palloc + l - (sizeof(DEBEXT) - 1), DEBEXT) == 0) {
-			l -= (sizeof(DEBEXT) - 1);
-			palloc[l] = '\0';
-		}
-		prefix = palloc;
+		size_t sourcefile_len = strlen(sourcefile);
+
+		if (str_match_end(sourcefile, DEBEXT))
+			sourcefile_len -= strlen(DEBEXT);
+
+		prefix = nfstrnsave(sourcefile, sourcefile_len);
 	}
 
 	mksplit(sourcefile, prefix, opt_maxpartsize, opt_msdos);

+ 5 - 7
src/packages.c

@@ -41,6 +41,7 @@
 #include <dpkg/pkg-list.h>
 #include <dpkg/pkg-queue.h>
 #include <dpkg/pkg-spec.h>
+#include <dpkg/string.h>
 #include <dpkg/options.h>
 
 #include "filesdb.h"
@@ -114,13 +115,10 @@ enqueue_specified(const char *const *argv)
       badusage(_("--%s needs a valid package name but '%.250s' is not: %s"),
                cipaction->olong, thisarg, err.str);
 
-    if (pkg->status == stat_notinstalled) {
-      size_t l = strlen(pkg->set->name);
-      const char *extension = pkg->set->name + l - sizeof(DEBEXT) + 1;
-
-      if (l >= sizeof(DEBEXT) && strcmp(extension, DEBEXT) == 0)
-        badusage(_("you must specify packages by their own names,"
-                   " not by quoting the names of the files they come in"));
+    if (pkg->status == stat_notinstalled &&
+        str_match_end(pkg->set->name, DEBEXT)) {
+      badusage(_("you must specify packages by their own names, "
+                 "not by quoting the names of the files they come in"));
     }
     enqueue_package(pkg);
   }