start service tasks separately in-case platforms need to perform additional set-up...
[AROS.git] / compiler / posixc / freopen.c
blobe165c9cb2f8b9d3d7aa16caa8a3ea104c0770bc4
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI function freopen().
6 */
8 #include <errno.h>
10 #include "__fdesc.h"
11 #include "__stdio.h"
13 /*****************************************************************************
15 NAME */
16 #include <stdio.h>
18 FILE *freopen (
20 /* SYNOPSIS */
21 const char *path,
22 const char *mode,
23 FILE *stream
26 /* FUNCTION
27 Opens the file whose name is the string pointed to by path and
28 associates the stream pointed to by stream with it.
30 INPUTS
31 path - the file to open
32 mode - The mode of the stream (same as with fopen()) must be com­
33 patible with the mode of the file descriptor. The file
34 position indicator of the new stream is set to that
35 belonging to fildes, and the error and end-of-file indica­
36 tors are cleared. Modes "w" or "w+" do not cause trunca­
37 tion of the file. The file descriptor is not dup'ed, and
38 will be closed when the stream created by fdopen is
39 closed.
40 stream - the stream to wich the file will be associated.
42 RESULT
43 NULL on error or stream.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 open(), fclose(), fileno()
54 INTERNALS
56 ******************************************************************************/
58 int fd, oflags;
60 if (!(path && mode && stream))
62 errno = EFAULT;
63 return NULL;
66 oflags = __smode2oflags(mode);
67 fd = __open(stream->fd, path, oflags, 644);
69 if (fd == -1)
70 return NULL;
72 stream->flags = __oflags2sflags(oflags);
74 return stream;