8000 Use __attribute((weak)) for _write() and other stubs called by newlib… · rondlh/arduino-pico@44abc19 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 44abc19

Browse files
authored
Use __attribute((weak)) for _write() and other stubs called by newlib, so that sketch and library code can provide non-stub implementations (earlephilhower#1777)
1 parent 2e93f1c commit 44abc19

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

cores/rp2040/posix.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
extern "C" int errno;
3535

36-
extern "C" ssize_t _write(int fd, const void *buf, size_t count) {
36+
extern "C"
37+
__attribute((weak))
38+
ssize_t _write(int fd, const void *buf, size_t count) {
3739
#if defined DEBUG_RP2040_PORT
3840
(void) fd;
3941
return DEBUG_RP2040_PORT.write((const char *)buf, count);
@@ -45,15 +47,19 @@ extern "C" ssize_t _write(int fd, const void *buf, size_t count) {
4547
#endif
4648
}
4749

48-
extern "C" int _chown(const char *path, uid_t owner, gid_t group) {
50+
extern "C"
51+
__attribute((weak))
52+
int _chown(const char *path, uid_t owner, gid_t group) {
4953
(void) path;
5054
(void) owner;
5155
(void) group;
5256
errno = ENOSYS;
5357
return -1;
5458
}
5559

56-
extern "C" int _close(int fd) {
60+
extern "C"
61+
__attribute((weak))
62+
int _close(int fd) {
5763
(void) fd;
5864
errno = ENOSYS;
5965
return -1;
@@ -72,7 +78,9 @@ extern "C" int _fork(void) {
7278
return -1;
7379
}
7480

75-
extern "C" int _fstat(int fd, struct stat *st) {
81+
extern "C"
82+
__attribute((weak))
83+
int _fstat(int fd, struct stat *st) {
7684
(void) fd;
7785
(void) st;
7886
errno = ENOSYS;
@@ -115,7 +123,9 @@ extern "C" void __setSystemTime(unsigned long long sec, unsigned long usec) {
115123
__timedelta_us = newnow_us - now_us;
116124
}
117125

118-
extern "C" int _isatty(int file) {
126+
extern "C"
127+
__attribute((weak))
128+
int _isatty(int file) {
119129
(void) file;
120130
errno = ENOSYS;
121131
return 0;
@@ -128,53 +138,67 @@ extern "C" int _kill(int pid, int sig) {
128138
return -1;
129139
}
130140

131-
extern "C" int _link(char *existing, char *newlink) {
141+
extern "C"
142+
__attribute((weak))
143+
int _link(char *existing, char *newlink) {
132144
(void) existing;
133145
(void) newlink;
134146
errno = ENOSYS;
135147
return -1;
136148
}
137149

138-
extern "C" int _lseek(int file, int ptr, int dir) {
150+
extern "C"
151+
__attribute((weak))
152+
int _lseek(int file, int ptr, int dir) {
139153
(void) file;
140154
(void) ptr;
141155
(void) dir;
142156
errno = ENOSYS;
143157
return -1;
144158
}
145159

146-
extern "C" int _open(char *file, int flags, int mode) {
160+
extern "C"
161+
__attribute((weak))
162+
int _open(char *file, int flags, int mode) {
147163
(void) file;
148164
(void) flags;
149165
(void) mode;
150166
errno = ENOSYS;
151167
return -1;
152168
}
153169

154-
extern "C" int _read(int file, char *ptr, int len) {
170+
extern "C"
171+
__attribute((weak))
172+
int _read(int file, char *ptr, int len) {
155173
(void) file;
156174
(void) ptr;
157175
(void) len;
158176
// return Serial.read(ptr, len);
159177
return -1;
160178
}
161179

162-
extern "C" int _readlink(const char *path, char *buf, size_t bufsize) {
180+
extern "C"
181+
__attribute((weak))
182+
int _readlink(const char *path, char *buf, size_t bufsize) {
163183
(void) path;
164184
(void) buf;
165185
(void) bufsize;
166186
errno = ENOSYS;
167187
return -1;
168188
}
169189

170-
extern "C" int _stat(const char *file, struct stat *st) {
190+
extern "C"
191+
__attribute((weak))
192+
int _stat(const char *file, struct stat *st) {
171193
(void) file;
172194
(void) st;
173195
errno = ENOSYS;
174196
return -1;
175197
}
176198

177-
extern "C" int _symlink(const char *path1, const char *path2) {
199+
extern "C"
200+
__attribute((weak))
201+
int _symlink(const char *path1, const char *path2) {
178202
(void) path1;
179203
(void) path2;
180204
errno = ENOSYS;
@@ -187,7 +211,9 @@ extern "C" clock_t _times(struct tms *buf) {
187211
return -1;
188212
}
189213

190-
extern "C" int _unlink(char *name) {
214+
extern "C"
215+
__attribute((weak))
216+
int _unlink(char *name) {
191217
(void) name;
192218
errno = ENOSYS;
193219
return -1;

0 commit comments

Comments
 (0)
0