use aros_target_toolchain to determine if we need to use the wrappers
[AROS.git] / compiler / posixc / fopen.c
blob3f40579c5e6a0b624a592eda6567f04a8cc7fd59
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fopen().
6 */
8 #include <fcntl.h>
9 #include "__stdio.h"
12 /*****************************************************************************
14 NAME */
15 #include <stdio.h>
17 FILE * fopen (
19 /* SYNOPSIS */
20 const char * pathname,
21 const char * mode)
23 /* FUNCTION
24 Opens a file with the specified name in the specified mode.
26 INPUTS
27 pathname - Path and filename of the file you want to open.
28 mode - How to open the file:
30 r: Open for reading. The stream is positioned at the
31 beginning of the file.
33 r+: Open for reading and writing. The stream is positioned
34 at the beginning of the file.
36 w: Open for writing. If the file doesn't exist, then
37 it is created. If it does already exist, then
38 it is truncated. The stream is positioned at the
39 beginning of the file.
41 w+: Open for reading and writing. If the file doesn't
42 exist, then it is created. If it does already
43 exist, then it is truncated. The stream is
44 positioned at the beginning of the file.
46 a: Open for writing. If the file doesn't exist, then
47 it is created. The stream is positioned at the
48 end of the file.
50 a+: Open for reading and writing. If the file doesn't
51 exist, then it is created. The stream is positioned
52 at the end of the file.
54 b: Open in binary more. This has no effect and is ignored.
56 RESULT
57 A pointer to a FILE handle or NULL in case of an error. When NULL
58 is returned, then errno is set to indicate the error.
60 NOTES
61 This function must not be used in a shared library or
62 in a threaded application.
64 EXAMPLE
66 BUGS
67 Most modes are not supported right now.
69 SEE ALSO
70 fclose(), fread(), fwrite(), open(), fgets(), fgetc(),
71 fputs(), fputc(), getc(), putc()
73 INTERNALS
75 ******************************************************************************/
77 int fd;
78 int openmode = __smode2oflags(mode);
80 if (openmode != -1)
82 fd = open(pathname, openmode, 644);
83 if (fd == -1)
84 return NULL;
86 return fdopen(fd, NULL);
88 else
90 return NULL;
92 } /* fopen */