FreeNOS
fopen.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <fcntl.h>
19 #include <sys/types.h>
20 #include "stdio.h"
21 #include "stdlib.h"
22 #include "errno.h"
23 
24 FILE * fopen(const char *filename,
25  const char *mode)
26 {
27  FILE *f;
28 
29  // Handle the file stream request
30  switch (*mode)
31  {
32  // Read
33  case 'r':
34  f = (FILE *) malloc(sizeof(FILE));
35  f->fd = open(filename, ZERO);
36  return f;
37 
38  // Unsupported
39  default:
40  break;
41  }
42 
43  // Sorry, not available yet!
44  errno = ENOTSUP;
45  return (FILE *) NULL;
46 }
fcntl.h
errno
C int errno
The lvalue errno is used by many functions to return error values.
types.h
fopen
FILE * fopen(const char *filename, const char *mode)
Open a stream.
Definition: fopen.cpp:24
open
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
Definition: open.cpp:26
malloc
C void * malloc(size_t size)
A memory allocator.
Definition: malloc.cpp:22
ENOTSUP
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:226
stdio.h
NULL
#define NULL
NULL means zero.
Definition: Macros.h:39
FILE::fd
int fd
File descriptor.
Definition: stdio.h:63
FILE
A structure containing information about a file.
Definition: stdio.h:60
stdlib.h
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
errno.h