📄 osutils.cxx
字号:
/*
* osutils.cxx
*
* Operating System utilities.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Log: osutils.cxx,v $
* Revision 1.172 2001/11/30 04:19:26 robertj
* Fixed correct setting of option bits in PTrace::Initialise()
* Added date and time to first message in PTrace::Initialise()
*
* Revision 1.171 2001/11/14 06:06:26 robertj
* Added functions on PTimer to get reset value and restart timer to it.
*
* Revision 1.170 2001/10/15 00:48:02 robertj
* Fixed warning on later MSVC compilers.
*
* Revision 1.169 2001/09/03 08:08:31 robertj
* Added tab so get extra "column" in trace output.
*
* Revision 1.168 2001/08/20 06:56:47 robertj
* Fixed memory leak report which isn't a memory leak.
*
* Revision 1.167 2001/07/20 04:14:19 robertj
* Removed GNU warning.
*
* Revision 1.166 2001/05/29 02:50:56 robertj
* Fixed GNU compatibility
*
* Revision 1.165 2001/05/29 00:49:18 robertj
* Added ability to put in a printf %x in thread name to get thread object
* address into user settable thread name.
*
* Revision 1.164 2001/05/03 06:26:22 robertj
* Fixed strange problem that occassionally crashes on exit. Mutex cannot be
* destroyed before program exit.
*
* Revision 1.163 2001/04/27 01:05:26 yurik
* Exit crash removal try
*
* Revision 1.162 2001/04/15 03:39:24 yurik
* Removed shutdown flag. Use IsTerminated() instead
*
* Revision 1.161 2001/04/14 04:53:01 yurik
* Got rid of init_seg pragma and added process shutdown flag
*
* Revision 1.160 2001/03/23 20:28:54 yurik
* Got rid of pragma warning for WinCE port
*
* Revision 1.159 2001/03/09 05:50:48 robertj
* Added ability to set default PConfig file or path to find it.
*
* Revision 1.158 2001/03/02 22:29:08 yurik
* New pragma for WinCE related port which enables (de)construction of library static objects be before applications'
* Eliminated nasty access violation stemmed from using static PMutex object in PTrace code. Thanks to Yuriy Gorvitovskiy.
*
* Revision 1.157 2001/02/22 22:31:44 robertj
* Changed PProcess version display to show build number even if zero.
*
* Revision 1.156 2001/02/22 08:16:42 robertj
* Added standard trace file setup subroutine.
*
* Revision 1.155 2001/02/19 03:44:20 robertj
* Changed "pl" in version number string to a simple ".", Now like 1.1.19
*
* Revision 1.154 2001/01/28 00:53:00 yurik
* WinCE port-related - streams refined
*
* Revision 1.153 2001/01/25 07:14:39 robertj
* Fixed spurios memory leak message. Usual static global problem.
*
* Revision 1.152 2001/01/24 18:27:44 yurik
* Added if !#defined WinCE when asm code used. Asm can't be used under WCE
*
* Revision 1.151 2001/01/02 07:47:44 robertj
* Fixed very narrow race condition in timers (destroyed while in OnTimeout()).
*
* Revision 1.150 2000/12/21 12:37:03 craigs
* Fixed deadlock problem with creating PTimer inside OnTimeout
*
* Revision 1.149 2000/11/28 12:55:37 robertj
* Added static function to create a new thread class and automatically
* run a function on another class in the context of that thread.
*
* Revision 1.148 2000/10/20 05:31:32 robertj
* Added function to change auto delete flag on a thread.
*
* Revision 1.147 2000/08/31 01:12:36 robertj
* Fixed problem with no new lines in trace output to stderr.
*
* Revision 1.146 2000/08/30 05:56:07 robertj
* Fixed free running timers broken by previous change.
*
* Revision 1.145 2000/08/30 03:17:00 robertj
* Improved multithreaded reliability of the timers under stress.
*
* Revision 1.144 2000/06/26 11:17:20 robertj
* Nucleus++ port (incomplete).
*
* Revision 1.143 2000/06/26 09:27:16 robertj
* Added ability to get at the PTraceStream without timestamps etc, use UINT_MAX trace level.
*
* Revision 1.142 2000/06/02 01:38:07 craigs
* Fixed typos
*
* Revision 1.141 2000/06/02 01:35:56 craigs
* Added more guards for NULL PStrings in PConfigArg handling
*
* Revision 1.140 2000/05/25 14:45:07 robertj
* Fixed detection of real argument over configured value.
*
* Revision 1.139 2000/05/25 13:47:51 robertj
* Fixed warning with GNU.
*
* Revision 1.138 2000/05/25 11:05:55 robertj
* Added PConfigArgs class so can save program arguments to config files.
*
* Revision 1.137 2000/05/05 10:08:29 robertj
* Fixed some GNU compiler warnings
*
* Revision 1.136 2000/04/28 06:58:50 robertj
* Fixed bug introduced when added Ashley Untts fix, forgot to take out old code!
*
* Revision 1.135 2000/04/27 04:19:27 robertj
* Fixed bug in restarting free running timers, thanks Ashley Unitt.
*
* Revision 1.134 2000/04/03 18:42:40 robertj
* Added function to determine if PProcess instance is initialised.
*
* Revision 1.133 2000/03/29 20:12:00 robertj
* Fixed GNU C++ warning
*
* Revision 1.132 2000/03/29 01:55:52 robertj
* Fixed infinite recursion on PProcess::Current() = NULL assertion.
*
* Revision 1.131 2000/03/02 05:43:12 robertj
* Fixed handling of NULL pointer on current thread in PTRACE output.
*
* Revision 1.130 2000/02/29 12:26:14 robertj
* Added named threads to tracing, thanks to Dave Harvey
*
* Revision 1.129 2000/02/17 11:34:28 robertj
* Changed PTRACE output to help line up text after filename output.
*
* Revision 1.128 2000/01/06 14:09:42 robertj
* Fixed problems with starting up timers,losing up to 10 seconds
*
* Revision 1.127 1999/10/19 09:21:30 robertj
* Added functions to get current trace options and level.
*
* Revision 1.126 1999/10/14 08:08:27 robertj
* Fixed problem, assuring millisecond accuracy in timestamp of trace output.
*
* Revision 1.125 1999/09/14 13:02:52 robertj
* Fixed PTRACE to PSYSTEMLOG conversion problem under Unix.
*
* Revision 1.124 1999/09/13 13:15:07 robertj
* Changed PTRACE so will output to system log in PServiceProcess applications.
*
* Revision 1.123 1999/08/22 12:54:35 robertj
* Fixed warnings about inlines on older GNU compiler
*
* Revision 1.122 1999/06/23 14:19:46 robertj
* Fixed core dump problem with SIGINT/SIGTERM terminating process.
*
* Revision 1.121 1999/06/14 07:59:38 robertj
* Enhanced tracing again to add options to trace output (timestamps etc).
*
* Revision 1.120 1999/04/26 08:06:51 robertj
* Added missing function in cooperative threading.
*
* Revision 1.119 1999/03/01 13:51:30 craigs
* Fixed ugly little bug in the cooperative multithreading that meant that threads blocked
* on timers didn't always get rescheduled.
*
* Revision 1.118 1999/02/23 10:13:31 robertj
* Changed trace to only diplay filename and not whole path.
*
* Revision 1.117 1999/02/23 07:11:27 robertj
* Improved trace facility adding trace levels and #define to remove all trace code.
*
* Revision 1.116 1998/11/30 12:45:54 robertj
* Fissioned into pchannel.cxx and pconfig.cxx
*
* Revision 1.115 1998/11/24 01:17:33 robertj
* Type discrepency between declaration and definition for PFile::SetPosition
*
* Revision 1.114 1998/11/06 02:37:53 robertj
* Fixed the fix for semaphore timeout race condition.
*
* Revision 1.113 1998/11/03 10:52:19 robertj
* Fixed bug in semaphores with timeout saying timed out when really signalled.
*
* Revision 1.112 1998/11/03 03:44:05 robertj
* Fixed missng strings on multiple parameters of same letter.
*
* Revision 1.111 1998/11/02 10:13:01 robertj
* Removed GNU warning.
*
* Revision 1.110 1998/11/01 04:56:53 robertj
* Added BOOl return value to Parse() to indicate there are parameters available.
*
* Revision 1.109 1998/10/31 14:02:20 robertj
* Removed StartImmediate capability as causes race condition in preemptive version.
*
* Revision 1.108 1998/10/31 12:47:10 robertj
* Added conditional mutex and read/write mutex thread synchronisation objects.
*
* Revision 1.107 1998/10/30 12:24:15 robertj
* Added ability to get all key values as a dictionary.
* Fixed warnings in GNU C.
*
* Revision 1.106 1998/10/30 11:22:15 robertj
* Added constructors that take strings as well as const char *'s.
*
* Revision 1.105 1998/10/30 05:25:09 robertj
* Allow user to shift past some arguments before parsing for the first time.
*
* Revision 1.104 1998/10/29 05:35:17 robertj
* Fixed porblem with GetCount() == 0 if do not call Parse() function.
*
* Revision 1.103 1998/10/28 03:26:43 robertj
* Added multi character arguments (-abc style) and options precede parameters mode.
*
* Revision 1.102 1998/10/28 00:59:49 robertj
* New improved argument parsing.
*
* Revision 1.101 1998/10/19 00:19:59 robertj
* Moved error and trace stream functions to common code.
*
* Revision 1.100 1998/10/18 14:28:45 robertj
* Renamed argv/argc to eliminate accidental usage.
*
* Revision 1.99 1998/10/13 14:06:28 robertj
* Complete rewrite of memory leak detection code.
*
* Revision 1.98 1998/09/24 07:23:54 robertj
* Moved structured fiel into separate module so don't need silly implementation file for GNU C.
*
* Revision 1.97 1998/09/23 06:22:24 robertj
* Added open source copyright license.
*
* Revision 1.96 1998/06/13 15:11:56 robertj
* Added stack check in Yield().
* Added immediate schedule of semaphore timeout thread.
*
* Revision 1.95 1998/05/30 13:28:18 robertj
* Changed memory check code so global statics are not included in leak check.
* Fixed deadlock in cooperative threading.
* Added PSyncPointAck class.
*
* Revision 1.94 1998/05/25 09:05:56 robertj
* Fixed close of channels on destruction.
*
* Revision 1.93 1998/04/07 13:33:33 robertj
* Changed startup code to support PApplication class.
*
* Revision 1.92 1998/03/29 06:16:45 robertj
* Rearranged initialisation sequence so PProcess descendent constructors can do "things".
*
* Revision 1.91 1998/03/20 03:18:17 robertj
* Added special classes for specific sepahores, PMutex and PSyncPoint.
*
* Revision 1.90 1998/02/05 13:33:12 robertj
* Fixed close of non-autodelete PIndirectChannels
*
* Revision 1.89 1998/02/03 06:19:55 robertj
* Added new function to read a block with minimum number of bytes.
*
* Revision 1.88 1998/01/26 00:47:13 robertj
* Added functions to get/set 64bit integers from a PConfig.
*
* Revision 1.87 1998/01/04 07:22:16 robertj
* Fixed bug in thread deletion not removing it from active thread list.
*
* Revision 1.86 1997/10/10 10:41:22 robertj
* Fixed problem with cooperative threading and Sleep() function returning immediately.
*
* Revision 1.85 1997/08/28 12:49:00 robertj
* Fixed possible assert on exit of application.
*
* Revision 1.84 1997/07/08 13:08:12 robertj
* DLL support.
*
* Revision 1.83 1997/04/27 05:50:15 robertj
* DLL support.
*
* Revision 1.82 1997/02/09 04:05:56 robertj
* Changed PProcess::Current() from pointer to reference.
*
* Revision 1.81 1997/02/05 11:51:42 robertj
* Changed current process function to return reference and validate objects descendancy.
*
* Revision 1.80 1996/12/21 05:54:38 robertj
* Fixed possible deadlock in timers.
*
* Revision 1.79 1996/12/05 11:44:22 craigs
* Made indirect close from different thread less likely to have
* race condition
*
* Revision 1.78 1996/11/30 12:08:42 robertj
* Removed extraneous compiler warning.
*
* Revision 1.77 1996/11/10 21:05:43 robertj
* Fixed bug of missing flush in close of indirect channel.
*
* Revision 1.76 1996/10/08 13:07:07 robertj
* Fixed bug in indirect channel being reopened double deleting subchannel.
*
* Revision 1.75 1996/09/14 13:09:37 robertj
* Major upgrade:
* rearranged sockets to help support IPX.
* added indirect channel class and moved all protocols to descend from it,
* separating the protocol from the low level byte transport.
*
* Revision 1.74 1996/08/11 06:53:04 robertj
* Fixed bug in Sleep() function (nonpreemptive version).
*
* Revision 1.73 1996/07/27 04:12:09 robertj
* Fixed bug in timer thread going into busy loop instead of blocking.
*
* Revision 1.72 1996/07/15 10:36:12 robertj
* Fixed bug in timer on startup, getting LARGE times timing out prematurely.
*
* Revision 1.71 1996/06/28 13:22:43 robertj
* Rewrite of timers to make OnTimeout more thread safe.
*
* Revision 1.70 1996/06/13 13:31:05 robertj
* Rewrite of auto-delete threads, fixes Windows95 total crash.
*
* Revision 1.69 1996/06/03 10:01:31 robertj
* Fixed GNU support bug fix for the fix.
*
* Revision 1.68 1996/06/01 05:03:37 robertj
* Fixed GNU compiler having difficulty with PTimeInterval *this.
*
* Revision 1.67 1996/05/26 03:46:56 robertj
* Compatibility to GNU 2.7.x
*
* Revision 1.66 1996/05/23 23:05:07 robertj
* Fixed process filename on MSOS platforms.
*
* Revision 1.65 1996/05/23 09:56:57 robertj
* Added mutex to timer list.
*
* Revision 1.64 1996/05/18 09:18:33 robertj
* Added mutex to timer list.
*
* Revision 1.63 1996/05/09 12:19:00 robertj
* Resolved C++ problems with 64 bit PTimeInterval for Mac platform.
*
* Revision 1.62 1996/04/14 02:53:34 robertj
* Split serial and pipe channel into separate compilation units for Linux executable size reduction.
*
* Revision 1.61 1996/04/10 12:51:29 robertj
* Fixed startup race condtion in timer thread.
*
* Revision 1.60 1996/04/09 03:32:58 robertj
* Fixed bug in config GetTime() cannot use PTime(0) in western hemisphere.
*
* Revision 1.59 1996/04/02 11:29:19 robertj
* Eliminated printing of patch level in version when there isn't one.
*
* Revision 1.58 1996/03/31 09:06:14 robertj
* Fixed WriteString() so works with sockets.
* Changed PPipeSokcet argument string list to array.
*
* Revision 1.57 1996/03/16 04:51:50 robertj
* Fixed yet another bug in the scheduler.
*
* Revision 1.56 1996/03/12 11:30:50 robertj
* Moved PProcess destructor to platform dependent code.
*
* Revision 1.55 1996/03/05 14:05:51 robertj
* Fixed some more bugs in scheduling.
*
* Revision 1.54 1996/03/04 12:22:46 robertj
* Fixed threading for unix stack check and loop list start point.
*
* Revision 1.53 1996/03/03 07:39:51 robertj
* Fixed bug in thread scheduler for correct termination of "current" thread.
*
* Revision 1.52 1996/03/02 03:24:48 robertj
* Changed timer thread to update timers periodically, this allows timers to be
* views dynamically by other threads.
* Added automatic deletion of thread object instances on thread completion.
*
* Revision 1.51 1996/02/25 11:15:27 robertj
* Added platform dependent Construct function to PProcess.
*
* Revision 1.50 1996/02/25 03:09:46 robertj
* Added consts to all GetXxxx functions in PConfig.
*
* Revision 1.49 1996/02/15 14:44:09 robertj
* Used string constructor for PTime, more "efficient".
*
* Revision 1.48 1996/02/13 12:59:30 robertj
* Changed GetTimeZone() so can specify standard/daylight time.
* Split PTime into separate module after major change to ReadFrom().
*
* Revision 1.47 1996/02/08 12:26:55 robertj
* Changed time for full support of time zones.
*
* Revision 1.46 1996/02/03 11:06:49 robertj
* Added string constructor for times, parses date/time from string.
*
* Revision 1.45 1996/01/28 14:09:39 robertj
* Fixed bug in time reading function for dates before 1980.
* Fixed bug in time reading, was out by one month.
* Added time functions to PConfig.
*
* Revision 1.44 1996/01/28 02:52:04 robertj
* Added assert into all Compare functions to assure comparison between compatible objects.
*
* Revision 1.43 1996/01/23 13:16:30 robertj
* Mac Metrowerks compiler support.
* Fixed timers so background thread not created if a windows app.
*
* Revision 1.42 1996/01/03 23:15:39 robertj
* Fixed some PTime bugs.
*
* Revision 1.41 1996/01/03 11:09:35 robertj
* Added Universal Time and Time Zones to PTime class.
*
* Revision 1.39 1995/12/23 03:40:40 robertj
* Changed version number system
*
* Revision 1.38 1995/12/10 11:41:12 robertj
* Added extra user information to processes and applications.
* Implemented timer support in text only applications with platform threads.
* Fixed bug in non-platform threads and semaphore timeouts.
*
* Revision 1.37 1995/11/21 11:50:57 robertj
* Added timeout on semaphore wait.
*
* Revision 1.36 1995/11/09 12:22:58 robertj
* Fixed bug in stream when reading an FF (get EOF).
*
* Revision 1.35 1995/07/31 12:09:25 robertj
* Added semaphore class.
* Removed PContainer from PChannel ancestor.
*
* Revision 1.34 1995/06/04 12:41:08 robertj
* Fixed bug in accessing argument strings with no argument.
*
* Revision 1.33 1995/04/25 11:30:06 robertj
* Fixed Borland compiler warnings.
*
* Revision 1.32 1995/04/22 00:51:00 robertj
* Changed file path strings to use PFilePath object.
* Changed semantics of Rename().
*
* Revision 1.31 1995/04/02 09:27:31 robertj
* Added "balloon" help.
*
* Revision 1.30 1995/04/01 08:30:58 robertj
* Fixed bug in timeout code of timers.
*
* Revision 1.29 1995/01/27 11:15:17 robertj
* Removed enum to int warning from GCC.
*
* Revision 1.28 1995/01/18 09:02:43 robertj
* Added notifier to timer.
*
* Revision 1.27 1995/01/15 04:57:15 robertj
* Implemented PTime::ReadFrom.
* Fixed flush of iostream at end of file.
*
* Revision 1.26 1995/01/11 09:45:14 robertj
* Documentation and normalisation.
*
* Revision 1.25 1995/01/10 11:44:15 robertj
* Removed PString parameter in stdarg function for GNU C++ compatibility.
*
* Revision 1.24 1995/01/09 12:31:51 robertj
* Removed unnecesary return value from I/O functions.
*
* Revision 1.23 1994/12/12 10:09:24 robertj
* Fixed flotain point configuration variable format.
*
* Revision 1.22 1994/11/28 12:38:23 robertj
* Async write functions should have const pointer.
*
* Revision 1.21 1994/10/30 11:36:58 robertj
* Fixed missing space in tine format string.
*
* Revision 1.20 1994/10/23 03:46:41 robertj
* Shortened OS error assert.
*
* Revision 1.19 1994/09/25 10:51:04 robertj
* Fixed error conversion code to use common function.
* Added pipe channel.
*
* Revision 1.18 1994/08/21 23:43:02 robertj
* Moved meta-string transmitter from PModem to PChannel.
* Added SuspendBlock state to cooperative multi-threading to fix logic fault.
* Added "force" option to Remove/Rename etc to override write protection.
* Added common entry point to convert OS error to PChannel error.
*
* Revision 1.17 1994/08/04 12:57:10 robertj
* Changed CheckBlock() to better name.
* Moved timer porcessing so is done at every Yield().
*
* Revision 1.16 1994/08/01 03:39:42 robertj
* Fixed temporary variable problem with GNU C++
*
* Revision 1.15 1994/07/27 05:58:07 robertj
* Synchronisation.
*
* Revision 1.14 1994/07/25 03:39:22 robertj
* Fixed problems with C++ temporary variables.
*
* Revision 1.13 1994/07/21 12:33:49 robertj
* Moved cooperative threads to common.
*
* Revision 1.12 1994/07/17 10:46:06 robertj
* Fixed timer bug.
* Moved handle from file to channel.
* Changed args to use container classes.
*
* Revision 1.11 1994/07/02 03:03:49 robertj
* Time interval and timer redesign.
*
* Revision 1.10 1994/06/25 11:55:15 robertj
* Unix version synchronisation.
*
* Revision 1.9 1994/04/20 12:17:44 robertj
* assert changes
*
* Revision 1.8 1994/04/01 14:05:06 robertj
* Text file streams
*
* Revision 1.7 1994/03/07 07:47:00 robertj
* Major upgrade
*
* Revision 1.6 1994/01/03 04:42:23 robertj
* Mass changes to common container classes and interactors etc etc etc.
*
* Revision 1.5 1993/12/31 06:53:02 robertj
* Made inlines optional for debugging purposes.
*
* Revision 1.4 1993/12/29 04:41:26 robertj
* Mac port.
*
* Revision 1.3 1993/11/20 17:26:28 robertj
* Removed separate osutil.h
*
* Revision 1.2 1993/08/31 03:38:02 robertj
* G++ needs explicit casts for char * / void * interchange.
*
* Revision 1.1 1993/08/27 18:17:47 robertj
* Initial revision
*
*/
#include <ptlib.h>
#include <ptlib/svcproc.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -