define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / compiler / clib / freopen.c
blob72162add24191ce0268c97525b16e4b61756233d
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 "__open.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;