This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cygstart patch


This time with patch. :-[

– Michael

On 8-Mar-2005 2:13, Michael Schaap wrote:

Hi Anthony, Chuck, all,

On 4-Mar-2005 4:21, Charles Wilson wrote:

Anthony --

I've applied this patch. Thanks!



Sorry for jumping in so late...


While I agree that the revised patch looks good and does the job, I'm not too happy with the constant reallocation that's going on. (I know, there won't be a measurable performance impact, but it, well, just looks wring to me. ;-) )

In any case, here's a proposed alternative patch (against the version containing Anthony's patch already) which calculates the actual total argument size in advance, before allocating.
(In addition, I've taken the opportunity to change the listed email address (cygwin_start at mscha dot org), which I had to block long ago due to the ongoing stream of spam and viruses, to a new one, obscured this time. Plus, I changed the feedback address to the mailing list address (also obscured), since the list is obviously much more responsive than I am. :-/ )


Chuck, if this looks OK to you, can you apply this patch?

Thanks, also to Anthony and all for everything you've done.

– Michael

PS: That free() bug was very embarrassing... :-[ (Hmm... why do I even draw attention to that again? ;-) )

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


diff -u ORIG/cygstart.1 ./cygstart.1
--- ORIG/cygstart.1	2002-03-15 04:51:30.000000000 +0100
+++ ./cygstart.1	2005-03-08 01:42:09.214625000 +0100
@@ -194,7 +194,7 @@
 
 .\"{{{  Author
 .SH AUTHOR
-Michael Schaap <cygwin_start@mscha.org>
+Michael Schaap <cygstart(at)mscha.org>
 .\"}}}
 .\"{{{  See also
 .SH "SEE ALSO"
diff -u ORIG/cygstart.c ./cygstart.c
--- ORIG/cygstart.c	2005-03-08 01:22:15.422250000 +0100
+++ ./cygstart.c	2005-03-08 01:41:21.167750000 +0100
@@ -1,7 +1,7 @@
 /*
  * cygstart - Let Windows start a program, or open a file or URL
  *
- * (c) 2002 Michael Schaap <cygwin_start@mscha.org>
+ * (c) 2002 Michael Schaap <cygstart(at)mscha.org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -74,6 +74,8 @@
     int ret;
     char *action = NULL;
     char *file = NULL;
+    size_t argLength;
+    const char **tmp;
     char *args = NULL;
     char *workDir = NULL;
     int show = SW_SHOWNORMAL;
@@ -102,7 +104,7 @@
         { NULL, '\0', 0, NULL, 0, NULL, NULL }
     };
 
-    /* SHow options */
+    /* Show options */
     struct poptOption showOptionsTable[] = {
         { "hide",  '\0',  POPT_ARG_NONE, NULL, 'H', \
           "Hides the window and activates another window", NULL},
@@ -340,16 +342,17 @@
 
     /* Retrieve any arguments */
     if (rest && *rest) {
-        if ((args = (char *) malloc(strlen(*rest)+1)) == NULL) {
+        tmp = rest;
+        argLength = strlen(*tmp);
+        while (tmp++ && *tmp) {
+            argLength += 1 + strlen(*tmp);
+        }
+        if ((args = (char *) malloc(argLength+1)) == NULL) {
             fprintf(stderr, "%s: memory allocation error\n", argv[0]);
             exit(1);
-        }	 
+        }
         strcpy(args, *rest);
         while (rest++ && *rest) {
-            if ((args = (char *) realloc(args, strlen(args)+strlen(*rest)+2)) == NULL) {
-                fprintf(stderr, "%s: memory allocation error\n", argv[0]);
-                exit(1);
-            }		
             strcat(args, " ");
             strcat(args, *rest);
         }
@@ -464,7 +467,7 @@
 {
     fprintf(f, "\n");
     fprintf(f, "With thanks to MSDN: <%s>\n\n", MSDN_URL);
-    fprintf(f, "Please report any bugs to <cygwin_start@mscha.org>.\n");
+    fprintf(f, "Please report any bugs to <cygwin(at)cygwin.com>.\n");
 }
 
 static printLicense(FILE *f, char *name)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]