tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / init_usergroup.c
blob85f885ec4515496d128e3951583eb6f9a31bafe1
1 /* $Id$
3 * init_usergroup.c - SAS/C autoinitialization func. for usergroup.library
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <exec/types.h>
11 #include <exec/libraries.h>
13 #include <intuition/intuition.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <dos/dosextens.h>
18 #include <stdlib.h>
20 #include <libraries/usergroup.h>
21 #include <clib/usergroup_protos.h>
22 #include <pragmas/usergroup_pragmas.h>
24 struct Library *UserGroupBase = NULL;
26 #define USERGROUPVERSION 1 /* minimum version to use */
28 extern STRPTR _ProgramName; /* SAS startup module defines this :-) */
29 extern int errno; /* errno variable */
31 /****** net.lib/autoinit_usergroup.library ************************************
33 NAME
34 autoinit usergroup.library - SAS C Autoinitialization Functions
36 SYNOPSIS
37 error = _STI_200_openUserGroup()
39 LONG _STI_200_openUserGroup(void)
41 _STD_200_closeUserGroup()
43 void _STD_200_closeUserGroup(void)
45 FUNCTION
46 These functions open and close the usergroup.library at the startup
47 and exit of the program, respectively. For a program to use these
48 functions, it must be linked with netlib:usr.lib.
50 NOTES
51 _STI_200_openUserGroup() also checks that the system version is at
52 least 37. It puts up a requester if the usergroup.library is not
53 found or is too old version.
55 The autoinitialization and autotermination functions are features
56 specific to the SAS C6. However, these functions can be used with
57 other (ANSI) C compilers, too. Example follows:
59 \* at start of main() *\
61 atexit(_STD_200_closeUserGroup);
62 if (_STI_200_openUserGroup() != 0)
63 exit(20);
65 BUGS
66 The same autoinitialization won't work for both SAS C 6.3 and SAS C
67 6.50 or latter. Only way to terminate an initialization function is
68 by exit() call with SAS C 6.3 binary. If an autoinitialization
69 function is terminated by exit() call with SAS C 6.50 binary, the
70 autotermination functions won't be called. Due this braindamage
71 these compilers require separate net.lib libraries.
73 SEE ALSO
74 SAS/C 6 User's Guide p. 145 for details of autoinitialization and
75 autotermination functions.
77 ****************************************************************************** */
79 /* SAS C 6.50 kludge */
80 #if __VERSION__ > 6 || __REVISION__ >= 50
81 #define exit(x) return(x)
82 #endif
85 * Using __stdargs prevents creation of register arguments entry point.
86 * If both stack args and reg. args entry points are created, this
87 * function is called _twice_, which is not wanted.
89 LONG __stdargs
90 _STI_200_openUserGroup(void)
92 const UBYTE *errorStr = "Cannot open %s.";
94 struct Process *me = (struct Process *)FindTask(NULL);
96 * Check OS version
98 if ((*(struct Library **)4)->lib_Version < 37)
99 exit(20);
102 * Open bsdsocket.library
104 if (UserGroupBase = OpenLibrary(USERGROUPNAME, USERGROUPVERSION)) {
105 if (ug_SetupContextTags(_ProgramName,
106 UGT_INTRMASK, SIGBREAKB_CTRL_C,
107 UGT_ERRNOPTR(sizeof(errno)), &errno,
108 TAG_END)
109 == 0)
110 return 0;
111 errorStr = "Cannot initialize context in %s.";
115 * Post requester only if approved
117 if (me->pr_WindowPtr != (APTR) -1) {
118 struct Library *IntuitionBase;
119 if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
120 struct EasyStruct libraryES;
122 libraryES.es_StructSize = sizeof(libraryES);
123 libraryES.es_Flags = 0;
124 libraryES.es_Title = _ProgramName;
125 libraryES.es_TextFormat = (STRPTR)errorStr;
126 libraryES.es_GadgetFormat = "Exit %s";
128 EasyRequest(NULL, &libraryES, NULL,
129 USERGROUPNAME,
130 _ProgramName);
132 CloseLibrary(IntuitionBase);
136 exit(RETURN_FAIL);
139 void __stdargs
140 _STD_200_closeUserGroup(void)
142 if (UserGroupBase != NULL) {
143 CloseLibrary(UserGroupBase), UserGroupBase = NULL;