|
1 | 1 | /*
|
2 |
| - * File : syscall_open.c |
3 |
| - * This file is part of RT-Thread RTOS |
4 |
| - * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team |
5 |
| - * |
6 |
| - * This program is free software; you can redistribute it and/or modify |
7 |
| - * it under the terms of the GNU General Public License as published by |
8 |
| - * the Free Software Foundation; either version 2 of the License, or |
9 |
| - * (at your option) any later version. |
10 |
| - * |
11 |
| - * This program is distributed in the hope that it will be useful, |
12 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
| - * GNU General Public License for more details. |
15 |
| - * |
16 |
| - * You should have received a copy of the GNU General Public License along |
17 |
| - * with this program; if not, write to the Free Software Foundation, Inc., |
18 |
| - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
| - * |
20 |
| - * Change Logs: |
21 |
| - * Date Author Notes |
22 |
| - * 2015-01-28 Bernard first version |
23 |
| - */ |
| 2 | +* File : syscall_open.c |
| 3 | +* This file is part of RT-Thread RTOS |
| 4 | +* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team |
| 5 | +* |
| 6 | +* This program is free software; you can redistribute it and/or modify |
| 7 | +* it under the terms of the GNU General Public License as published by |
| 8 | +* the Free Software Foundation; either version 2 of the License, or |
| 9 | +* (at your option) any later version. |
| 10 | +* |
| 11 | +* This program is distributed in the hope that it will be useful, |
| 12 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +* GNU General Public License for more details. |
| 15 | +* |
| 16 | +* You should have received a copy of the GNU General Public License along |
| 17 | +* with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +* |
| 20 | +* Change Logs: |
| 21 | +* Date Author Notes |
| 22 | +* 2015-01-28 Bernard first version |
| 23 | +*/ |
24 | 24 |
|
25 | 25 | #include <rtthread.h>
|
26 | 26 | #include <yfuns.h>
|
|
32 | 32 |
|
33 | 33 | int __open(const char *filename, int mode)
|
34 | 34 | {
|
35 |
| - if (mode & _LLIO_CREAT) |
| 35 | +#ifndef RT_USING_DFS |
| 36 | + return -1; |
| 37 | +#else |
| 38 | + int handle; |
| 39 | + int open_mode = O_RDONLY; |
| 40 | + |
| 41 | + if (mode & _LLIO_CREAT) |
| 42 | + { |
| 43 | + open_mode |= O_CREAT; |
| 44 | + |
| 45 | + /* Check what we should do with it if it exists. */ |
| 46 | + if (mode & _LLIO_APPEND) |
36 | 47 | {
|
| 48 | + /* Append to the existing file. */ |
| 49 | + open_mode |= O_APPEND; |
37 | 50 | }
|
38 | 51 |
|
39 |
| - if (mode & _LLIO_TEXT) |
| 52 | + if (mode & _LLIO_TRUNC) |
40 | 53 | {
|
41 |
| - /* we didn't support text mode */ |
| 54 | + /* Truncate the existsing file. */ |
| 55 | + open_mode |= O_TRUNC; |
42 | 56 | }
|
43 |
| - |
44 |
| - switch (mode & _LLIO_RDWRMASK) |
45 |
| - { |
| 57 | + } |
| 58 | + |
| 59 | + if (mode & _LLIO_TEXT) |
| 60 | + { |
| 61 | + /* we didn't support text mode */ |
| 62 | + } |
| 63 | + |
| 64 | + switch (mode & _LLIO_RDWRMASK) |
| 65 | + { |
46 | 66 | case _LLIO_RDONLY:
|
47 |
| - /* The file should be opened for read only. */ |
48 | 67 | break;
|
49 |
| - |
| 68 | + |
50 | 69 | case _LLIO_WRONLY:
|
51 |
| - /* The file should be opened for write only. */ |
| 70 | + open_mode |= O_WRONLY; |
52 | 71 | break;
|
53 |
| - |
| 72 | + |
54 | 73 | case _LLIO_RDWR:
|
55 | 74 | /* The file should be opened for both reads and writes. */
|
| 75 | + open_mode |= O_RDWR; |
56 | 76 | break;
|
57 |
| - |
| 77 | + |
58 | 78 | default:
|
59 | 79 | return -1;
|
60 | 80 | }
|
61 |
| - |
62 |
| - return handle; |
| 81 | + |
| 82 | + handle = open(filename, open_mode, 0); |
| 83 | + if (handle < 0) |
| 84 | + return -1; |
| 85 | + |
| 86 | + return handle + _LLIO_STDERR + 1; |
| 87 | +#endif |
63 | 88 | }
|
64 |
| - |
|
0 commit comments