Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Newlib Library"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 36: Line 36:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Define to 1 to enable POSIX style path semantics which is useful when porting applications from UNIX.
 
Define to 1 to enable POSIX style path semantics which is useful when porting applications from UNIX.
  +
  +
== DOS File Handles ==
  +
  +
Sometimes the underlying DOS file handle may be required in some special circumstances. The '''_get_osfhandle()''' function is provided in the '''fcntl.h''' header file to access DOS file handles.
  +
  +
The following is an example program which demonstrates the feature.
  +
<syntaxhighlight>
  +
#include <proto/dos.h>
  +
#include <stdio.h>
  +
#include <fcntl.h>
  +
  +
int main()
  +
{
  +
printf("0x%08x 0x%08x 0x%08x\n",
  +
(unsigned int)IDOS->Input(),
  +
(unsigned int)IDOS->Output(),
  +
(unsigned int)IDOS->ErrorOutput());
  +
  +
printf("0x%08x 0x%08x 0x%08x\n",
  +
_get_osfhandle( fileno(stdin) ),
  +
_get_osfhandle( fileno(stdout) ),
  +
_get_osfhandle( fileno(stderr) ));
  +
  +
return 0;
  +
}
  +
</syntaxhighlight>
  +
  +
Note that this feature is available in newlib.library 53.20 and higher.

Revision as of 07:11, 8 March 2013

The built-in AmigaOS C library is a variant of the Newlib C standard library implementation. This section describes features of Newlib which are unique to AmigaOS.

Shared Interface Pointer

Newlib is a rather unique in that is uses a shared interface pointer name INewlib (struct Interface* type). This is only a concern when you are not using the standard C startup code and opening newlib.library directly. One consequence of using a shared interface pointer is that you must specify the NP_Child tag when using IDOS->CreateNewProc() if you child process is to share the parent process' newlib context information (e.g. stdin, stdout and stderr).

Startup Code

The standard C startup code provides information on whether your application was launched from Workbench or the Shell console. Your program always starts using the standard argc and argv parameters:

int main(int argc, char **argv)

If argc is equal to zero that means the application was started from the Workbench. In this case, the argv parameter is a pointer to a struct WBStartup.

If argc is non-zero then it means the application was started from the Shell console and the normal C startup rules apply.

Standard Interfaces

The following interfaces are handled by the C startup code and are guaranteed to be present when main() is called:

  • IExec
  • IDOS
  • IUtility

Options

extern const char *__stdiowin;

Define __stdiowin to control the default standard I/O window which will open automatically if your program needs it. The default is "CON:64/48/800/200/[CLI command name|Task name]/AUTO/CLOSE/WAIT".

extern int __unix_path_semantics;

Define to 1 to enable POSIX style path semantics which is useful when porting applications from UNIX.

DOS File Handles

Sometimes the underlying DOS file handle may be required in some special circumstances. The _get_osfhandle() function is provided in the fcntl.h header file to access DOS file handles.

The following is an example program which demonstrates the feature.

#include <proto/dos.h>
#include <stdio.h>
#include <fcntl.h>
 
int main()
{
	printf("0x%08x 0x%08x 0x%08x\n",
		(unsigned int)IDOS->Input(),
		(unsigned int)IDOS->Output(),
		(unsigned int)IDOS->ErrorOutput());
 
	printf("0x%08x 0x%08x 0x%08x\n",
		_get_osfhandle( fileno(stdin) ),
		_get_osfhandle( fileno(stdout) ),
		_get_osfhandle( fileno(stderr) ));
 
	return 0;
}

Note that this feature is available in newlib.library 53.20 and higher.