Skip to content

Commit b685d3b

Browse files
committed
posix: options: implement POSIX_SYSTEM_DATABASE_R
Provide an implementation for the POSIX_SYSTEM_DATABASE_R Option Group. This group is required for all conforming implementations and is therefore required for PSE51, PSE52, PSE53, PSE54, and all other possible subprofiles. Signed-off-by: Chris Friedt <[email protected]>
1 parent c35c9ec commit b685d3b

File tree

11 files changed

+399
-80
lines changed

11 files changed

+399
-80
lines changed

include/zephyr/posix/grp.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2024 Meta Platforms
3+
* Copyright (c) 2024 Tenstorrent AI ULC
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -24,9 +25,18 @@ struct group {
2425
char **gr_mem;
2526
};
2627

28+
#if defined(_XOPEN_SOURCE)
29+
void endgrent(void);
30+
struct group *getgrent(void);
31+
#endif
32+
struct group *getgrgid(gid_t gid);
33+
int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result);
34+
struct group *getgrnam(const char *name);
2735
int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize,
2836
struct group **result);
29-
int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result);
37+
#if defined(_XOPEN_SOURCE)
38+
void setgrent(void);
39+
#endif
3040

3141
#ifdef __cplusplus
3242
}

include/zephyr/posix/pwd.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2024 Meta Platforms
3+
* Copyright (c) 2024 Tenstorrent AI ULC
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -25,9 +26,18 @@ struct passwd {
2526
char *pw_shell;
2627
};
2728

28-
int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize,
29+
#if defined(_XOPEN_SOURCE)
30+
void endpwent(void);
31+
struct passwd *getpwent(void);
32+
#endif
33+
struct passwd *getpwnam(const char *name);
34+
int getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize,
2935
struct passwd **result);
36+
struct passwd *getpwuid(uid_t uid);
3037
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result);
38+
#if defined(_XOPEN_SOURCE)
39+
void setpwent(void);
40+
#endif
3141

3242
#ifdef __cplusplus
3343
}

include/zephyr/posix/sys/sysconf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ enum {
264264
#define __z_posix_sysconf_SC_XOPEN_UUCP (-1L)
265265
#define __z_posix_sysconf_SC_XOPEN_VERSION _XOPEN_VERSION
266266
#define __z_posix_sysconf_SC_CLK_TCK (100L)
267-
#define __z_posix_sysconf_SC_GETGR_R_SIZE_MAX (0L)
268-
#define __z_posix_sysconf_SC_GETPW_R_SIZE_MAX (0L)
267+
#define __z_posix_sysconf_SC_GETGR_R_SIZE_MAX CONFIG_POSIX_GETGR_R_SIZE_MAX
268+
#define __z_posix_sysconf_SC_GETPW_R_SIZE_MAX CONFIG_POSIX_GETPW_R_SIZE_MAX
269269
#define __z_posix_sysconf_SC_AIO_LISTIO_MAX AIO_LISTIO_MAX
270270
#define __z_posix_sysconf_SC_AIO_MAX AIO_MAX
271271
#define __z_posix_sysconf_SC_AIO_PRIO_DELTA_MAX AIO_PRIO_DELTA_MAX

lib/posix/options/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_SPIN_LOCKS)
121121
zephyr_library_sources_ifdef(CONFIG_POSIX_SPIN_LOCKS spinlock.c)
122122
endif()
123123

124+
if (NOT CONFIG_TC_PROVIDES_POSIX_SYSTEM_DATABASE_R)
125+
zephyr_library_sources_ifdef(CONFIG_POSIX_SYSTEM_DATABASE_R
126+
system_database_priv.c
127+
system_database_r.c
128+
)
129+
endif()
130+
124131
if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS)
125132
zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
126133
clock.c
@@ -145,11 +152,9 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS)
145152
# We have opted to use POSIX_THREADS here to match the Option name.
146153
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
147154
cond.c
148-
grp.c
149155
key.c
150156
mutex.c
151157
pthread.c
152-
pwd.c
153158
)
154159
endif()
155160

lib/posix/options/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rsource "Kconfig.semaphore"
2828
rsource "Kconfig.signal"
2929
rsource "Kconfig.spinlock"
3030
rsource "Kconfig.sync_io"
31+
rsource "Kconfig.system_database_r"
3132
rsource "Kconfig.timer"
3233

3334
menu "X/Open system interfaces"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2024 Tenstorrent AI ULC
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config POSIX_SYSTEM_DATABASE_R
6+
bool "POSIX System Database"
7+
help
8+
Select 'y' here, and the system will support getgrgid_r(), getgrnam_r(), getpwnam_r(), and
9+
getpwuid_r().
10+
11+
For more information, please see
12+
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
13+
14+
config POSIX_GETGR_R_SIZE_MAX
15+
int "Initial size of getgrgid_r() and getgrnam_r() data buffers"
16+
default 96
17+
help
18+
This option sets the maximum size of the buffer for getgrgid_r() and getgrnam_r().
19+
20+
The default size is derived from the formula below. Note, that the home directory and
21+
shell fields are not based on PATH_MAX, which can be excessively large.
22+
23+
_POSIX_LOGIN_NAME_MAX + 1 +
24+
sizeof(void *) +
25+
sizeof("4294967295") + 1 +
26+
2 * (_POSIX_NAME_MAX + 1 + sizeof(void *))
27+
+ sizeof(void *)
28+
29+
config POSIX_GETPW_R_SIZE_MAX
30+
int "Initial size of getpwnam_r() and getpwuid_r() data buffers"
31+
default 64
32+
help
33+
This option sets the maximum size of the buffer for getpwnam_r() and getpwuid_r().
34+
35+
The default size is derived from the formula below. Note, that the home directory and
36+
shell fields are not based on PATH_MAX, which can be excessively large.
37+
38+
_POSIX_LOGIN_NAME_MAX + 1 +
39+
sizeof("4294967295") + 1 +
40+
sizeof("4294967295") + 1 +
41+
_POSIX_NAME_MAX + 1 +
42+
_POSIX_NAME_MAX + 1

lib/posix/options/grp.c

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/posix/options/pwd.c

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)