Adam Fedor <[EMAIL PROTECTED]> writes:

> Tom Koelman wrote:
>> Adam Fedor <[EMAIL PROTECTED]> writes:
>>
>>>Tom Koelman wrote:
>>>
>>>>Hi,
>>>>Under MiNGQ _gnu_process_args crashes when argv is 0. This patch
>>>>fixes
>>>>this and sets the executable to the empty string when this happens.
>>>>
>>>
>>>Wow. How often does this happen? It seems pretty strange to me.
>> It happens under MinGW. When I create a dll that uses GNUstep, and
>> this dll in turn is called by a program that is not compiled by gcc
>> this is the case.
>>
>
> OK. I commited this to the freeze branch (with a minor change so it
> compiles on gcc pre 3.0).

Meanwhile,

I think the attached patch is better. Under MinGW, it uses the
GetModuleFileName call to figure out the name of the executable if
argv happens to be 0.

Tom Koelman

Index: Source/NSProcessInfo.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/NSProcessInfo.m,v
retrieving revision 1.88.2.1
diff -u -p -r1.88.2.1 NSProcessInfo.m
--- Source/NSProcessInfo.m	18 Feb 2003 15:56:59 -0000	1.88.2.1
+++ Source/NSProcessInfo.m	23 Feb 2003 22:12:46 -0000
@@ -186,8 +186,28 @@ _gnu_process_args(int argc, char *argv[]
       }
   else
       {
+#ifdef __MINGW__
+      char* buffer;
+      int buffer_size = 0;
+      int needed_size = 0;
+      while (needed_size == buffer_size)
+          {
+          buffer_size = buffer_size + 256;
+          buffer = (char*)malloc(buffer_size);
+          needed_size = GetModuleFileNameA(NULL, buffer, buffer_size);
+          if (needed_size<buffer_size)
+              {
+              _gnu_arg_zero = buffer;
+              }
+          else
+              {
+              free(buffer);
+              }
+          }
+#else      
       _gnu_arg_zero = (char*)malloc(1);
       _gnu_arg_zero[0] = '\0';
+#endif      
       }
 
   /* Getting the process name */
_______________________________________________
Bug-gnustep mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gnustep

Reply via email to