Patch for premain() function
"Ralf Habacker" <[email protected]>
| Newsgroups | gmane.comp.gnu.mingw.patches |
|---|---|
| Message-ID | <003401c26c81$ea8aef70$686607d5@BRAMSCHE> |
Hi all, this patches implements a user callable function before main() for general initialisation purpose without needs for patching the mingw runtime on user level. If someone like this, please submit it to the cvs tree and let me know. Currently I'm not subscribed to this list, so please send answers diretly to me. Thanks. Ralf Changelog Entry 2002-10-05 Ralf Habacker <[email protected]> * Makefile.in: Added new file premain.c * crt1.c (__mingw_CRTStartup): added call to premain() * premain.c: new file Patch Index: Makefile.in =================================================================== RCS file: /cvs/src/src/winsup/mingw/Makefile.in,v retrieving revision 1.29 diff -u -3 -p -B -u -b -B -r1.29 Makefile.in --- Makefile.in 5 Sep 2002 14:27:28 -0000 1.29 +++ Makefile.in 5 Oct 2002 13:09:02 -0000 @@ -150,7 +150,7 @@ FLAGS_TO_PASS:=\ CRT0S = crt1.o dllcrt1.o crt2.o dllcrt2.o CRT_noglob.o crtmt.o crtst.o \ CRT_fp8.o CRT_fp10.o MINGW_OBJS = CRTglob.o CRTfmode.o CRTinit.o dllmain.o gccmain.o \ - main.o crtst.o mthr_stub.o CRT_fp10.o + main.o premain.o crtst.o mthr_stub.o CRT_fp10.o MOLD_OBJS = ctype_old.o string_old.o LIBS = libcrtdll.a libmsvcrt.a libmsvcrt20.a libmsvcrt40.a libmingw32.a \ @@ -161,7 +161,7 @@ DLLS = $(THREAD_DLL_NAME) SRCDIST_FILES = CRT_noglob.c CRTfmode.c CRTglob.c CRTinit.c ChangeLog \ Makefile.in README TODO config.guess config.sub configure configure.in \ crt1.c crtdll.def crtmt.c crtst.c ctype_old.c dllcrt1.c dllmain.c \ -gccmain.c init.c install-sh jamfile main.c mkinstalldirs moldname-crtdll.def \ +gccmain.c init.c install-sh jamfile main.c premain.c mkinstalldirs moldname-crtdll.def \ moldname-msvcrt.def moldname.def moldname.def.in msvcrt.def msvcrt20.def \ msvcrt40.def mthr.c mthr_init.c mthr_stub.c readme.txt string_old.c \ CRT_fp8.c CRT_fp10.c test_headers.c @@ -411,6 +411,7 @@ dllcrt1.o: $(srcdir)/dllcrt1.c dllcrt2.o: $(srcdir)/dllcrt1.c dllmain.o: $(srcdir)/dllmain.c main.o: $(srcdir)/main.c +premain.o: $(srcdir)/premain.c oldnames.o: $(srcdir)/oldnames.c string_old.o: $(srcdir)/string_old.c CRT_fp8.o: $(srcdir)/CRT_fp8.c Index: crt1.c =================================================================== RCS file: /cvs/src/src/winsup/mingw/crt1.c,v retrieving revision 1.3 diff -u -3 -p -B -u -b -B -r1.3 crt1.c --- crt1.c 3 Oct 2002 00:49:20 -0000 1.3 +++ crt1.c 5 Oct 2002 13:09:02 -0000 @@ -43,6 +43,7 @@ #include "init.c" extern int main (int, char **, char **); +extern int premain (int, char **, char **); /* * Must have the correct app type for MSVCRT. @@ -185,6 +186,14 @@ __mingw_CRTStartup () * NOTE: DLLs don't do this because that would be rude! */ _mingw32_init_fmode (); + + /* + * Call the premain function. If the user does not supply one + * the one in the 'libmingw32.a' library will be linked in and is + * called as a dummy with no really functionality. See main.c + * for more details. + */ + premain (_argc, _argv, environ); /* * Call the main function. If the user does not supply one Index: dllcrt1.c =================================================================== RCS file: /cvs/src/src/winsup/mingw/dllcrt1.c,v retrieving revision 1.2 diff -u -3 -p -B -u -b -B -r1.2 dllcrt1.c --- dllcrt1.c 13 Jun 2002 10:20:41 -0000 1.2 +++ dllcrt1.c 5 Oct 2002 13:20:40 -0000 @@ -78,6 +78,13 @@ DllMainCRTStartup (HANDLE hDll, DWORD dw printf ("%s: DLL_PROCESS_ATTACH (%d)\n", __FUNCTION__); #endif + /* + * Call the premain function. If the user does not supply one + * the one in the 'libmingw32.a' library will be linked in and is + * called as a dummy with no really functionality. See main.c + * for more details. + */ + premain (0,NULL,NULL); #ifdef __GNUC__ /* From libgcc.a, __main calls global class constructors, =================================================================== --- /dev/null 2002-10-05 15:27:19.000000000 +0200 +++ premain.c 2002-10-05 15:27:17.000000000 +0200 @@ -0,0 +1,39 @@ +/* + * premain.c + * + * pre main called function for general initialisition purposes. + * This function is called by application or dll initialisaion + * immediatly before the main() call. + * + * This file is part of the Mingw32 package. + * + * Contributors: + * Created by Ralf Habacker<[email protected]> + * + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAMED. This includes but is not limited to warrenties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * $Revision: 1.5 $ + * $Author: cgf $ + * $Date: 2000/02/05 04:04:45 $ + * + */ + +/* note: + argc = 0 - call comes from dll initialisation + argc > 0 - call comes from applications initialisation. In this case + argv and argc contains true information +*/ +void +premain (int argc, char *argv[], char *environ[]) +{ + return; +} + ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf