Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Appendix B - The RTLib.o and NuRTLib.o Libraries


A Preload Example

Listing B-1 shows a C program that installs a preload handler and uses it to print information about the segment.

To compile and link this example for the classic 68K far model environment, use the following MPW commands:

SC -model far example.c -o example.c.o -i {CIncludes}
ILink -model far -w -t MPST -c 'MPS ' -o example \xCB
   example.c.o \xCB
   {Libraries}RTLib.o \xCB
   {Libraries}Interface.o \xCB
   {Libraries}IntEnv.o \xCB
   {Libraries}MacRuntime.o \xCB
   {CLibraries}StdCLib.o \xCB
For the CFM-68K runtime environment, use the following commands:

SC -model cfmseg example.c -o example.c.o -i {CIncludes}
Ilink -model cfmseg -xm e -w -t MPST -c 'MPS ' -o example \xCB
   example.c.o \xCB
   {CFM68KLibraries}NuRTLib.o \xCB
   {CFM68KLibraries}NuMacRuntime.o \xCB
   {SharedLibraries}InterfaceLib \xCB
   {SharedLibraries}StdCLib
Listing B-1 A preload handler example

#include <stdio.h>
#include <types.h>
#include <RTLib.h>
#pragma segment One
one ()
{
   /* do something */
}
#pragma segment Main
pascal short preload_handler(RTState* state)
{
   
   /* print segment information */
   
   printf("segno= %d\n",state->fSegNo);
   printf("segtype= %.4s\n",&(state->fSegType));
   printf("segsize= %d\n",state->fSegSize);
   if (state->fSegInCore) printf("incore = yes\n");
   else printf("incore = no\n");
   return(0);
}
main ()
{
   RTPBparam_block, *p;
   OSErrerror;
   
   /* load printf segment so that the preload handler does not */
   /* invoke another call to _LoadSeg */
   
   printf("load printf segment\n");
   /* load the handler */
   
   p = &param_block;
   p->fOperation = kRTSetPreLoad;
   p->fRTParam.fSegLoadParam.fUserHdlr = (void*)&preload_handler;
   error = Runtime(p);
   
   /* load the segment */
   
   one();
}


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997