source: trunk/sys/dietlibc/fdglue2.c @ 1

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

First import

File size: 1.1 KB
Line 
1#include <unistd.h>
2#include <fcntl.h>
3#include <sys/stat.h>
4#include <errno.h>
5#include "dietstdio.h"
6#include <stdlib.h>
7#ifdef WANT_THREAD_SAFE
8#include <pthread.h>
9#endif
10
11extern int __stdio_atexit;
12
13FILE*__stdio_init_file(int fd,int closeonerror,int mode) {
14  FILE *tmp=(FILE*)malloc(sizeof(FILE));
15  if (!tmp) goto err_out;
16  tmp->buf=(char*)malloc(BUFSIZE);
17  if (!tmp->buf) {
18    free(tmp);
19err_out:
20    if (closeonerror) close(fd);
21    errno=ENOMEM;
22    return 0;
23  }
24  tmp->fd=fd;
25  tmp->bm=0;
26  tmp->bs=0;
27  tmp->buflen=BUFSIZE;
28  {
29    //struct stat st;
30    //st.st_mode = 0;
31    //fstat(fd,&st);
32    //tmp->flags=(S_ISFIFO(st.st_mode))?FDPIPE:0;
33  }
34  tmp->flags = 0;
35  tmp->flags = (mode & O_WRONLY) ? tmp->flags | CANWRITE : tmp->flags;
36  tmp->flags = (mode & O_RDONLY) ? tmp->flags | CANREAD : tmp->flags;
37
38  tmp->popen_kludge=0;
39  if (__stdio_atexit==0) {
40    __stdio_atexit=1;
41    atexit(__stdio_flushall);
42  }
43  tmp->next=__stdio_root;
44  __stdio_root=tmp;
45  tmp->ungotten=0;
46
47  return tmp;
48}
49
50FILE* __stdio_init_file_nothreads(int fd,int closeonerror,int mode) __attribute__((alias("__stdio_init_file")));
Note: See TracBrowser for help on using the repository browser.