source: trunk/sys/dietlibc/freopen.c @ 240

Last change on this file since 240 was 1, checked in by alain, 8 years ago

First import

File size: 847 bytes
Line 
1#include "dietstdio.h"
2#include <unistd.h>
3#include <fcntl.h>
4#include <errno.h>
5
6/* this is needed so the libpthread wrapper can initialize the mutex,
7 * not to lock it */
8
9FILE *freopen_unlocked(const char *path, const char *mode, FILE *stream) {
10  if (stream) {
11    int f=__stdio_parse_mode(mode);
12    fflush_unlocked(stream);
13    close(stream->fd);
14    if ((stream->fd=open(path,f,0666))!=-1) {
15      //struct stat st;
16      //fstat(stream->fd,&st);
17      stream->flags = 0;//=(S_ISFIFO(st.st_mode))?FDPIPE:0;
18      switch (f&3) {
19      case O_RDWR: stream->flags|=CANWRITE;
20      case O_RDONLY: stream->flags|=CANREAD; break;
21      case O_WRONLY: stream->flags|=CANWRITE;
22      }
23    }
24  } else errno=EINVAL;
25  return stream;
26}
27
28FILE *freopen(const char *path, const char *mode, FILE *stream) __attribute__((weak,alias("freopen_unlocked")));
Note: See TracBrowser for help on using the repository browser.