summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorKenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>2009-01-16 11:59:37 -0800
committerKenjiro Tsuji <Kenjiro.Tsuji@Sun.COM>2009-01-16 11:59:37 -0800
commitb9175c69691c8949bec97fb8f689b7d1efdb05bb (patch)
tree9c9b02d762f4cb6afa112bd1505698f027b3fbdf /usr/src/lib/libc
parent65c8f1c0a342917e5c22dcf2b006e6307631ed67 (diff)
downloadillumos-gate-b9175c69691c8949bec97fb8f689b7d1efdb05bb.tar.gz
6783069 libc must not use defread internally
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/gen/deflt.c140
-rw-r--r--usr/src/lib/libc/port/gen/getgrnam_r.c9
-rw-r--r--usr/src/lib/libc/port/gen/localtime.c51
-rw-r--r--usr/src/lib/libc/port/mapfile-vers4
4 files changed, 159 insertions, 45 deletions
diff --git a/usr/src/lib/libc/port/gen/deflt.c b/usr/src/lib/libc/port/gen/deflt.c
index 716b3dd79e..72a0f8862a 100644
--- a/usr/src/lib/libc/port/gen/deflt.c
+++ b/usr/src/lib/libc/port/gen/deflt.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -30,8 +30,6 @@
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include "lint.h"
#include "libc.h"
#include <stdio.h>
@@ -45,14 +43,15 @@
#define TSTBITS(flags, mask) (((flags) & (mask)) == (mask))
-static void strip_quotes(char *);
-
struct thr_data {
int Dcflags; /* [re-]initialized on each call to defopen() */
FILE *fp;
char *buf;
};
+static int defopen_common(const char *, struct thr_data *);
+static void strip_quotes(char *);
+
#define BUFFERSIZE 1024
/*
@@ -105,6 +104,46 @@ defopen(char *fn)
{
struct thr_data *thr_data = get_thr_data();
+ return (defopen_common(fn, thr_data));
+}
+
+/*
+ * defopen_r() - declare defopen filename (reentrant)
+ *
+ * defopen_r(const char *fn)
+ *
+ * 'fn' is a full pathname of a file which becomes the one read
+ * by subsequent defread_r() calls. defopen_r returns a pointer
+ * to the internally allocated buffer containing the file descriptor.
+ * The pointer should be specified to the following defread_r and
+ * defcntl_r functions. As the pointer to be returned points to
+ * the libc lmalloc'd memory, defclose_r must be used to close
+ * the defopen file and to release the allocated memory. Caller
+ * must not try to release the memory by free().
+ *
+ * see defread_r() for more details.
+ *
+ * EXIT returns non-NULL pointer if success
+ * returns NULL if error
+ */
+void *
+defopen_r(const char *fn)
+{
+ /* memory allocated by lmalloc gets initialized to zeros */
+ struct thr_data *thr_data = lmalloc(sizeof (struct thr_data));
+
+ if (defopen_common(fn, thr_data) < 0) {
+ if (thr_data != NULL)
+ lfree(thr_data, sizeof (struct thr_data));
+ return (NULL);
+ }
+
+ return ((void *)thr_data);
+}
+
+static int
+defopen_common(const char *fn, struct thr_data *thr_data)
+{
if (thr_data == NULL)
return (-1);
@@ -121,7 +160,8 @@ defopen(char *fn)
/*
* We allocate the big buffer only if the fopen() succeeds.
- * Notice that we deallocate the buffer only when the thread exits.
+ * Notice that we deallocate the buffer only when the thread exits
+ * for defopen().
* There are misguided applications that assume that data returned
* by defread() continues to exist after defopen(NULL) is called.
*/
@@ -150,7 +190,7 @@ defopen(char *fn)
* the matched string (*cp). If no line is found or no file
* is open, defread() returns NULL.
*
- * Note that there is no way to simulatniously peruse multiple
+ * Note that there is no way to simultaneously peruse multiple
* defopen files; since there is no way of indicating 'which one'
* to defread(). If you want to peruse a secondary file you must
* recall defopen(). If you need to go back to the first file,
@@ -160,8 +200,29 @@ char *
defread(char *cp)
{
struct thr_data *thr_data = get_thr_data();
+
+ return (defread_r(cp, thr_data));
+}
+
+/*
+ * defread_r() - read an entry from the defopen file
+ *
+ * defread_r(const char *cp, void *defp)
+ *
+ * defread_r scans the data file associated with the pointer
+ * specified by 'defp' that was returned by defopen_r(), and
+ * looks for a line which begins with the string '*cp'.
+ * If such a line is found, defread_r returns a pointer to
+ * the first character following the matched string (*cp).
+ * If no line is found or no file is open, defread_r() returns NULL.
+ */
+char *
+defread_r(const char *cp, void *ptr)
+{
+ struct thr_data *thr_data = (struct thr_data *)ptr;
int (*compare)(const char *, const char *, size_t);
- char *buf_tmp, *ret_ptr = NULL;
+ char *buf_tmp;
+ char *ret_ptr = NULL;
size_t off, patlen;
if (thr_data == NULL || thr_data->fp == NULL)
@@ -203,21 +264,52 @@ defread(char *cp)
*
* ENTRY
* cmd Command. One of DC_GET, DC_SET.
- * arg Depends on command. If DC_GET, ignored. If
- * DC_GET, new flags value, created by ORing the DC_* bits.
+ * arg Depends on command. If DC_GET, ignored.
+ * If DC_SET, new flags value, created by ORing
+ * the DC_* bits.
* RETURN
* oldflags Old value of flags. -1 on error.
* NOTES
- * Currently only one bit of flags implemented, namely respect/
- * ignore case. The routine is as general as it is so that we
- * leave our options open. E.g. we might want to specify rewind/
- * norewind before each defread.
+ * The following commands are implemented:
+ *
+ * DC_CASE: respect(on)/ignore(off) case
+ * DC_NOREWIND: don't(on)/do(off) reqind in defread
+ * DC_STRIP_QUOTES: strip(on)/leave(off) qoates
*/
-
int
defcntl(int cmd, int newflags)
{
struct thr_data *thr_data = get_thr_data();
+
+ return (defcntl_r(cmd, newflags, thr_data));
+}
+
+/*
+ * defcntl_r -- default control
+ *
+ * SYNOPSIS
+ * oldflags = defcntl_r(int cmd, int arg, void *defp);
+ *
+ * ENTRY
+ * cmd Command. One of DC_GET, DC_SET.
+ * arg Depends on command. If DC_GET, ignored.
+ * If DC_SET, new flags value, created by ORing
+ * the DC_* bits.
+ * defp pointer to the defopen'd descriptor
+ *
+ * RETURN
+ * oldflags Old value of flags. -1 on error.
+ * NOTES
+ * The following commands are implemented:
+ *
+ * DC_CASE: respect(on)/ignore(off) case
+ * DC_NOREWIND: don't(on)/do(off) reqind in defread
+ * DC_STRIP_QUOTES: strip(on)/leave(off) qoates
+ */
+int
+defcntl_r(int cmd, int newflags, void *ptr)
+{
+ struct thr_data *thr_data = (struct thr_data *)ptr;
int oldflags;
if (thr_data == NULL)
@@ -240,6 +332,24 @@ defcntl(int cmd, int newflags)
}
/*
+ * defclose_r() - close defopen file
+ *
+ * defclose_r(void *defp)
+ *
+ * defclose_r closes the defopen file associated with the specified
+ * pointer and releases the allocated resources.
+ */
+void
+defclose_r(void *ptr)
+{
+ struct thr_data *thr_data = (struct thr_data *)ptr;
+
+ (void) fclose(thr_data->fp);
+ lfree(thr_data->buf, BUFFERSIZE);
+ lfree(thr_data, sizeof (struct thr_data));
+}
+
+/*
* strip_quotes -- strip double (") or single (') quotes from a buffer
*
* ENTRY
diff --git a/usr/src/lib/libc/port/gen/getgrnam_r.c b/usr/src/lib/libc/port/gen/getgrnam_r.c
index 7e610cd8f2..126b8c3349 100644
--- a/usr/src/lib/libc/port/gen/getgrnam_r.c
+++ b/usr/src/lib/libc/port/gen/getgrnam_r.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -242,6 +242,7 @@ _getgroupsbymember(const char *username, gid_t gid_array[],
int maxgids, int numgids)
{
struct nss_groupsbymem arg;
+ void *defp;
arg.username = username;
arg.gid_array = gid_array;
@@ -268,10 +269,10 @@ _getgroupsbymember(const char *username, gid_t gid_array[],
*/
arg.force_slow_way = 1;
- if (defopen(__NSW_DEFAULT_FILE) == 0) {
- if (defread(USE_NETID_STR) != NULL)
+ if ((defp = defopen_r(__NSW_DEFAULT_FILE)) != NULL) {
+ if (defread_r(USE_NETID_STR, defp) != NULL)
arg.force_slow_way = 0;
- (void) defopen(NULL);
+ defclose_r(defp);
}
(void) nss_search(&db_root, _nss_initf_group,
diff --git a/usr/src/lib/libc/port/gen/localtime.c b/usr/src/lib/libc/port/gen/localtime.c
index 9d406227cb..ed94ba5dc1 100644
--- a/usr/src/lib/libc/port/gen/localtime.c
+++ b/usr/src/lib/libc/port/gen/localtime.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -33,8 +33,6 @@
* (arthur_david_olson@nih.gov).
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* localtime.c
*
@@ -700,7 +698,7 @@ mktime(struct tm *tmptr)
#ifdef _ILP32
overflow = t > LONG_MAX || t < LONG_MIN ||
- tmptr->tm_year < 1 || tmptr->tm_year > 138;
+ tmptr->tm_year < 1 || tmptr->tm_year > 138;
#else
overflow = t > LONG_MAX || t < LONG_MIN;
#endif
@@ -714,11 +712,11 @@ mktime(struct tm *tmptr)
set_zone_context((time_t)t);
if (is_in_dst) {
(void) offtime_u((time_t)t,
- -altzone, &_tm);
+ -altzone, &_tm);
_tm.tm_isdst = 1;
} else {
(void) offtime_u((time_t)t,
- -timezone, &_tm);
+ -timezone, &_tm);
}
} else {
(void) offtime_u((time_t)t, -timezone, &_tm);
@@ -731,22 +729,22 @@ mktime(struct tm *tmptr)
set_zone_context((time_t)t);
if (is_in_dst) {
(void) offtime_u((time_t)t,
- -altzone, &_tm);
+ -altzone, &_tm);
_tm.tm_isdst = 1;
} else {
(void) offtime_u((time_t)t,
- -timezone, &_tm);
+ -timezone, &_tm);
}
} else { /* check for ambiguous 'fallback' transition */
set_zone_context((time_t)t - dst_delta);
if (is_in_dst) { /* In fallback, force DST */
t -= dst_delta;
(void) offtime_u((time_t)t,
- -altzone, &_tm);
+ -altzone, &_tm);
_tm.tm_isdst = 1;
} else {
(void) offtime_u((time_t)t,
- -timezone, &_tm);
+ -timezone, &_tm);
}
}
break;
@@ -1088,16 +1086,16 @@ offtime_u(time_t t, long offset, struct tm *tmptr)
if (days < 0)
--newy;
days -= ((long)newy - (long)y) * DAYSPERNYEAR +
- LEAPS_THRU_END_OF(newy > 0 ? newy - 1L : newy) -
- LEAPS_THRU_END_OF(y > 0 ? y - 1L : y);
+ LEAPS_THRU_END_OF(newy > 0 ? newy - 1L : newy) -
+ LEAPS_THRU_END_OF(y > 0 ? y - 1L : y);
y = newy;
}
tmptr->tm_year = (int)(y - TM_YEAR_BASE);
tmptr->tm_yday = (int)days;
ip = __mon_lengths[yleap];
for (tmptr->tm_mon = 0; days >=
- (long)ip[tmptr->tm_mon]; ++(tmptr->tm_mon))
- days = days - (long)ip[tmptr->tm_mon];
+ (long)ip[tmptr->tm_mon]; ++(tmptr->tm_mon))
+ days = days - (long)ip[tmptr->tm_mon];
tmptr->tm_mday = (int)(days + 1);
tmptr->tm_isdst = 0;
@@ -1130,8 +1128,8 @@ posix_check_dst(long long t, state_t *sp)
year = gmttm.tm_year + 1900;
jan01 = t - ((gmttm.tm_yday * SECSPERDAY) +
- (gmttm.tm_hour * SECSPERHOUR) +
- (gmttm.tm_min * SECSPERMIN) + gmttm.tm_sec);
+ (gmttm.tm_hour * SECSPERHOUR) +
+ (gmttm.tm_min * SECSPERMIN) + gmttm.tm_sec);
/*
* If transition rules were provided for this zone,
* use them, otherwise, default to USA daylight rules,
@@ -1620,7 +1618,7 @@ load_posixinfo(const char *name, state_t *sp)
return (-1);
dstlen = name - dstname;
if (dstlen < 1)
- return (-1);
+ return (-1);
if (*name == '>')
++name;
if (*name != '\0' && *name != ',' && *name != ';') {
@@ -1810,13 +1808,13 @@ getzname(const char *strp, int quoted)
if (quoted) {
while ((c = *strp) != '\0' && c != '>' &&
- isgraph((unsigned char)c))
- ++strp;
+ isgraph((unsigned char)c))
+ ++strp;
} else {
while ((c = *strp) != '\0' && isgraph((unsigned char)c) &&
!isdigit((unsigned char)c) && c != ',' && c != '-' &&
- c != '+')
- ++strp;
+ c != '+')
+ ++strp;
}
/* Found an excessively invalid character. Discredit whole name */
@@ -1992,13 +1990,14 @@ get_default_tz(void)
char *tz = NULL;
uchar_t *tzp, *tzq;
int flags;
+ void *defp;
- if (defopen(TIMEZONE) == 0) {
- flags = defcntl(DC_GETFLAGS, 0);
+ if ((defp = defopen_r(TIMEZONE)) != NULL) {
+ flags = defcntl_r(DC_GETFLAGS, 0, defp);
TURNON(flags, DC_STRIP_QUOTES);
- (void) defcntl(DC_SETFLAGS, flags);
+ (void) defcntl_r(DC_SETFLAGS, flags, defp);
- if ((tzp = (uchar_t *)defread(TZSTRING)) != NULL) {
+ if ((tzp = (uchar_t *)defread_r(TZSTRING, defp)) != NULL) {
while (isspace(*tzp))
tzp++;
tzq = tzp;
@@ -2012,7 +2011,7 @@ get_default_tz(void)
tz = strdup((char *)tzp);
}
- (void) defopen(NULL);
+ defclose_r(defp);
}
return (tz);
}
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 484070680d..d241599a27 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -1429,9 +1429,13 @@ SUNWprivate_1.1 {
_D_cplx_div_ix;
_D_cplx_div_rx;
_D_cplx_mul;
+ defclose_r;
defcntl;
+ defcntl_r;
defopen;
+ defopen_r;
defread;
+ defread_r;
_delete;
_dgettext;
_doprnt;