[darwinbuild-changes] [482] branches/PR-6688645/darwinup/main.cpp

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 18 14:25:33 PDT 2009


Revision: 482
          http://trac.macosforge.org/projects/darwinbuild/changeset/482
Author:   wsiegrist at apple.com
Date:     2009-03-18 14:25:33 -0700 (Wed, 18 Mar 2009)
Log Message:
-----------
Rename partition to path to be more clear. Do not make an unnecessary copy of the arg since Depot copies it later.

Modified Paths:
--------------
    branches/PR-6688645/darwinup/main.cpp

Modified: branches/PR-6688645/darwinup/main.cpp
===================================================================
--- branches/PR-6688645/darwinup/main.cpp	2009-03-18 20:32:05 UTC (rev 481)
+++ branches/PR-6688645/darwinup/main.cpp	2009-03-18 21:25:33 UTC (rev 482)
@@ -33,18 +33,18 @@
 #include <limits.h>
 
 void usage(char* progname) {
-	fprintf(stderr, "usage:    %s [-v] [-p DIR] [command] [args]       \n", progname);
-	fprintf(stderr, "                                                             \n");
-	fprintf(stderr, "options:                                                     \n");
-	fprintf(stderr, "          -p DIR     install roots under DIR (default: /)    \n");
-	fprintf(stderr, "          -v         verbose (use -vv for extra verbosity)   \n");
-	fprintf(stderr, "                                                             \n");
-	fprintf(stderr, "commands:                                                    \n");
-	fprintf(stderr, "          install    <path>                                  \n");
-	fprintf(stderr, "          list                                               \n");
-	fprintf(stderr, "          files      <uuid>                                  \n");
-	fprintf(stderr, "          uninstall  <uuid>                                  \n");
-	fprintf(stderr, "          verify     <uuid>                                  \n");
+	fprintf(stderr, "usage:    %s [-v] [-p DIR] [command] [args]          \n", progname);
+	fprintf(stderr, "                                                               \n");
+	fprintf(stderr, "options:                                                       \n");
+	fprintf(stderr, "          -p DIR     operate on roots under DIR (default: /)   \n");
+	fprintf(stderr, "          -v         verbose (use -vv for extra verbosity)     \n");
+	fprintf(stderr, "                                                               \n");
+	fprintf(stderr, "commands:                                                      \n");
+	fprintf(stderr, "          install    <path>                                    \n");
+	fprintf(stderr, "          list                                                 \n");
+	fprintf(stderr, "          files      <uuid>                                    \n");
+	fprintf(stderr, "          uninstall  <uuid>                                    \n");
+	fprintf(stderr, "          verify     <uuid>                                    \n");
 	exit(1);
 }
 
@@ -52,11 +52,8 @@
 uint32_t verbosity;
 
 int main(int argc, char* argv[]) {
-	char* progname = strdup(basename(argv[0]));
-	
-	// the partition we are working on
-	char partition[PATH_MAX] = "/";
-
+	char* progname = strdup(basename(argv[0]));      
+	char* path;
 	int ch;
 	while ((ch = getopt(argc, argv, "p:v")) != -1) {
 		switch (ch) {
@@ -65,9 +62,11 @@
 			verbosity |= VERBOSE;
 			break;
 		case 'p':
-			int optlen = strlen(optarg);
-			int limitlen = (optlen < PATH_MAX ? optlen : PATH_MAX);
-			strncpy(partition, optarg, limitlen);
+		        if (strlen(optarg) > (PATH_MAX - 1)) {
+			        fprintf(stderr, "Error: -p option value is too long \n");
+				exit(3);
+			}
+			path = optarg;
 			break;
 		case '?':
 		default:
@@ -78,7 +77,7 @@
 	argv += optind;
 
 	int res = 0;
-	Depot* depot = new Depot(partition);
+	Depot* depot = new Depot(path);
 	if (!depot->is_locked()) {
 	        fprintf(stderr, 
 			"Error: unable to access and lock %s. " \
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20090318/a74ecea1/attachment.html>


More information about the darwinbuild-changes mailing list