Configurable buffer size for getpwnam() and getgrnam()
Ricard Wanderlof
ricard.wanderlof at axis.com
Wed Dec 6 08:35:11 PST 2006
The following patch adds a configurable buffer size for getpwnam() and
getgrnam() and friends. The default buffer size is, as before, 256 (glibc
seems to use 1024 by default).
I couldn't find a good existing place to put the config variable so I
added a new menu to the configuration called Advanced Library Settings
which would then be intended for esoteric stuff like this that most people
won't want to change.
vapier suggested adding a new include file for this type of seldom-used
user-defined stuff, but I felt the additional complexity of having a
secondary configuration infrastructure couldn't be justified when there is
a nice, working configuration system in place.
I also removed the corresponding definitions from pwd_grp_internal.c, as
they didn't seem to be used there at all.
Patch included in the mail for visual review, and also as an attachement.
/Ricard
diff -u -r uClibc-trunk/extra/Configs/Config.in uClibc-dev/extra/Configs/Config.in
--- uClibc-trunk/extra/Configs/Config.in 2006-12-06 14:02:59.000000000 +0100
+++ uClibc-dev/extra/Configs/Config.in 2006-12-06 14:17:36.000000000 +0100
@@ -592,6 +592,28 @@
endmenu
+menu "Advanced Library Settings"
+
+config UCLIBC_PWD_BUFFER_SIZE
+ int "Buffer size for getpwnam() and friends"
+ default 256
+ help
+ This sets the value of the buffer size for getpwnam() and friends.
+ By default, this is 256. (For reference, glibc uses 1024).
+ The value can be found using sysconf() with the _SC_GETPW_R_SIZE_MAX
+ parameter.
+
+config UCLIBC_GRP_BUFFER_SIZE
+ int "Buffer size for getgrnam() and friends"
+ default 256
+ help
+ This sets the value of the buffer size for getgrnam() and friends.
+ By default, this is 256. (For reference, glibc uses 1024).
+ The value can be found using sysconf() with the _SC_GETGR_R_SIZE_MAX
+ parameter.
+
+endmenu
+
menu "Networking Support"
config UCLIBC_HAS_IPV6
diff -u -r uClibc-trunk/libc/pwd_grp/pwd_grp.c uClibc-dev/libc/pwd_grp/pwd_grp.c
--- uClibc-trunk/libc/pwd_grp/pwd_grp.c 2006-12-06 14:03:08.000000000 +0100
+++ uClibc-dev/libc/pwd_grp/pwd_grp.c 2006-12-06 14:15:56.000000000 +0100
@@ -57,14 +57,6 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
extern int __parsepwent(void *pw, char *line) attribute_hidden;
@@ -167,7 +159,7 @@
struct passwd *fgetpwent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -185,7 +177,7 @@
struct group *fgetgrent(FILE *stream)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -202,7 +194,7 @@
struct spwd *fgetspent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -222,7 +214,7 @@
*result
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
DO_ERANGE:
__set_errno(rv);
goto DONE;
@@ -308,7 +300,7 @@
struct passwd *getpwuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -324,7 +316,7 @@
struct group *getgrgid(gid_t gid)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -350,7 +342,7 @@
int rv;
struct passwd *pp;
struct passwd password;
- char pwd_buff[PWD_BUFFER_SIZE];
+ char pwd_buff[__UCLIBC_PWD_BUFFER_SIZE__];
*result if (!(rv @@ -371,7 +363,7 @@
struct spwd *getspuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -387,7 +379,7 @@
struct passwd *getpwnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -403,7 +395,7 @@
struct group *getgrnam(const char *name)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -419,7 +411,7 @@
struct spwd *getspnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -437,7 +429,7 @@
{
struct passwd resultbuf;
struct passwd *result;
- char buffer[PWD_BUFFER_SIZE];
+ char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
if (!buf) {
__set_errno(EINVAL);
@@ -641,7 +633,7 @@
struct passwd *getpwent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd pwd;
struct passwd *result;
@@ -657,7 +649,7 @@
struct group *getgrent(void)
{
- static char line_buff[GRP_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group gr;
struct group *result;
@@ -673,7 +665,7 @@
struct spwd *getspent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -689,7 +681,7 @@
struct spwd *sgetspent(const char *string)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -712,7 +704,7 @@
int num_groups, rv;
char **m;
struct group group;
- char buff[PWD_BUFFER_SIZE];
+ char buff[__UCLIBC_PWD_BUFFER_SIZE__];
rv
@@ -1141,7 +1133,7 @@
int rv __STDIO_AUTO_THREADLOCK_VAR;
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
__set_errno(rv);
} else {
__STDIO_AUTO_THREADLOCK(f);
diff -u -r uClibc-trunk/libc/pwd_grp/pwd_grp_internal.c uClibc-dev/libc/pwd_grp/pwd_grp_internal.c
--- uClibc-trunk/libc/pwd_grp/pwd_grp_internal.c 2006-12-06 14:03:08.000000000 +0100
+++ uClibc-dev/libc/pwd_grp/pwd_grp_internal.c 2006-12-06 14:16:07.000000000 +0100
@@ -39,14 +39,6 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
#ifndef GETXXKEY_R_FUNC
diff -u -r uClibc-trunk/libc/unistd/sysconf.c uClibc-dev/libc/unistd/sysconf.c
--- uClibc-trunk/libc/unistd/sysconf.c 2006-12-06 14:03:13.000000000 +0100
+++ uClibc-dev/libc/unistd/sysconf.c 2006-12-06 14:16:46.000000000 +0100
@@ -568,13 +568,11 @@
#endif
/* If you change these, also change libc/pwd_grp/pwd_grp.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
case _SC_GETGR_R_SIZE_MAX:
- return GRP_BUFFER_SIZE;
+ return __UCLIBC_GRP_BUFFER_SIZE__;
case _SC_GETPW_R_SIZE_MAX:
- return PWD_BUFFER_SIZE;
+ return __UCLIBC_PWD_BUFFER_SIZE__;
/* getlogin() is a worthless interface. In uClibc we let the user specify
* whatever they want via the LOGNAME environment variable, or we return NULL
--
Ricard Wolf Wanderlöf ricardw(at)axis.com
Axis Communications AB, Lund, Sweden www.axis.com
Phone +46 46 272 2016 Fax +46 46 13 61 30
-------------- next part --------------
diff -u -r uClibc-trunk/extra/Configs/Config.in uClibc-dev/extra/Configs/Config.in
--- uClibc-trunk/extra/Configs/Config.in 2006-12-06 14:02:59.000000000 +0100
+++ uClibc-dev/extra/Configs/Config.in 2006-12-06 14:17:36.000000000 +0100
@@ -592,6 +592,28 @@
endmenu
+menu "Advanced Library Settings"
+
+config UCLIBC_PWD_BUFFER_SIZE
+ int "Buffer size for getpwnam() and friends"
+ default 256
+ help
+ This sets the value of the buffer size for getpwnam() and friends.
+ By default, this is 256. (For reference, glibc uses 1024).
+ The value can be found using sysconf() with the _SC_GETPW_R_SIZE_MAX
+ parameter.
+
+config UCLIBC_GRP_BUFFER_SIZE
+ int "Buffer size for getgrnam() and friends"
+ default 256
+ help
+ This sets the value of the buffer size for getgrnam() and friends.
+ By default, this is 256. (For reference, glibc uses 1024).
+ The value can be found using sysconf() with the _SC_GETGR_R_SIZE_MAX
+ parameter.
+
+endmenu
+
menu "Networking Support"
config UCLIBC_HAS_IPV6
diff -u -r uClibc-trunk/libc/pwd_grp/pwd_grp.c uClibc-dev/libc/pwd_grp/pwd_grp.c
--- uClibc-trunk/libc/pwd_grp/pwd_grp.c 2006-12-06 14:03:08.000000000 +0100
+++ uClibc-dev/libc/pwd_grp/pwd_grp.c 2006-12-06 14:15:56.000000000 +0100
@@ -57,14 +57,6 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
extern int __parsepwent(void *pw, char *line) attribute_hidden;
@@ -167,7 +159,7 @@
struct passwd *fgetpwent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -185,7 +177,7 @@
struct group *fgetgrent(FILE *stream)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -202,7 +194,7 @@
struct spwd *fgetspent(FILE *stream)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -222,7 +214,7 @@
*result
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
DO_ERANGE:
__set_errno(rv);
goto DONE;
@@ -308,7 +300,7 @@
struct passwd *getpwuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -324,7 +316,7 @@
struct group *getgrgid(gid_t gid)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -350,7 +342,7 @@
int rv;
struct passwd *pp;
struct passwd password;
- char pwd_buff[PWD_BUFFER_SIZE];
+ char pwd_buff[__UCLIBC_PWD_BUFFER_SIZE__];
*result if (!(rv @@ -371,7 +363,7 @@
struct spwd *getspuid(uid_t uid)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -387,7 +379,7 @@
struct passwd *getpwnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd resultbuf;
struct passwd *result;
@@ -403,7 +395,7 @@
struct group *getgrnam(const char *name)
{
- static char buffer[GRP_BUFFER_SIZE];
+ static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group resultbuf;
struct group *result;
@@ -419,7 +411,7 @@
struct spwd *getspnam(const char *name)
{
- static char buffer[PWD_BUFFER_SIZE];
+ static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd resultbuf;
struct spwd *result;
@@ -437,7 +429,7 @@
{
struct passwd resultbuf;
struct passwd *result;
- char buffer[PWD_BUFFER_SIZE];
+ char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
if (!buf) {
__set_errno(EINVAL);
@@ -641,7 +633,7 @@
struct passwd *getpwent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct passwd pwd;
struct passwd *result;
@@ -657,7 +649,7 @@
struct group *getgrent(void)
{
- static char line_buff[GRP_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
static struct group gr;
struct group *result;
@@ -673,7 +665,7 @@
struct spwd *getspent(void)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -689,7 +681,7 @@
struct spwd *sgetspent(const char *string)
{
- static char line_buff[PWD_BUFFER_SIZE];
+ static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
static struct spwd spwd;
struct spwd *result;
@@ -712,7 +704,7 @@
int num_groups, rv;
char **m;
struct group group;
- char buff[PWD_BUFFER_SIZE];
+ char buff[__UCLIBC_PWD_BUFFER_SIZE__];
rv
@@ -1141,7 +1133,7 @@
int rv __STDIO_AUTO_THREADLOCK_VAR;
- if (buflen < PWD_BUFFER_SIZE) {
+ if (buflen < __UCLIBC_PWD_BUFFER_SIZE__) {
__set_errno(rv);
} else {
__STDIO_AUTO_THREADLOCK(f);
diff -u -r uClibc-trunk/libc/pwd_grp/pwd_grp_internal.c uClibc-dev/libc/pwd_grp/pwd_grp_internal.c
--- uClibc-trunk/libc/pwd_grp/pwd_grp_internal.c 2006-12-06 14:03:08.000000000 +0100
+++ uClibc-dev/libc/pwd_grp/pwd_grp_internal.c 2006-12-06 14:16:07.000000000 +0100
@@ -39,14 +39,6 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
#ifndef GETXXKEY_R_FUNC
diff -u -r uClibc-trunk/libc/unistd/sysconf.c uClibc-dev/libc/unistd/sysconf.c
--- uClibc-trunk/libc/unistd/sysconf.c 2006-12-06 14:03:13.000000000 +0100
+++ uClibc-dev/libc/unistd/sysconf.c 2006-12-06 14:16:46.000000000 +0100
@@ -568,13 +568,11 @@
#endif
/* If you change these, also change libc/pwd_grp/pwd_grp.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
case _SC_GETGR_R_SIZE_MAX:
- return GRP_BUFFER_SIZE;
+ return __UCLIBC_GRP_BUFFER_SIZE__;
case _SC_GETPW_R_SIZE_MAX:
- return PWD_BUFFER_SIZE;
+ return __UCLIBC_PWD_BUFFER_SIZE__;
/* getlogin() is a worthless interface. In uClibc we let the user specify
* whatever they want via the LOGNAME environment variable, or we return NULL
More information about the uClibc
mailing list