-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathos.c
More file actions
99 lines (89 loc) · 2.62 KB
/
Copy pathos.c
File metadata and controls
99 lines (89 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2026 HardenedLinux Community
* Nala Ginrut <roy@hardenedlinux.org>
* Animula is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* Animula is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "os.h"
#include "debug.h"
#if defined ANIMULA_LINUX
//
#elif defined ANIMULA_ZEPHYR
# include <zephyr/fs/fs.h> // fs_open
# include <zephyr/fs/fs_interface.h> // fs_file_t
GLOBAL_DEF (struct fs_file_t,
file_descriptors[CONFIG_MAXIMUM_NUMBER_OPEN_FILE_DESCRIPTOR])
= {0};
# ifndef CONFIG_MAXIMUM_NUMBER_OPEN_FILE_DESCRIPTOR
# error \
"Please specify CONFIG_MAXIMUM_NUMBER_OPEN_FILE_DESCRIPTOR in prj.conf"
# else
int zephyr_open (const char *pathname, int flags)
{
int fd = 0;
// 0: stdout
// 1: stdin
// 2: stderr
struct fs_file_t *file = NULL;
for (size_t i = 3; i < CONFIG_MAXIMUM_NUMBER_OPEN_FILE_DESCRIPTOR; i++)
{
if (NULL == (GLOBAL_REF (file_descriptors)[i]).filep)
{
file = &(GLOBAL_REF (file_descriptors)[i]);
fd = i;
break;
}
}
int ret = fs_open (file, pathname, flags);
// file is modified in fs_open
if (ret < 0) // open error
{
return ret;
}
else if (0 == ret) // success
{
return fd;
}
else // ret > 0
{
PANIC ("Error, zephyr fs_open shall not return a positive value");
return ret;
}
}
int zephyr_close (int fd)
{
struct fs_file_t *file = &(GLOBAL_REF (file_descriptors))[fd];
int ret = fs_close (file);
if (0 == ret) // success
{
(GLOBAL_REF (file_descriptors))[fd].filep = (void *)NULL;
os_memset ((void *)file, 0, sizeof (struct fs_file_t));
// file->filep = (void*)NULL;
return 0;
}
else // failed
{
return ret;
}
}
ssize_t zephyr_read (int fd, void *buf, size_t count)
{
struct fs_file_t *file = &(GLOBAL_REF (file_descriptors))[fd];
return fs_read (file, buf, count);
}
int zephyr_stat (const char *path, struct fs_dirent *entry)
{
return fs_stat (path, entry);
}
# endif /* CONFIG_MAXIMUM_NUMBER_OPEN_FILE_DESCRIPTOR */
#endif /* ANIMULA_ZEPHYR */