mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Updates for revised NSProcessInfo
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4631 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0434537a06
commit
a4805d93d7
15 changed files with 776 additions and 474 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
|||
Thu Jul 22 13:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSTimeZone.m: ([-initWithOffset:]) bugfix by Kai Henningsen
|
||||
* acconfig.h: Removed old libc method of getting NSProcessInfo stuff.
|
||||
* aclocal.m4: Removed old libc method of getting NSProcessInfo stuff.
|
||||
* configure.in: Added new '/proc' method of getting NSProcessInfo stuff
|
||||
by Nico Pero, with modifications and --enable-fake-main
|
||||
* Headers/GSConfig.h.in: New NSProcessInfo stuff
|
||||
* Headers/NSObject.h: Remove fake-main include - use GSConfig.h
|
||||
* Headers/config.h.in: Remove fake-main include - use GSConfig.h
|
||||
* Headers/preface.h.in: Remove fake-main include - use GSConfig.h
|
||||
* Source/GNUmakefile: Remove fake-main.h
|
||||
* Source/Makefile.postamble: NSProcessInfo.o depends on GSConfig.h
|
||||
* Source/NSLog.m: Bugfix - set up pointer to log function.
|
||||
* Source/NSProcessInfo.m: Remove old hack for getting process info
|
||||
and add new '/proc' method, along with improvements to the fake-main
|
||||
mechanism.
|
||||
|
||||
Tue Jul 20 15:45:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSCalendarDate.m: ([initWithString:calendarFormat:locale:])
|
||||
|
|
|
@ -1,11 +1,80 @@
|
|||
/* Machine/OS specific configuration information for GNUstep
|
||||
|
||||
Please NOTE - GSConfig.h is generated by the configure script from the
|
||||
file GSConfig.h.in - changes/fixes need to be made to the original file,
|
||||
not to the GSConfig.h generated from it.
|
||||
|
||||
Copyright (C) 1998,1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Richard frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef included_GSConfig_h
|
||||
#define included_GSConfig_h
|
||||
|
||||
#define GS_FAKE_MAIN @GS_FAKE_MAIN@
|
||||
#if GS_FAKE_MAIN
|
||||
|
||||
/*
|
||||
* Machine/OS specific information required by GNUstep headers.
|
||||
* NOTE - if GS_FAKE_MAIN (above) is set to 1, this hack applies - and you
|
||||
* must make sure that this file is included in any file that implements
|
||||
* the 'main()' function and links with the GNUstep base libarary.
|
||||
* You should NOT include this file in a program that does not link with
|
||||
* the base library.
|
||||
* This file is included automatically in NSObject.h and Foundation.h
|
||||
*
|
||||
* The Foundation classe NSProcessInfo need access to the argc, argv,
|
||||
* and env variables of the main() function. The purpose of this (ugly hack)
|
||||
* definition is to give the gstep-base library the opportunity to implement
|
||||
* its own main function with private access to the global vars. The private
|
||||
* main() implementation (in NSProcessInfo.m) will then call the user defined
|
||||
* gnustep_base_user_main() function.
|
||||
*
|
||||
* The original hack was -
|
||||
** Written by: Georg Tuparev, EMBL & Academia Naturalis,
|
||||
** Heidelberg, Germany
|
||||
** Tuparev@EMBL-Heidelberg.de
|
||||
**
|
||||
** NOTE! This is very dirty and dangerous trick. I spend several hours
|
||||
** on thinking and man pages browsing, but couldn't find better solution.
|
||||
** I know that I will spend 666 years in the Computer Hell for writing
|
||||
** this hack, and the master devil (Bully Boy) will send me to write
|
||||
** Windowz software.
|
||||
** BTW, for writing this hack I got personal congratulations from Dennis
|
||||
** Ritchie and Bjarne Stroustrup sent me a bunch of flowers and asked me
|
||||
** to participate in the standardization committee for C-- v.6.0 as
|
||||
** responsible for the new Tab-Overriding-Operator and Scope-Sensitive-
|
||||
** Comments ... but this makes my situation even worse ;-)
|
||||
** - Georg
|
||||
*
|
||||
* On some systems, there are other relatively clean workarounds, if this
|
||||
* applies to the system you are running on, your configuration script
|
||||
* should have set GS_FAKE_MAIN to zero, so that this define hack will
|
||||
* not be used.
|
||||
*/
|
||||
|
||||
#define main gnustep_base_user_main
|
||||
extern int gnustep_base_user_main (/* int argc, char *argv[] */);
|
||||
|
||||
#endif /* GS_FAKE_MAIN */
|
||||
|
||||
|
||||
/*
|
||||
* Definition to specify if your processor stores words with the most
|
||||
* significant byte first (like Motorola and SPARC, unlike Intel and VAX).
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <objc/objc.h>
|
||||
#include <objc/Protocol.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
#include <base/fake-main.h>
|
||||
|
||||
@class NSArchiver;
|
||||
@class NSArray;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
byte first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
#undef SYS_AUTOLOAD
|
||||
#undef CON_AUTOLOAD
|
||||
|
||||
#undef NeXT_cc
|
||||
|
@ -27,6 +26,15 @@
|
|||
/* Define if you have the register_printf_function function. */
|
||||
#undef HAVE_REGISTER_PRINTF_FUNCTION
|
||||
|
||||
/* Define if your kernel supports the /proc filesystem */
|
||||
#undef HAVE_PROC_FS
|
||||
|
||||
/* Define if your Obj-C compiler calls +load methods before main */
|
||||
#undef HAVE_LOAD_METHOD
|
||||
|
||||
/* Define if your Lib C defines program_invocation_name */
|
||||
#undef HAVE_PROGRAM_INVOCATION_NAME
|
||||
|
||||
/* The number of bytes in a double. */
|
||||
#undef SIZEOF_DOUBLE
|
||||
|
||||
|
@ -48,6 +56,9 @@
|
|||
/* The number of bytes in a void*. */
|
||||
#undef SIZEOF_VOIDP
|
||||
|
||||
/* Define if you have the asprintf function. */
|
||||
#undef HAVE_ASPRINTF
|
||||
|
||||
/* Define if you have the getcwd function. */
|
||||
#undef HAVE_GETCWD
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/* LibobjectsMain.h for GNUStep
|
||||
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Georg Tuparev, EMBL & Academia Naturalis,
|
||||
Heidelberg, Germany
|
||||
Tuparev@EMBL-Heidelberg.de
|
||||
Last update: 05-aug-1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __fake_main_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __fake_main_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
/*
|
||||
Several Foundation classes (NSBundle, NSProcessInfo, ...) need access
|
||||
to the argc, argv, and env variables of the main() function. The purpose
|
||||
of this (ugly hack) definition is to give the libobjects library the
|
||||
oportunity to implement its own main function with private access to the
|
||||
global vars. The private main() implementation then will call the user
|
||||
defined (now renamed to LibobjectsMain()) function. The libobjects main()
|
||||
functions is implemented in NSProcessInfo.m
|
||||
*/
|
||||
|
||||
#if (!defined(SYS_AUTOLOAD)) || defined(__FreeBSD__)
|
||||
#ifndef __MINGW32__
|
||||
#define main gnustep_base_user_main
|
||||
extern int gnustep_base_user_main (/* int argc, char *argv[] */);
|
||||
#endif
|
||||
#endif /* __ELF__ */
|
||||
|
||||
/*
|
||||
NOTE! This is very dirty and dangerous trick. I spend several hours
|
||||
on thinking and man pages browsing, but couldn't find better solution.
|
||||
I know that I will spend 666 years in the Computer Hell for writing
|
||||
this hack, and the master devil (Bully Boy) will send me to write
|
||||
Windowz software.
|
||||
BTW, for writing this hack I got personal congratulations from Dennis
|
||||
Ritchie and Bjarne Stroustrup sent me a bunch of flowers and asked me
|
||||
to participate in the standardization committee for C-- v.6.0 as
|
||||
responsible for the new Tab-Overriding-Operator and Scope-Sensitive-
|
||||
Comments ... but this makes my situation even worse ;-)
|
||||
- Georg
|
||||
*/
|
||||
|
||||
#endif /* __fake_main_h_GNUSTEP_BASE_INCLUDE */
|
|
@ -27,7 +27,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <base/objc-gnu2next.h>
|
||||
#include <base/fake-main.h>
|
||||
#include <GSConfig.h>
|
||||
|
||||
#if defined(__WIN32__) || defined(_WIN32) || defined(__MS_WIN32__)
|
||||
#ifndef __WIN32__
|
||||
|
|
|
@ -226,7 +226,6 @@ Unicode.h \
|
|||
UnixFileHandle.h \
|
||||
ValueHolding.h \
|
||||
behavior.h \
|
||||
fake-main.h \
|
||||
numbers.h \
|
||||
ostream.h \
|
||||
o_array.h \
|
||||
|
|
|
@ -195,6 +195,7 @@ $(GNUSTEP_OBJ_DIR)/NSConnection.o \
|
|||
$(GNUSTEP_OBJ_DIR)/NSData.o \
|
||||
$(GNUSTEP_OBJ_DIR)/NSInvocation.o \
|
||||
$(GNUSTEP_OBJ_DIR)/NSMethodSignature.o \
|
||||
$(GNUSTEP_OBJ_DIR)/NSProcessInfo.o \
|
||||
$(GNUSTEP_OBJ_DIR)/NSUnarchiver.o \
|
||||
: $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/GSConfig.h
|
||||
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
NSLog_printf_handler *_NSLog_printf_handler;
|
||||
|
||||
static void
|
||||
_NSLog_standard_printf_handler (NSString* message)
|
||||
{
|
||||
|
@ -75,6 +73,8 @@ _NSLog_standard_printf_handler (NSString* message)
|
|||
#endif
|
||||
}
|
||||
|
||||
NSLog_printf_handler *_NSLog_printf_handler = _NSLog_standard_printf_handler;
|
||||
|
||||
void
|
||||
NSLog (NSString* format, ...)
|
||||
{
|
||||
|
@ -130,7 +130,7 @@ NSLogv (NSString* format, va_list args)
|
|||
}
|
||||
[myLock lock];
|
||||
|
||||
_NSLog_printf_handler (prefix);
|
||||
_NSLog_printf_handler(prefix);
|
||||
|
||||
[myLock unlock];
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Implementation for NSProcessInfo for GNUStep
|
||||
Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995-1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Georg Tuparev, EMBL & Academia Naturalis,
|
||||
Heidelberg, Germany
|
||||
|
@ -24,7 +24,6 @@
|
|||
|
||||
/*************************************************************************
|
||||
* File Name : NSProcessInfo.m
|
||||
* Version : 0.6 beta
|
||||
* Date : 06-aug-1995
|
||||
*************************************************************************
|
||||
* Notes :
|
||||
|
@ -40,14 +39,14 @@
|
|||
* 1) To test the class on more platforms;
|
||||
* 2) To change the format of the string renurned by globallyUniqueString;
|
||||
* Bugs : Not known
|
||||
* Last update: 08-aug-1995
|
||||
* Last update: 22-jul-1999
|
||||
* History : 06-aug-1995 - Birth and the first beta version (v. 0.5);
|
||||
* 08-aug-1995 - V. 0.6 (tested on NS, SunOS, Solaris, OSF/1
|
||||
* The use of the environ global var was changed to more
|
||||
* conventional env[] (main function) so now the class could be
|
||||
* used on SunOS and Solaris. [GT]
|
||||
*************************************************************************
|
||||
* Acknowledgments:
|
||||
* Acknowledgments:
|
||||
* - Adam Fedor, Andrew McCallum, and Paul Kunz for their help;
|
||||
* - To the NEXTSTEP/GNUStep community
|
||||
*************************************************************************/
|
||||
|
@ -62,6 +61,10 @@
|
|||
#include <netdb.h>
|
||||
#endif /* !__WIN32__ */
|
||||
|
||||
#ifdef HAVE_STRERROR
|
||||
#include <errno.h>
|
||||
#endif /* HAVE_STRERROR */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -75,34 +78,44 @@
|
|||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
/* This error message should be called only if the private main function
|
||||
* was not executed successfully. This may heppen ONLY if onother library
|
||||
* was not executed successfully. This may happen ONLY if another library
|
||||
* or kit defines its own main function (as gnustep-base does).
|
||||
*/
|
||||
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"GNUSTEP Internal Error: \
|
||||
The private GNUstep function to establish the argv and environment \
|
||||
variables was not called. Please report this error to bug-gnustep@gnu.org."
|
||||
#if GS_FAKE_MAIN
|
||||
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"\nGNUSTEP Internal Error:\n\
|
||||
The private GNUstep function to establish the argv and environment\n\
|
||||
variables was not called.\n\
|
||||
Perhaps your program failed to #include <Foundation/NSObject.h> or\n\
|
||||
<Foundation/Foundation.h>?\n\
|
||||
If that is not the problem, Please report the error to bug-gnustep@gnu.org.\n\n"
|
||||
#else
|
||||
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"\nGNUSTEP Internal Error:\n\
|
||||
The private GNUstep function to establish the argv and environment\n\
|
||||
variables was not called.\n\
|
||||
Please report the error to bug-gnustep@gnu.org.\n\n"
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
*** _NSConcreteProcessInfo
|
||||
*************************************************************************/
|
||||
@interface _NSConcreteProcessInfo:NSProcessInfo
|
||||
- (id)autorelease;
|
||||
- (void)release;
|
||||
- (id)retain;
|
||||
@interface _NSConcreteProcessInfo: NSProcessInfo
|
||||
- (id) autorelease;
|
||||
- (void) release;
|
||||
- (id) retain;
|
||||
@end
|
||||
|
||||
@implementation _NSConcreteProcessInfo
|
||||
- (id)autorelease
|
||||
- (id) autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)release
|
||||
- (void) release
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (id)retain
|
||||
- (id) retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
@ -116,25 +129,25 @@ variables was not called. Please report this error to bug-gnustep@gnu.org."
|
|||
*** Static global vars
|
||||
*************************************************************************/
|
||||
// The shared NSProcessInfo instance
|
||||
static NSProcessInfo* _gnu_sharedProcessInfoObject = nil;
|
||||
static NSProcessInfo *_gnu_sharedProcessInfoObject = nil;
|
||||
|
||||
// Host name of the CPU executing the process
|
||||
static NSString* _gnu_hostName = nil;
|
||||
static NSString *_gnu_hostName = nil;
|
||||
|
||||
// Current process name
|
||||
static NSString* _gnu_processName = nil;
|
||||
static NSString *_gnu_processName = nil;
|
||||
|
||||
// Array of NSStrings (argv[1] .. argv[argc-1])
|
||||
static NSArray* _gnu_arguments = nil;
|
||||
static NSArray *_gnu_arguments = nil;
|
||||
|
||||
// Dictionary of environment vars and their values
|
||||
static NSMutableDictionary* _gnu_environment = nil;
|
||||
static NSMutableDictionary *_gnu_environment = nil;
|
||||
|
||||
// Array of debug levels set.
|
||||
static NSMutableSet* _debug_set = nil;
|
||||
static NSMutableSet *_debug_set = nil;
|
||||
|
||||
/*************************************************************************
|
||||
*** Implementing the Libobjects main function
|
||||
*** Implementing the gnustep_base_user_main function
|
||||
*************************************************************************/
|
||||
|
||||
static void
|
||||
|
@ -144,31 +157,33 @@ _gnu_process_args(int argc, char *argv[], char *env[])
|
|||
int i;
|
||||
|
||||
/* Getting the process name */
|
||||
_gnu_processName = [[NSString alloc] initWithCString:argv[0]];
|
||||
|
||||
_gnu_processName = [[NSString alloc] initWithCString: argv[0]];
|
||||
|
||||
/* Copy the argument list */
|
||||
{
|
||||
NSMutableSet *mySet;
|
||||
id obj_argv[argc];
|
||||
int added = 0;
|
||||
id obj_argv[argc];
|
||||
int added = 0;
|
||||
|
||||
mySet = [[NSMutableSet alloc] init];
|
||||
mySet = [NSMutableSet new];
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
NSString *str = [NSString stringWithCString:argv[i]];
|
||||
NSString *str = [NSString stringWithCString: argv[i]];
|
||||
|
||||
if ([str hasPrefix: @"--GNU-Debug="])
|
||||
[mySet addObject: [str substringFromIndex: 12]];
|
||||
else
|
||||
obj_argv[added++] = str;
|
||||
}
|
||||
_gnu_arguments = [[NSArray alloc] initWithObjects:obj_argv count:added];
|
||||
_gnu_arguments = [[NSArray alloc] initWithObjects: obj_argv count: added];
|
||||
_debug_set = mySet;
|
||||
}
|
||||
|
||||
/* Copy the evironment list */
|
||||
{
|
||||
NSMutableArray *keys = [NSMutableArray new];
|
||||
NSMutableArray *values = [NSMutableArray new];
|
||||
NSMutableArray *keys = [NSMutableArray new];
|
||||
NSMutableArray *values = [NSMutableArray new];
|
||||
|
||||
i = 0;
|
||||
while (env[i])
|
||||
{
|
||||
|
@ -200,6 +215,7 @@ _gnu_process_args(int argc, char *argv[], char *env[])
|
|||
#else
|
||||
int len = strlen(env[i]);
|
||||
char *cp = strchr(env[i], '=');
|
||||
|
||||
if (len && cp)
|
||||
{
|
||||
char buf[len+2];
|
||||
|
@ -213,86 +229,191 @@ _gnu_process_args(int argc, char *argv[], char *env[])
|
|||
#endif
|
||||
i++;
|
||||
}
|
||||
_gnu_environment = [[NSDictionary alloc] initWithObjects:values
|
||||
forKeys:keys];
|
||||
/* Do this explicitly, because we probably don't have
|
||||
a NSAutoreleasePool initialized yet. */
|
||||
_gnu_environment = [[NSDictionary alloc] initWithObjects: values
|
||||
forKeys: keys];
|
||||
[keys release];
|
||||
[values release];
|
||||
}
|
||||
[arp release];
|
||||
}
|
||||
|
||||
/* Place the _gnu_process_args function in the _libc_subinit section so
|
||||
that it automatically gets called before main with the argument and
|
||||
environment pointers. FIXME: Would like to do something similar
|
||||
for other formats besides ELF. */
|
||||
#if (!defined(__FreeBSD__)) && defined(SYS_AUTOLOAD)
|
||||
#ifdef linux
|
||||
|
||||
/* Under linux the functions in __libc_subinit are called before the
|
||||
* global constructiors, therefore, we cannot send methods to any objects
|
||||
#if !GS_FAKE_MAIN && (defined(HAVE_PROC_FS) && defined(HAVE_LOAD_METHOD))
|
||||
/*
|
||||
* We have to save program arguments and environment before main () is
|
||||
* executed, because main () could modify their values before we get a
|
||||
* chance to read them
|
||||
*/
|
||||
static int _gnu_noobjc_argc;
|
||||
static char **_gnu_noobjc_argv;
|
||||
static char **_gnu_noobjc_env;
|
||||
|
||||
static int _gnu_noobjc_argc;
|
||||
static char **_gnu_noobjc_argv;
|
||||
static char **_gnu_noobjc_env;
|
||||
|
||||
static void
|
||||
_gnu_process_noobjc_args(int argc, char *argv[], char *env[])
|
||||
/*
|
||||
* The +load method (an extension of the GNU compiler) is invoked
|
||||
* before main and +initialize (for this class) is executed. This is
|
||||
* guaranteed if +load contains only pure C code, as we have here.
|
||||
*/
|
||||
+ (void) load
|
||||
{
|
||||
int i;
|
||||
|
||||
/* We have to copy these in case the main() modifies their values
|
||||
* somehow before we get a change to use them
|
||||
/*
|
||||
* Now we have the problem of reading program arguments and
|
||||
* environment. We take the environment from extern char **environ, and
|
||||
* the program arguments from the /proc filesystem.
|
||||
*/
|
||||
|
||||
_gnu_noobjc_argc = argc;
|
||||
i = 0;
|
||||
while (argv[i])
|
||||
i++;
|
||||
_gnu_noobjc_argv = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto error;
|
||||
i = 0;
|
||||
while (*argv)
|
||||
{
|
||||
_gnu_noobjc_argv[i] = malloc(strlen(*argv)+1);
|
||||
if (_gnu_noobjc_argv[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_argv[i],*argv);
|
||||
argv++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_argv[i] = 0;
|
||||
i = 0;
|
||||
while (env[i])
|
||||
i++;
|
||||
_gnu_noobjc_env = malloc(sizeof(char *)*(i+1));
|
||||
extern char **environ;
|
||||
char *proc_file_name = NULL;
|
||||
FILE *ifp;
|
||||
int c;
|
||||
int argument;
|
||||
int length;
|
||||
int position;
|
||||
int env_terms;
|
||||
#ifdef HAVE_PROGRAM_INVOCATION_NAME
|
||||
extern char *program_invocation_name;
|
||||
#endif /* HAVE_PROGRAM_INVOCATION_NAME */
|
||||
|
||||
// Read environment
|
||||
c = 0;
|
||||
while (environ[c] != NULL)
|
||||
c++;
|
||||
env_terms = c;
|
||||
_gnu_noobjc_env = (char**)malloc(sizeof(char*) * (env_terms + 1));
|
||||
if (_gnu_noobjc_env == NULL)
|
||||
goto error;
|
||||
i = 0;
|
||||
while(*env)
|
||||
goto malloc_error;
|
||||
for (c = 0; c < env_terms; c++)
|
||||
{
|
||||
_gnu_noobjc_env[i] = malloc(strlen(*env)+1);
|
||||
if (_gnu_noobjc_env[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_env[i],*env);
|
||||
env++;
|
||||
i++;
|
||||
_gnu_noobjc_env[c] = (char *)strdup(environ[c]);
|
||||
if (_gnu_noobjc_env[c] == NULL)
|
||||
goto malloc_error;
|
||||
}
|
||||
_gnu_noobjc_env[i] = 0;
|
||||
_gnu_noobjc_env[c] = NULL;
|
||||
|
||||
// Read commandline
|
||||
proc_file_name = (char *)malloc(sizeof(char) * 2048);
|
||||
sprintf(proc_file_name, "/proc/%d/cmdline", (int) getpid());
|
||||
|
||||
/*
|
||||
* We read the /proc file thrice.
|
||||
* First, to know how many arguments there are and allocate memory for them.
|
||||
* Second, to know how long each argument is, and allocate memory accordingly.
|
||||
* Third, to actually copy the arguments into memory.
|
||||
*/
|
||||
_gnu_noobjc_argc = 0;
|
||||
#ifdef HAVE_STRERROR
|
||||
errno = 0;
|
||||
#endif /* HAVE_STRERROR */
|
||||
ifp = fopen(proc_file_name, "r");
|
||||
if (ifp == NULL)
|
||||
goto proc_fs_error;
|
||||
while (1)
|
||||
{
|
||||
c = getc(ifp);
|
||||
if (c == 0)
|
||||
_gnu_noobjc_argc++;
|
||||
else if (c == EOF)
|
||||
break;
|
||||
}
|
||||
_gnu_noobjc_argc++;
|
||||
/*
|
||||
* Now _gnu_noobcj_argc is the number of arguments;
|
||||
* allocate memory accordingly.
|
||||
*/
|
||||
_gnu_noobjc_argv = (char **)malloc((sizeof(char *)) * (_gnu_noobjc_argc + 1));
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto malloc_error;
|
||||
|
||||
freopen(proc_file_name, "r", ifp);
|
||||
if (ifp == NULL)
|
||||
{
|
||||
free(_gnu_noobjc_argv);
|
||||
goto proc_fs_error;
|
||||
}
|
||||
argument = 0;
|
||||
length = 0;
|
||||
while (1)
|
||||
{
|
||||
c = getc(ifp);
|
||||
length++;
|
||||
if ((c == EOF) || (c == 0)) // End of a parameter
|
||||
{
|
||||
_gnu_noobjc_argv[argument] = (char*)malloc((sizeof(char))*length);
|
||||
if (_gnu_noobjc_argv[argument] == NULL)
|
||||
goto malloc_error;
|
||||
argument++;
|
||||
if (c == EOF) // End of command line
|
||||
break;
|
||||
length = 0;
|
||||
}
|
||||
}
|
||||
freopen(proc_file_name, "r", ifp);
|
||||
if (ifp == NULL)
|
||||
{
|
||||
for (c = 0; c < _gnu_noobjc_argc; c++)
|
||||
free(_gnu_noobjc_argv[c]);
|
||||
free(_gnu_noobjc_argv);
|
||||
goto proc_fs_error;
|
||||
}
|
||||
argument = 0;
|
||||
position = 0;
|
||||
while (1)
|
||||
{
|
||||
c = getc(ifp);
|
||||
if ((c == EOF) || (c == 0)) // End of a parameter
|
||||
{
|
||||
_gnu_noobjc_argv[argument][position] = '\0';
|
||||
argument++;
|
||||
if (c == EOF) // End of command line
|
||||
break;
|
||||
position = 0;
|
||||
continue;
|
||||
}
|
||||
_gnu_noobjc_argv[argument][position] = c;
|
||||
position++;
|
||||
}
|
||||
_gnu_noobjc_argv[argument] = NULL;
|
||||
fclose(ifp);
|
||||
free(proc_file_name);
|
||||
return;
|
||||
|
||||
error:
|
||||
fputs("malloc() error when starting gstep-base\n", stderr);
|
||||
proc_fs_error:
|
||||
#ifdef HAVE_STRERROR
|
||||
fprintf(stderr, "Couldn't open file %s when starting gnustep-base; %s\n",
|
||||
proc_file_name, strerror(errno));
|
||||
#else /* !HAVE_FUNCTION_STRERROR */
|
||||
fprintf(stderr, "Couldn't open file %s when starting gnustep-base.\n",
|
||||
proc_file_name);
|
||||
#endif /* HAVE_FUNCTION_STRERROR */
|
||||
fprintf(stderr, "Your gnustep-base library is compiled for a kernel supporting the /proc filesystem, but it can't access it.\n");
|
||||
fprintf(stderr, "You should recompile or change your kernel.\n");
|
||||
#ifdef HAVE_PROGRAM_INVOCATION_NAME
|
||||
fprintf(stderr, "We try to go on anyway; but the program will ignore any argument which were passed to it.\n");
|
||||
_gnu_noobjc_argc = 1;
|
||||
_gnu_noobjc_argv = malloc(sizeof(char *) * 2);
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto malloc_error;
|
||||
_gnu_noobjc_argv[0] = strdup(program_invocation_name);
|
||||
if (_gnu_noobjc_argv[0] == NULL)
|
||||
goto malloc_error;
|
||||
_gnu_noobjc_argv[1] = NULL;
|
||||
return;
|
||||
#else /* !HAVE_PROGRAM_INVOCATION_NAME */
|
||||
/*
|
||||
* There is really little sense in going on here, because NSBundle
|
||||
* will anyway crash later if we just put something like "_Unknown_"
|
||||
* as the program name.
|
||||
*/
|
||||
abort();
|
||||
#endif /* HAVE_PROGRAM_INVOCATION_NAME */
|
||||
malloc_error:
|
||||
fprintf(stderr, "malloc() error when starting gnustep-base.\n");
|
||||
fprintf(stderr, "Free some memory and then re-run the program.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
static void _gnu_noobjc_free_vars(void)
|
||||
static void
|
||||
_gnu_noobjc_free_vars(void)
|
||||
{
|
||||
char **p;
|
||||
|
||||
|
||||
p = _gnu_noobjc_argv;
|
||||
while (*p)
|
||||
{
|
||||
|
@ -312,33 +433,25 @@ static void _gnu_noobjc_free_vars(void)
|
|||
_gnu_noobjc_env = 0;
|
||||
}
|
||||
|
||||
void * __gnustep_base_subinit_args__
|
||||
__attribute__ ((section ("__libc_subinit"))) = &(_gnu_process_noobjc_args);
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (!_gnu_processName && !_gnu_arguments && !_gnu_environment)
|
||||
{
|
||||
NSAssert(_gnu_noobjc_argv && _gnu_noobjc_env,
|
||||
_GNU_MISSING_MAIN_FUNCTION_CALL);
|
||||
_gnu_process_args(_gnu_noobjc_argc,_gnu_noobjc_argv,_gnu_noobjc_env);
|
||||
_GNU_MISSING_MAIN_FUNCTION_CALL);
|
||||
_gnu_process_args(_gnu_noobjc_argc, _gnu_noobjc_argv, _gnu_noobjc_env);
|
||||
_gnu_noobjc_free_vars();
|
||||
}
|
||||
}
|
||||
#else /* !HAVE_PROC_FS || !HAVE_LOAD_METHOD */
|
||||
|
||||
#else
|
||||
static void * __gnustep_base_subinit_args__
|
||||
__attribute__ ((section ("_libc_subinit"))) = &(_gnu_process_args);
|
||||
#endif /* linux */
|
||||
|
||||
#else
|
||||
#ifdef __MINGW32__
|
||||
/* For Windows32API Library, we know the global variables */
|
||||
extern int __argc;
|
||||
extern char** __argv;
|
||||
extern char** _environ;
|
||||
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSProcessInfo class])
|
||||
_gnu_process_args(__argc, __argv, _environ);
|
||||
|
@ -366,15 +479,16 @@ int main(int argc, char *argv[], char *env[])
|
|||
_gnu_process_args(argc, argv, env);
|
||||
|
||||
/* Call the user defined main function */
|
||||
return gnustep_base_user_main (argc, argv, env);
|
||||
return gnustep_base_user_main(argc, argv, env);
|
||||
}
|
||||
#endif /* __MINGW32__ */
|
||||
#endif /* __ELF__ */
|
||||
|
||||
#endif /* HAS_LOAD_METHOD && HAS_PROC_FS */
|
||||
|
||||
/*************************************************************************
|
||||
*** Getting an NSProcessInfo Object
|
||||
*************************************************************************/
|
||||
+ (NSProcessInfo *)processInfo
|
||||
+ (NSProcessInfo *) processInfo
|
||||
{
|
||||
// Check if the main() function was successfully called
|
||||
// We can't use NSAssert, which calls NSLog, which calls NSProcessInfo...
|
||||
|
@ -382,7 +496,7 @@ int main(int argc, char *argv[], char *env[])
|
|||
{
|
||||
_NSLog_printf_handler(_GNU_MISSING_MAIN_FUNCTION_CALL);
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: _GNU_MISSING_MAIN_FUNCTION_CALL];
|
||||
format: _GNU_MISSING_MAIN_FUNCTION_CALL];
|
||||
}
|
||||
|
||||
if (!_gnu_sharedProcessInfoObject)
|
||||
|
@ -394,7 +508,7 @@ int main(int argc, char *argv[], char *env[])
|
|||
/*************************************************************************
|
||||
*** Returning Process Information
|
||||
*************************************************************************/
|
||||
- (NSArray *)arguments
|
||||
- (NSArray *) arguments
|
||||
{
|
||||
return _gnu_arguments;
|
||||
}
|
||||
|
@ -404,29 +518,29 @@ int main(int argc, char *argv[], char *env[])
|
|||
return _debug_set;
|
||||
}
|
||||
|
||||
- (NSDictionary *)environment
|
||||
- (NSDictionary *) environment
|
||||
{
|
||||
return _gnu_environment;
|
||||
}
|
||||
|
||||
- (NSString *)hostName
|
||||
- (NSString *) hostName
|
||||
{
|
||||
if (!_gnu_hostName)
|
||||
{
|
||||
char hn[MAXHOSTNAMELEN];
|
||||
|
||||
gethostname(hn, MAXHOSTNAMELEN);
|
||||
_gnu_hostName = [[NSString alloc] initWithCString:hn];
|
||||
_gnu_hostName = [[NSString alloc] initWithCString: hn];
|
||||
}
|
||||
return _gnu_hostName;
|
||||
}
|
||||
|
||||
- (NSString *)processName
|
||||
- (NSString *) processName
|
||||
{
|
||||
return _gnu_processName;
|
||||
}
|
||||
|
||||
- (NSString *)globallyUniqueString
|
||||
- (NSString *) globallyUniqueString
|
||||
{
|
||||
int pid;
|
||||
|
||||
|
@ -439,7 +553,7 @@ int main(int argc, char *argv[], char *env[])
|
|||
// $$$ The format of the string is not specified by the OpenStep
|
||||
// specification. It could be useful to change this format after
|
||||
// NeXTSTEP release 4.0 comes out.
|
||||
return [NSString stringWithFormat:@"%s:%d:[%s]",
|
||||
return [NSString stringWithFormat: @"%s: %d: [%s]",
|
||||
[[self hostName] cString],
|
||||
pid,
|
||||
[[[NSDate date] description] cString]];
|
||||
|
@ -448,11 +562,11 @@ int main(int argc, char *argv[], char *env[])
|
|||
/*************************************************************************
|
||||
*** Specifying a Process Name
|
||||
*************************************************************************/
|
||||
- (void)setProcessName:(NSString *)newName
|
||||
- (void) setProcessName: (NSString *)newName
|
||||
{
|
||||
if (newName && [newName length]) {
|
||||
[_gnu_processName autorelease];
|
||||
_gnu_processName = [newName copyWithZone:[self zone]];
|
||||
_gnu_processName = [newName copyWithZone: [self zone]];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -405,7 +405,7 @@ decode (const void *ptr)
|
|||
name = [NSString stringWithFormat: @"%d", anOffset];
|
||||
detail = [[NSConcreteTimeZoneDetail alloc]
|
||||
initWithTimeZone: self withAbbrev: name
|
||||
withOffset: offset withDST: NO];
|
||||
withOffset: anOffset withDST: NO];
|
||||
offset = anOffset;
|
||||
return self;
|
||||
}
|
||||
|
|
10
acconfig.h
10
acconfig.h
|
@ -1,7 +1,6 @@
|
|||
/* Macros that may be defined by the aclocal.m4 extentions to `configure'
|
||||
for GNUstep Base Library. */
|
||||
|
||||
#undef SYS_AUTOLOAD
|
||||
#undef CON_AUTOLOAD
|
||||
|
||||
#undef NeXT_cc
|
||||
|
@ -117,3 +116,12 @@
|
|||
|
||||
/* Define if you have the <values.h> header file. */
|
||||
#undef HAVE_VALUES_H
|
||||
|
||||
/* Define if your kernel supports the /proc filesystem */
|
||||
#undef HAVE_PROC_FS
|
||||
|
||||
/* Define if your Obj-C compiler calls +load methods before main */
|
||||
#undef HAVE_LOAD_METHOD
|
||||
|
||||
/* Define if your Lib C defines program_invocation_name */
|
||||
#undef HAVE_PROGRAM_INVOCATION_NAME
|
||||
|
|
37
aclocal.m4
vendored
37
aclocal.m4
vendored
|
@ -62,45 +62,9 @@ else
|
|||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN(OBJC_SYS_AUTOLOAD,
|
||||
#--------------------------------------------------------------------
|
||||
# Guess if we are using a object file format that supports automatic
|
||||
# loading of init functions.
|
||||
#
|
||||
# Makes the following substitutions:
|
||||
# Defines SYS_AUTOLOAD (whether initializer functions are autoloaded)
|
||||
#--------------------------------------------------------------------
|
||||
[AC_MSG_CHECKING(loading of initializer functions)
|
||||
AC_CACHE_VAL(objc_cv_subinit_worked,
|
||||
[AC_TRY_RUN([
|
||||
static char *argv0 = 0;
|
||||
static char *env0 = 0;
|
||||
static void args_test (int argc, char *argv[], char *env[])
|
||||
{
|
||||
argv0 = argv[0];
|
||||
env0 = env[0];
|
||||
}
|
||||
static void * __libobjects_subinit_args__
|
||||
__attribute__ ((section ("__libc_subinit"))) = &(args_test);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argv[0] == argv0 && env[0] == env0)
|
||||
exit (0);
|
||||
exit (1);
|
||||
}
|
||||
], objc_cv_subinit_worked=yes, objc_cv_subinit_worked=no, objc_cv_subinit_worked=no)])
|
||||
if test $objc_cv_subinit_worked = yes; then
|
||||
AC_DEFINE(SYS_AUTOLOAD)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN(OBJC_SYS_DYNAMIC_LINKER,
|
||||
[dnl
|
||||
AC_REQUIRE([OBJC_CON_AUTOLOAD])dnl
|
||||
AC_REQUIRE([OBJC_SYS_AUTOLOAD])dnl
|
||||
#--------------------------------------------------------------------
|
||||
# Guess the type of dynamic linker for the system
|
||||
#
|
||||
|
@ -126,7 +90,6 @@ AC_SUBST(DYNAMIC_LINKER)dnl
|
|||
AC_DEFUN(OBJC_SYS_DYNAMIC_FLAGS,
|
||||
[dnl
|
||||
AC_REQUIRE([OBJC_CON_AUTOLOAD])dnl
|
||||
AC_REQUIRE([OBJC_SYS_AUTOLOAD])dnl
|
||||
AC_REQUIRE([OBJC_SYS_DYNAMIC_LINKER])dnl
|
||||
#--------------------------------------------------------------------
|
||||
# Set the flags for compiling dynamically loadable objects
|
||||
|
|
100
configure.in
100
configure.in
|
@ -378,6 +378,49 @@ AC_SUBST(_GSC_S_LNG_LNG)
|
|||
#--------------------------------------------------------------------
|
||||
OBJC_SYS_DYNAMIC_LINKER()
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Guess if we are using a compiler which has the (GNU extension) +load
|
||||
# method which is executed before main.
|
||||
# Defines HAVE_LOAD_METHOD if +load methods are called before main.
|
||||
# Needed by NSProcessInfo.m
|
||||
#--------------------------------------------------------------------
|
||||
AC_MSG_CHECKING(if +load method is executed before main)
|
||||
AC_CACHE_VAL(objc_load_method_worked,
|
||||
[dnl Temporarily redefine m4 quote symbols
|
||||
dnl Because in the test program we need to use ObjC [object message] syntax
|
||||
changequote(,)
|
||||
cat > loadtest.m <<EOF
|
||||
@interface Test
|
||||
static int test_result;
|
||||
+(void) load;
|
||||
+(int) test_result;
|
||||
@end
|
||||
|
||||
@implementation Test
|
||||
static int test_result = 1;
|
||||
+(void) load {test_result = 0;}
|
||||
+(int) test_result {return test_result;}
|
||||
@end
|
||||
|
||||
int main (void) {return [Test test_result];}
|
||||
EOF
|
||||
changequote([,])
|
||||
dnl FIX, -lobjc -lpthread should be substituted
|
||||
$CC -o loadtest $CFLAGS $OBJCFLAGS $LDFLAGS loadtest.m $LIBS -lobjc -lpthread >/dev/null 2>/dev/null
|
||||
rm loadtest.m
|
||||
objc_load_method_worked=no
|
||||
if (./loadtest); then
|
||||
objc_load_method_worked=yes
|
||||
fi
|
||||
rm loadtest >/dev/null 2>/dev/null
|
||||
])
|
||||
if test $objc_load_method_worked = yes; then
|
||||
AC_DEFINE(HAVE_LOAD_METHOD)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Generic settings needed by NSZone.m
|
||||
#--------------------------------------------------------------------
|
||||
|
@ -489,7 +532,7 @@ AC_FUNC_SETPGRP
|
|||
AC_CHECK_FUNCS(usleep)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# This function needed by NSDebug.m
|
||||
# This function needed by NSDebug.m and NSProcessInfo.m
|
||||
#--------------------------------------------------------------------
|
||||
AC_CHECK_FUNCS(strerror)
|
||||
|
||||
|
@ -512,6 +555,42 @@ fi
|
|||
#--------------------------------------------------------------------
|
||||
AC_CHECK_FUNCS(realpath)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check if the C Library defines extern char *program_invocation_name
|
||||
# Used in critical cases by NSProcessInfo.m
|
||||
#--------------------------------------------------------------------
|
||||
AC_MSG_CHECKING(program_invocation_name in C Library)
|
||||
AC_CACHE_VAL(program_invocation_name_worked,
|
||||
[AC_TRY_RUN([
|
||||
#include <string.h>
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
extern char *program_invocation_name;
|
||||
return (strcmp (program_invocation_name, argv[0]));
|
||||
}
|
||||
], program_invocation_name_worked=yes, program_invocation_name_worked=no, program_invocation_name_worked=no)])
|
||||
if test $program_invocation_name_worked = yes; then
|
||||
AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Defines HAVE_PROC_FS if the kernel supports the /proc filesystem.
|
||||
# Needed by NSProcessInfo.m
|
||||
#--------------------------------------------------------------------
|
||||
AC_MSG_CHECKING(kernel support for /proc filesystem)
|
||||
if (grep proc /etc/fstab >/dev/null 2>/dev/null); then
|
||||
sys_proc_fs=yes;
|
||||
AC_DEFINE(HAVE_PROC_FS)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
sys_proc_fs=no;
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Tools for making a DLL.
|
||||
#--------------------------------------------------------------------
|
||||
|
@ -558,6 +637,25 @@ case "${target}" in
|
|||
;;
|
||||
esac
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Include redefinition of main () only if needed
|
||||
#--------------------------------------------------------------------
|
||||
echo "handling fake-main definition"
|
||||
AC_ARG_ENABLE(fake-main,
|
||||
[ --enable-fake-main Force use of redefine of the main function],,
|
||||
enable_fake_main=no)
|
||||
if test "$enable_fake_main" = "yes"; then
|
||||
GS_FAKE_MAIN=1
|
||||
else
|
||||
if test $objc_load_method_worked = yes -a $sys_proc_fs = yes; then
|
||||
GS_FAKE_MAIN=0
|
||||
else
|
||||
GS_FAKE_MAIN=1
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(GS_FAKE_MAIN)
|
||||
|
||||
|
||||
AC_SUBST(whole_archive)
|
||||
AC_SUBST(no_whole_archive)
|
||||
|
||||
|
|
Loading…
Reference in a new issue