mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Addeed operating system methods
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13399 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
664b093731
commit
e85b986e37
3 changed files with 161 additions and 36 deletions
|
@ -7,6 +7,10 @@
|
||||||
* Source/UnixFileHandle.m: Permit accept/connect on descriptors
|
* Source/UnixFileHandle.m: Permit accept/connect on descriptors
|
||||||
by default.
|
by default.
|
||||||
* Source/WindowsFileHandle.m: ditto
|
* Source/WindowsFileHandle.m: ditto
|
||||||
|
* Headers/Foundation/NSProcessInfo.h: Added MacOS-X operating system
|
||||||
|
methods and enum
|
||||||
|
* Source/NSProcessInfo.m: Added operating system methods and documented
|
||||||
|
all methods for autogsdoc.
|
||||||
|
|
||||||
2002-04-07 Richard Frith-Macdonald <rfm@gnu.org>
|
2002-04-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -34,22 +34,42 @@
|
||||||
@class NSData;
|
@class NSData;
|
||||||
@class NSMutableSet;
|
@class NSMutableSet;
|
||||||
|
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
/*
|
||||||
|
* Constants returned by -operatingSystem
|
||||||
|
* NB. The presence of a constant in this list does *NOT* imply that
|
||||||
|
* the named operating system is supported. Some values are provided
|
||||||
|
* for MacOS-X compatibility only.
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
NSWindowsNTOperatingSystem = 1,
|
||||||
|
NSWindows95OperatingSystem,
|
||||||
|
NSSolarisOperatingSystem,
|
||||||
|
NSHPUXOperatingSystem,
|
||||||
|
NSMACHOperatingSystem,
|
||||||
|
NSSunOSOperatingSystem,
|
||||||
|
NSOSF1OperatingSystem,
|
||||||
|
NSGNULinuxOperatingSystem = 100,
|
||||||
|
NSBSDOperatingSystem
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@interface NSProcessInfo: NSObject
|
@interface NSProcessInfo: NSObject
|
||||||
|
|
||||||
/* Getting an NSProcessInfo Object */
|
|
||||||
+ (NSProcessInfo*) processInfo;
|
+ (NSProcessInfo*) processInfo;
|
||||||
|
|
||||||
/* Returning Process Information */
|
|
||||||
- (NSArray*) arguments;
|
- (NSArray*) arguments;
|
||||||
- (NSDictionary*) environment;
|
- (NSDictionary*) environment;
|
||||||
|
- (NSString*) globallyUniqueString;
|
||||||
- (NSString*) hostName;
|
- (NSString*) hostName;
|
||||||
#ifndef STRICT_OPENSTEP
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (unsigned int) operatingSystem;
|
||||||
|
- (NSString*) operatingSystemName;
|
||||||
- (int) processIdentifier;
|
- (int) processIdentifier;
|
||||||
#endif
|
#endif
|
||||||
- (NSString*) processName;
|
- (NSString*) processName;
|
||||||
- (NSString*) globallyUniqueString;
|
|
||||||
|
|
||||||
/* Specifying a Process Name */
|
|
||||||
- (void) setProcessName: (NSString*)newName;
|
- (void) setProcessName: (NSString*)newName;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
#include <GSConfig.h>
|
#include <GSConfig.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
|
#include <Foundation/NSBundle.h>
|
||||||
#include <Foundation/NSSet.h>
|
#include <Foundation/NSSet.h>
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
#include <Foundation/NSDate.h>
|
#include <Foundation/NSDate.h>
|
||||||
|
@ -535,9 +536,9 @@ int main(int argc, char *argv[], char *env[])
|
||||||
|
|
||||||
#endif /* HAS_LOAD_METHOD && HAS_PROCFS */
|
#endif /* HAS_LOAD_METHOD && HAS_PROCFS */
|
||||||
|
|
||||||
/*************************************************************************
|
/**
|
||||||
*** Getting an NSProcessInfo Object
|
* Returns the shared NSProcessInfo object for the current process.
|
||||||
*************************************************************************/
|
*/
|
||||||
+ (NSProcessInfo *) processInfo
|
+ (NSProcessInfo *) processInfo
|
||||||
{
|
{
|
||||||
// Check if the main() function was successfully called
|
// Check if the main() function was successfully called
|
||||||
|
@ -556,45 +557,31 @@ int main(int argc, char *argv[], char *env[])
|
||||||
return _gnu_sharedProcessInfoObject;
|
return _gnu_sharedProcessInfoObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/**
|
||||||
*** Returning Process Information
|
* Returns an array containing the arguments supplied to start this
|
||||||
*************************************************************************/
|
* process. NB. In GNUstep, any arguments of the form --GNU-Debug=...
|
||||||
|
* are <em>not</em> included in this array ... they are part of the
|
||||||
|
* debug mechanism, and are hidden so that setting debug variables
|
||||||
|
* will not effect the normal operation of the program.
|
||||||
|
*/
|
||||||
- (NSArray *) arguments
|
- (NSArray *) arguments
|
||||||
{
|
{
|
||||||
return _gnu_arguments;
|
return _gnu_arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a dictionary giving the environment variables which were
|
||||||
|
* provided for the process to use.
|
||||||
|
*/
|
||||||
- (NSDictionary *) environment
|
- (NSDictionary *) environment
|
||||||
{
|
{
|
||||||
return _gnu_environment;
|
return _gnu_environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) hostName
|
/**
|
||||||
{
|
* Returns a string which may be used as a unique identifier for the
|
||||||
if (!_gnu_hostName)
|
* current process.
|
||||||
{
|
*/
|
||||||
_gnu_hostName = [[[NSHost currentHost] name] copy];
|
|
||||||
}
|
|
||||||
return _gnu_hostName;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) processIdentifier
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
|
||||||
pid = (int)GetCurrentProcessId();
|
|
||||||
#else
|
|
||||||
pid = (int)getpid();
|
|
||||||
#endif
|
|
||||||
return pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *) processName
|
|
||||||
{
|
|
||||||
return _gnu_processName;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *) globallyUniqueString
|
- (NSString *) globallyUniqueString
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
@ -612,6 +599,120 @@ int main(int argc, char *argv[], char *env[])
|
||||||
[self hostName], pid, [NSDate date]];
|
[self hostName], pid, [NSDate date]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the machine on which this process is running.
|
||||||
|
*/
|
||||||
|
- (NSString *) hostName
|
||||||
|
{
|
||||||
|
if (!_gnu_hostName)
|
||||||
|
{
|
||||||
|
_gnu_hostName = [[[NSHost currentHost] name] copy];
|
||||||
|
}
|
||||||
|
return _gnu_hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a number representing the operating system type.<br />
|
||||||
|
* The known types are listed in the header file, but not all of the
|
||||||
|
* listed types are actually implemented ... some are present for
|
||||||
|
* MacOS-X compatibility only.<br />
|
||||||
|
* <list>
|
||||||
|
* <item>NSWindowsNTOperatingSystem - used for windows NT, 2000, XP</item>
|
||||||
|
* <item>NSWindows95OperatingSystem - probably never to be implemented</item>
|
||||||
|
* <item>NSSolarisOperatingSystem - not yet recognised</item>
|
||||||
|
* <item>NSHPUXOperatingSystem - not implemented</item>
|
||||||
|
* <item>NSMACHOperatingSystem - perhaps the HURD in future?</item>
|
||||||
|
* <item>NSSunOSOperatingSystem - probably never to be implemented</item>
|
||||||
|
* <item>NSOSF1OperatingSystem - probably never to be implemented</item>
|
||||||
|
* <item>NSGNULinuxOperatingSystem - the GNUstep 'standard'</item>
|
||||||
|
* <item>NSBSDOperatingSystem - BSD derived operating systems</item>
|
||||||
|
* </list>
|
||||||
|
*/
|
||||||
|
- (unsigned int) operatingSystem
|
||||||
|
{
|
||||||
|
static unsigned int os = 0;
|
||||||
|
|
||||||
|
if (os == 0)
|
||||||
|
{
|
||||||
|
NSString *n = [self operatingSystemName];
|
||||||
|
|
||||||
|
if ([n isEqualToString: @"linux-gnu"] == YES)
|
||||||
|
{
|
||||||
|
os = NSGNULinuxOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n isEqualToString: @"mingw"] == YES)
|
||||||
|
{
|
||||||
|
os = NSWindowsNTOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n isEqualToString: @"cygwin"] == YES)
|
||||||
|
{
|
||||||
|
os = NSWindowsNTOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n hasPrefix: @"bsd"] == YES)
|
||||||
|
{
|
||||||
|
os = NSBSDOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n hasPrefix: @"freebsd"] == YES)
|
||||||
|
{
|
||||||
|
os = NSBSDOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n hasPrefix: @"netbsd"] == YES)
|
||||||
|
{
|
||||||
|
os = NSBSDOperatingSystem;
|
||||||
|
}
|
||||||
|
else if ([n hasPrefix: @"openbsd"] == YES)
|
||||||
|
{
|
||||||
|
os = NSBSDOperatingSystem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Unable to determine O/S ... assuming GNU/Linux");
|
||||||
|
os = NSGNULinuxOperatingSystem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the operating system in use.
|
||||||
|
*/
|
||||||
|
- (NSString*) operatingSystemName
|
||||||
|
{
|
||||||
|
static NSString *os = nil;
|
||||||
|
|
||||||
|
if (os == nil)
|
||||||
|
{
|
||||||
|
os = [[NSBundle _gnustep_target_os] copy];
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the process identifier number which identifies this process
|
||||||
|
* on this machine.
|
||||||
|
*/
|
||||||
|
- (int) processIdentifier
|
||||||
|
{
|
||||||
|
int pid;
|
||||||
|
|
||||||
|
#if defined(__MINGW__)
|
||||||
|
pid = (int)GetCurrentProcessId();
|
||||||
|
#else
|
||||||
|
pid = (int)getpid();
|
||||||
|
#endif
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the process name for this process. This may have been set using
|
||||||
|
* the -setProcessName: method, or may be the default process name (the
|
||||||
|
* file name of the binary being executed).
|
||||||
|
*/
|
||||||
|
- (NSString *) processName
|
||||||
|
{
|
||||||
|
return _gnu_processName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the name of the current process to newName.
|
* Change the name of the current process to newName.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue