µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
c-newlib-reent.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2015-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(__clang__)
13#pragma clang diagnostic ignored "-Wempty-translation-unit"
14#endif
15
16// ----------------------------------------------------------------------------
17
18#if defined(__ARM_EABI__)
19
20// ----------------------------------------------------------------------------
21
23
24// ----------------------------------------------------------------------------
25
26extern "C"
27{
28
29 // Many newlib functions call the reentrant versions right away,
30 // and these call the _name() implementations. To avoid this, the
31 // shortcut is to simply skip the reentrant code (ignore the pointer)
32 // and directly call the posix implementation.
33
34#pragma GCC diagnostic push
35#if defined(__clang__)
36#elif defined(__GNUC__)
37#pragma GCC diagnostic ignored "-Wmissing-declarations"
38#pragma GCC diagnostic ignored "-Wunused-parameter"
39#endif
40
41 int __attribute__ ((weak))
42 _close_r (void* ptr, int fildes)
43 {
44 return __posix_close (fildes);
45 }
46
47 int __attribute__ ((weak))
48 _execve_r (void* ptr, const char* path, char* const argv[],
49 char* const envp[])
50 {
51 return __posix_execve (path, argv, envp);
52 }
53
54 int __attribute__ ((weak))
55 _fcntl_r (void* ptr, int fildes, int cmd, int arg)
56 {
57 return __posix_fcntl (fildes, cmd, arg);
58 }
59
60 pid_t __attribute__ ((weak))
61 _fork_r (void* ptr)
62 {
63 return __posix_fork ();
64 }
65
66#pragma GCC diagnostic push
67#if defined(__clang__)
68#elif defined(__GNUC__)
69#pragma GCC diagnostic ignored "-Wredundant-tags"
70#endif
71 int __attribute__ ((weak))
72 _fstat_r (void* ptr, int fildes, struct stat* buf)
73 {
74 return __posix_fstat (fildes, buf);
75 }
76#pragma GCC diagnostic pop
77
78 pid_t __attribute__ ((weak))
79 _getpid_r (void* ptr)
80 {
81 return __posix_getpid ();
82 }
83
84 int __attribute__ ((weak))
85 _gettimeofday_r (void* ptr, /* struct */ timeval* ptimeval, void* ptimezone)
86 {
87 return __posix_gettimeofday (ptimeval, ptimezone);
88 }
89
90 int __attribute__ ((weak))
91 _isatty_r (void* ptr, int fildes)
92 {
93 return __posix_isatty (fildes);
94 }
95
96 int __attribute__ ((weak))
97 _kill_r (void* ptr, pid_t pid, int sig)
98 {
99 return __posix_kill (pid, sig);
100 }
101
102 int __attribute__ ((weak))
103 _link_r (void* ptr, const char* existing, const char* _new)
104 {
105 return __posix_link (existing, _new);
106 }
107
108 off_t __attribute__ ((weak))
109 _lseek_r (void* ptr, int fildes, off_t offset, int whence)
110 {
111 return __posix_lseek (fildes, offset, whence);
112 }
113
114 int __attribute__ ((weak))
115 _mkdir_r (void* ptr, const char* path, mode_t mode)
116 {
117 return __posix_mkdir (path, mode);
118 }
119
120 int __attribute__ ((weak))
121 _open_r (void* ptr, const char* path, int oflag, int mode)
122 {
123 return __posix_open (path, oflag, mode);
124 }
125
126 ssize_t __attribute__ ((weak))
127 _read_r (void* ptr, int fildes, void* buf, size_t nbyte)
128 {
129 return __posix_read (fildes, buf, nbyte);
130 }
131
132 int __attribute__ ((weak))
133 _rename_r (void* ptr, const char* oldfn, const char* newfn)
134 {
135 return __posix_rename (oldfn, newfn);
136 }
137
138#pragma GCC diagnostic push
139#if defined(__clang__)
140#elif defined(__GNUC__)
141#pragma GCC diagnostic ignored "-Wredundant-tags"
142#endif
143 int __attribute__ ((weak))
144 _stat_r (void* ptr, const char* path, struct stat* buf)
145 {
146 return __posix_stat (path, buf);
147 }
148#pragma GCC diagnostic pop
149
150 clock_t __attribute__ ((weak))
151 _times_r (void* ptr, /* struct */ tms* buf)
152 {
153 return __posix_times (buf);
154 }
155
156 int __attribute__ ((weak))
157 _unlink_r (void* ptr, const char* name)
158 {
159 return __posix_unlink (name);
160 }
161
162 pid_t __attribute__ ((weak))
163 _wait_r (void* ptr, int* stat_loc)
164 {
165 return __posix_wait (stat_loc);
166 }
167
168 ssize_t __attribute__ ((weak))
169 _write_r (void* ptr, int fildes, const void* buf, size_t nbyte)
170 {
171 return __posix_write (fildes, buf, nbyte);
172 }
173
174 // --------------------------------------------------------------------------
175
176#pragma GCC diagnostic pop
177}
178
179// ----------------------------------------------------------------------------
180
181#endif /* defined(__ARM_EABI__) */
pid_t _fork_r(void *ptr)
int _isatty_r(void *ptr, int fildes)
clock_t _times_r(void *ptr, tms *buf)
off_t _lseek_r(void *ptr, int fildes, off_t offset, int whence)
int _unlink_r(void *ptr, const char *name)
pid_t _wait_r(void *ptr, int *stat_loc)
int _open_r(void *ptr, const char *path, int oflag, int mode)
int _stat_r(void *ptr, const char *path, struct stat *buf)
ssize_t _read_r(void *ptr, int fildes, void *buf, size_t nbyte)
int _execve_r(void *ptr, const char *path, char *const argv[], char *const envp[])
ssize_t _write_r(void *ptr, int fildes, const void *buf, size_t nbyte)
pid_t _getpid_r(void *ptr)
int _fstat_r(void *ptr, int fildes, struct stat *buf)
int _close_r(void *ptr, int fildes)
int _kill_r(void *ptr, pid_t pid, int sig)
int _link_r(void *ptr, const char *existing, const char *_new)
int _rename_r(void *ptr, const char *oldfn, const char *newfn)
int _gettimeofday_r(void *ptr, timeval *ptimeval, void *ptimezone)
int _mkdir_r(void *ptr, const char *path, mode_t mode)
int _fcntl_r(void *ptr, int fildes, int cmd, int arg)
int stat(const char *path, struct stat *buf)
#define __posix_wait
#define __posix_kill
#define __posix_lseek
#define __posix_fstat
#define __posix_stat
#define __posix_close
#define __posix_link
#define __posix_read
#define __posix_fcntl
#define __posix_gettimeofday
#define __posix_times
#define __posix_write
#define __posix_open
#define __posix_mkdir
#define __posix_rename
#define __posix_isatty
#define __posix_unlink
#define __posix_getpid
#define __posix_fork
#define __posix_execve