Skip to content

Commit 0f6d355

Browse files
committed
LibC: Improve error handling for unimplemented functions
- getpriority()/setpriority(): Set errno to ENOSYS before returning -1 - chroot(): Set errno to ENOSYS before returning -1 - nice(): Set errno to ENOSYS and return -1 (was incorrectly returning incr) - fnmatch(): Return FNM_NOMATCH instead of 0 (match) for unimplemented stub These functions now properly indicate they are not implemented by setting errno to ENOSYS, following POSIX conventions. The fnmatch() change prevents false positive matches when the function is called before implementation.
1 parent 0add8d9 commit 0f6d355

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Userland/Libraries/LibC/fnmatch.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7-
#include <AK/Format.h>
87
#include <fnmatch.h>
98

10-
int fnmatch(char const*, char const*, int)
9+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fnmatch.html
10+
int fnmatch([[maybe_unused]] char const* pattern, [[maybe_unused]] char const* string, [[maybe_unused]] int flags)
1111
{
12-
dbgln("FIXME: Implement fnmatch()");
13-
return 0;
12+
// FIXME: Implement fnmatch()
13+
// Returning FNM_NOMATCH is safer than returning 0 (match) for unimplemented function
14+
return FNM_NOMATCH;
1415
}

Userland/Libraries/LibC/priority.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7-
#include <AK/Format.h>
7+
#include <errno.h>
88
#include <sys/resource.h>
99

1010
extern "C" {
1111

12+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpriority.html
1213
int getpriority([[maybe_unused]] int which, [[maybe_unused]] id_t who)
1314
{
14-
dbgln("FIXME: Implement getpriority()");
15+
// FIXME: Implement getpriority()
16+
errno = ENOSYS;
1517
return -1;
1618
}
1719

20+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/setpriority.html
1821
int setpriority([[maybe_unused]] int which, [[maybe_unused]] id_t who, [[maybe_unused]] int value)
1922
{
20-
dbgln("FIXME: Implement setpriority()");
23+
// FIXME: Implement setpriority()
24+
errno = ENOSYS;
2125
return -1;
2226
}
2327
}

Userland/Libraries/LibC/unistd.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,10 @@ int pause()
11101110
}
11111111

11121112
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/chroot.html
1113-
int chroot(char const* path)
1113+
int chroot([[maybe_unused]] char const* path)
11141114
{
1115-
dbgln("FIXME: chroot(\"{}\")", path);
1115+
// FIXME: Implement chroot()
1116+
errno = ENOSYS;
11161117
return -1;
11171118
}
11181119

@@ -1125,10 +1126,11 @@ int getdtablesize()
11251126
}
11261127

11271128
// https://pubs.opengroup.org/onlinepubs/007904975/functions/nice.html
1128-
int nice(int incr)
1129+
int nice([[maybe_unused]] int incr)
11291130
{
1130-
dbgln("FIXME: nice was called with: {}, not implemented", incr);
1131-
return incr;
1131+
// FIXME: Implement nice()
1132+
errno = ENOSYS;
1133+
return -1;
11321134
}
11331135

11341136
int brk(void* addr)

0 commit comments

Comments
 (0)