added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / loadseg.c
blob0aa8f1337383e97e7922a2a44579ea8333aa43c3
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: DOS function LoadSeg()
6 Lang: english
7 */
8 #ifdef __x86_64__
9 #define DEBUG 1
10 #else
11 #define DEBUG 0
12 #endif
14 #include <dos/dos.h>
15 #include <dos/dosextens.h>
16 #include <proto/dos.h>
17 #include <aros/debug.h>
18 #include "dos_intern.h"
20 /*****************************************************************************
22 NAME */
23 #include <proto/dos.h>
25 AROS_LH1(BPTR, LoadSeg,
27 /* SYNOPSIS */
28 AROS_LHA(CONST_STRPTR, name, D1),
30 /* LOCATION */
31 struct DosLibrary *, DOSBase, 25, Dos)
33 /* FUNCTION
34 Loads an executable file into memory. Each hunk of the loadfile
35 is loaded into its own memory section and a handle on all of them
36 is returned. The segments can be freed with UnLoadSeg().
38 INPUTS
39 name - NUL terminated name of the file.
41 RESULT
42 Handle to the loaded executable or NULL if the load failed.
43 IoErr() gives additional information in that case.
45 NOTES
46 This function is built on top of InternalLoadSeg()
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 UnLoadSeg()
55 INTERNALS
57 *****************************************************************************/
59 AROS_LIBFUNC_INIT
61 void (* FunctionArray[3])();
62 BPTR file, segs=0;
64 FunctionArray[0] = __AROS_GETVECADDR(DOSBase,7); /* Read() */
65 FunctionArray[1] = __AROS_GETVECADDR(SysBase,33); /* AllocMem() */
66 FunctionArray[2] = __AROS_GETVECADDR(SysBase,35); /* FreeMem() */
68 /* Open the file */
69 D(bug("[LoadSeg] Opening '%s'...\n", name));
70 file = Open (name, FMF_READ);
72 if (file)
74 D(bug("[LoadSeg] Loading '%s'...\n", name));
76 segs = InternalLoadSeg(file, NULL, (void *)FunctionArray, NULL);
78 if (segs)
79 SetIoErr(0);
80 else
81 bug("[LoadSeg] Failed to load '%s'\n", name);
82 Close(file);
84 D(else
85 bug("[LoadSeg] Failed to open '%s'\n", name));
88 /* And return */
89 return segs;
91 AROS_LIBFUNC_EXIT
92 } /* LoadSeg */