summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorvasiljevic <zv@archiware.com>2006-09-07 09:17:33 (GMT)
committervasiljevic <zv@archiware.com>2006-09-07 09:17:33 (GMT)
commit8d7192b9bb9fcda7acb42ef68a34c1a743902686 (patch)
tree24a87d9260aeac9825379096d9dfb97726dcc486 /unix
parenta997d1ebf0d281c2f1e2d4351b2c08ef1411cf8e (diff)
downloadtcl-8d7192b9bb9fcda7acb42ef68a34c1a743902686.zip
tcl-8d7192b9bb9fcda7acb42ef68a34c1a743902686.tar.gz
tcl-8d7192b9bb9fcda7acb42ef68a34c1a743902686.tar.bz2
Rewritten MT-safe wrappers to return ptrs to TSD storage.
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixChan.c28
-rw-r--r--unix/tclUnixCompat.c239
-rw-r--r--unix/tclUnixFCmd.c54
-rw-r--r--unix/tclUnixPort.h37
-rw-r--r--unix/tclUnixSock.c20
5 files changed, 161 insertions, 217 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index 5a0d40b..df51411 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixChan.c,v 1.71 2006/09/06 13:23:37 vasiljevic Exp $
+ * RCS: @(#) $Id: tclUnixChan.c,v 1.72 2006/09/07 09:17:33 vasiljevic Exp $
*/
#include "tclInt.h" /* Internal definitions for Tcl. */
@@ -2266,25 +2266,14 @@ TcpGetOptionProc(
(strncmp(optionName, "-peername", len) == 0))) {
if (getpeername(statePtr->fd, (struct sockaddr *) &peername,
&size) >= 0) {
-#ifdef TCL_THREADS
- int buflen = 1024, herrno;
- char hbuf[1024];
- struct hostent he;
-#endif
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-peername");
Tcl_DStringStartSublist(dsPtr);
}
Tcl_DStringAppendElement(dsPtr, inet_ntoa(peername.sin_addr));
-#ifdef TCL_THREADS
- hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */
- (char *) &peername.sin_addr, sizeof(peername.sin_addr),
- AF_INET, &he, hbuf, buflen, &herrno);
-#else
- hostEntPtr = gethostbyaddr( /* INTL: Native. */
+ hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */
(char *) &peername.sin_addr,
sizeof(peername.sin_addr), AF_INET);
-#endif
if (hostEntPtr != NULL) {
Tcl_DString ds;
@@ -2324,25 +2313,14 @@ TcpGetOptionProc(
(strncmp(optionName, "-sockname", len) == 0))) {
if (getsockname(statePtr->fd, (struct sockaddr *) &sockname,
&size) >= 0) {
-#ifdef TCL_THREADS
- int buflen = 1024, herrno;
- char hbuf[1024];
- struct hostent he;
-#endif
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-sockname");
Tcl_DStringStartSublist(dsPtr);
}
Tcl_DStringAppendElement(dsPtr, inet_ntoa(sockname.sin_addr));
-#ifdef TCL_THREADS
- hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */
- (char *) &sockname.sin_addr, sizeof(sockname.sin_addr),
- AF_INET, &he, hbuf, buflen, &herrno);
-#else
- hostEntPtr = gethostbyaddr( /* INTL: Native. */
+ hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */
(char *) &sockname.sin_addr,
sizeof(sockname.sin_addr), AF_INET);
-#endif
if (hostEntPtr != NULL) {
Tcl_DString ds;
diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c
index 691264f..0fc0903 100644
--- a/unix/tclUnixCompat.c
+++ b/unix/tclUnixCompat.c
@@ -6,7 +6,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixCompat.c,v 1.2 2006/09/06 13:25:29 vasiljevic Exp $
+ * RCS: @(#) $Id: tclUnixCompat.c,v 1.3 2006/09/07 09:17:33 vasiljevic Exp $
*
*/
@@ -18,6 +18,26 @@
#include <string.h>
/*
+ * Per-thread private storage used to store values
+ * returned from MT-unsafe library calls.
+ */
+
+typedef struct ThreadSpecificData {
+
+ struct passwd pwd;
+ char pbuf[2048];
+
+ struct group grp;
+ char gbuf[2048];
+
+ struct hostent hent;
+ char hbuf[2048];
+
+} ThreadSpecificData;
+
+static Tcl_ThreadDataKey dataKey;
+
+/*
* Mutex to lock access to MT-unsafe calls. This is just to protect
* our own usage. It does not protect us from others calling the
* same functions without (or using some different) lock.
@@ -34,8 +54,8 @@ Tcl_Mutex compatLock;
*
* CopyArray --
*
- * Copies array of strings (or fixed values) to the
- * private buffer, honouring the size of the buffer.
+ * Copies array of NULL-terminated or fixed-length strings
+ * to the private buffer, honouring the size of the buffer.
*
* Results:
* Number of bytes copied on success or -1 on error (errno = ERANGE)
@@ -92,8 +112,8 @@ CopyArray(char **src, int elsize, char *buf, int buflen)
*
* CopyString --
*
- * Copies a string to the private buffer, honouring the
- * size of the buffer
+ * Copies a NULL-terminated string to the private buffer,
+ * honouring the size of the buffer
*
* Results:
* 0 success or -1 on error (errno = ERANGE)
@@ -305,7 +325,7 @@ CopyGrp(struct group *tgtPtr, char *buf, int buflen)
* See "man getpwnam" for more details.
*
* Results:
- * 0 on success or -1 on error.
+ * Pointer to struct passwd on success or NULL on error.
*
* Side effects:
* None.
@@ -313,33 +333,34 @@ CopyGrp(struct group *tgtPtr, char *buf, int buflen)
*---------------------------------------------------------------------------
*/
-int
-TclpGetPwNam(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
- struct passwd **pwbufp)
+struct passwd *
+TclpGetPwNam(const char *name)
{
- int result = 0;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWNAM_R_5)
- result = getpwnam_r(name, pwbuf, buf, buflen, pwbufp);
+ struct passwd *pwPtr;
+ return (getpwnam_r(name, &tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf),
+ &pwPtr) == 0) ? &tsdPtr->pwd : NULL;
+
#elif defined(HAVE_GETPWNAM_R_4)
- *pwbufp = getpwnam_r(name, pwbuf, buf, buflen);
- if (*pwbufp == NULL) {
- result = -1;
- }
+ return getpwnam_r(name, &tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf));
+
#else
- struct passwd *pwPtr = NULL;
+ struct passwd *pwPtr;
Tcl_MutexLock(&compatLock);
pwPtr = getpwnam(name);
- if (pwPtr == NULL) {
- result = -1;
- } else {
- *pwbuf = *pwPtr;
- *pwbufp = pwbuf;
- result = CopyPwd(pwbuf, buf, buflen);
+ if (pwPtr != NULL) {
+ tsdPtr->pwd = *pwPtr;
+ pwPtr = &tsdPtr->pwd;
+ if (CopyPwd(&tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf)) == -1) {
+ pwPtr = NULL;
+ }
}
Tcl_MutexUnlock(&compatLock);
+ return pwPtr;
#endif
- return result;
+ return NULL; /* Not reached */
}
@@ -352,7 +373,7 @@ TclpGetPwNam(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
* See "man getpwuid" for more details.
*
* Results:
- * 0 on success or -1 on error.
+ * Pointer to struct passwd on success or NULL on error.
*
* Side effects:
* None.
@@ -360,33 +381,34 @@ TclpGetPwNam(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
*---------------------------------------------------------------------------
*/
-int
-TclpGetPwUid(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen,
- struct passwd **pwbufp)
+struct passwd *
+TclpGetPwUid(uid_t uid)
{
- int result = 0;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWUID_R_5)
- result = getpwuid_r(uid, pwbuf, buf, buflen, pwbufp);
+ struct passwd *pwPtr;
+ return (getpwuid_r(uid, &tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf),
+ &pwPtr) == 0) ? &tsdPtr->pwd : NULL;
+
#elif defined(HAVE_GETPWUID_R_4)
- *pwbufp = getpwuid_r(uid, pwbuf, buf, buflen);
- if (*pwbufp == NULL) {
- result = -1;
- }
+ return getpwuid_r(uid, &tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf));
+
#else
- struct passwd *pwPtr = NULL;
+ struct passwd *pwPtr;
Tcl_MutexLock(&compatLock);
pwPtr = getpwuid(uid);
- if (pwPtr == NULL) {
- result = -1;
- } else {
- *pwbuf = *pwPtr;
- *pwbufp = pwbuf;
- result = CopyPwd(pwbuf, buf, buflen);
+ if (pwPtr != NULL) {
+ tsdPtr->pwd = *pwPtr;
+ pwPtr = &tsdPtr->pwd;
+ if (CopyPwd(&tsdPtr->pwd, tsdPtr->pbuf, sizeof(tsdPtr->pbuf)) == -1) {
+ pwPtr = NULL;
+ }
}
Tcl_MutexUnlock(&compatLock);
+ return pwPtr;
#endif
- return result;
+ return NULL; /* Not reached */
}
@@ -399,7 +421,7 @@ TclpGetPwUid(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen,
* See "man getgrnam" for more details.
*
* Results:
- * 0 on success or -1 on error.
+ * Pointer to struct group on success or NULL on error.
*
* Side effects:
* None.
@@ -407,33 +429,34 @@ TclpGetPwUid(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen,
*---------------------------------------------------------------------------
*/
-int
-TclpGetGrNam(const char *name, struct group *gbuf, char *buf, size_t buflen,
- struct group **gbufp)
+struct group *
+TclpGetGrNam(const char *name)
{
- int result = 0;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRNAM_R_5)
- result = getgrnam_r(name, gbuf, buf, buflen, gbufp);
+ struct group *grPtr;
+ return (getgrnam_r(name, &tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf),
+ &grPtr) == 0) ? &tsdPtr->grp : NULL;
+
#elif defined(HAVE_GETGRNAM_R_4)
- *gbufp = getgrgid_r(name, gbuf, buf, buflen);
- if (*gbufp == NULL) {
- result = -1;
- }
+ return getgrnam_r(name, &tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf));
+
#else
- struct group *grPtr = NULL;
+ struct group *grPtr;
Tcl_MutexLock(&compatLock);
grPtr = getgrnam(name);
- if (grPtr == NULL) {
- result = -1;
- } else {
- *gbuf = *grPtr;
- *gbufp = gbuf;
- result = CopyGrp(gbuf, buf, buflen);
+ if (grPtr != NULL) {
+ tsdPtr->grp = *grPtr;
+ grPtr = &tsdPtr->grp;
+ if (CopyGrp(&tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf)) == -1) {
+ grPtr = NULL;
+ }
}
Tcl_MutexUnlock(&compatLock);
+ return grPtr;
#endif
- return result;
+ return NULL; /* Not reached */
}
@@ -446,7 +469,7 @@ TclpGetGrNam(const char *name, struct group *gbuf, char *buf, size_t buflen,
* See "man getgrgid" for more details.
*
* Results:
- * 0 on success or -1 on error.
+ * Pointer to struct group on success or NULL on error.
*
* Side effects:
* None.
@@ -454,33 +477,34 @@ TclpGetGrNam(const char *name, struct group *gbuf, char *buf, size_t buflen,
*---------------------------------------------------------------------------
*/
-int
-TclpGetGrGid(gid_t gid, struct group *gbuf, char *buf, size_t buflen,
- struct group **gbufp)
+struct group *
+TclpGetGrGid(gid_t gid)
{
- int result = 0;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRGID_R_5)
- result = getgrgid_r(gid, gbuf, buf, buflen, gbufp);
+ struct group *grPtr;
+ return (getgrgid_r(gid, &tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf),
+ &grPtr) == 0) ? &tsdPtr->grp : NULL;
+
#elif defined(HAVE_GETGRGID_R_4)
- *gbufp = getgrgid_r(gid, gbuf, buf, buflen);
- if (*gbufp == NULL) {
- result = -1;
- }
+ return getgrgid_r(gid, &tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf));
+
#else
- struct group *grPtr = NULL;
+ struct group *grPtr;
Tcl_MutexLock(&compatLock);
grPtr = getgrgid(gid);
- if (grPtr == NULL) {
- result = -1;
- } else {
- *gbuf = *grPtr;
- *gbufp = gbuf;
- result = CopyGrp(gbuf, buf, buflen);
+ if (grPtr != NULL) {
+ tsdPtr->grp = *grPtr;
+ grPtr = &tsdPtr->grp;
+ if (CopyGrp(&tsdPtr->grp, tsdPtr->gbuf, sizeof(tsdPtr->gbuf)) == -1) {
+ grPtr = NULL;
+ }
}
Tcl_MutexUnlock(&compatLock);
+ return grPtr;
#endif
- return result;
+ return NULL; /* Not reached */
}
@@ -502,33 +526,36 @@ TclpGetGrGid(gid_t gid, struct group *gbuf, char *buf, size_t buflen,
*/
struct hostent *
-TclpGetHostByName(const char *name, struct hostent *hbuf, char *buf,
- size_t buflen, int *h_errnop)
+TclpGetHostByName(const char *name)
{
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+
#if defined(HAVE_GETHOSTBYNAME_R_5)
- return gethostbyname_r(name, hbuf, buf, buflen, h_errnop);
+ int h_errno;
+ return gethostbyname_r(name, &tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf), &h_errno);
+
#elif defined(HAVE_GETHOSTBYNAME_R_6)
struct hostent *hePtr;
- return (gethostbyname_r(name, hbuf, buf, buflen, &hePtr,
- h_errnop) == 0) ? hbuf : NULL;
+ int h_errno;
+ return (gethostbyname_r(name, &tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf), &hePtr, &h_errno) == 0) ?
+ &tsdPtr->hent : NULL;
+
#elif defined(HAVE_GETHOSTBYNAME_R_3)
struct hostent_data data;
- if (-1 == gethostbyname_r(host, hbuf, &data)) {
- *h_errnop = h_errno;
- return NULL;
- } else {
- return &hbuf;
- }
+ return (gethostbyname_r(host, &tsdPtr->hent, &data) == 0) ?
+ &tsdPtr->buf.hent : NULL;
#else
- struct hostent *hePtr = NULL;
+ struct hostent *hePtr;
Tcl_MutexLock(&compatLock);
hePtr = gethostbyname(name);
if (hePtr != NULL) {
- *hbuf = *hePtr;
- if (-1 == CopyHostent(hbuf, buf, buflen)) {
+ tsdPtr->hent = *hePtr;
+ hePtr = &tsdPtr->hent;
+ if (CopyHostent(&tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf)) == -1) {
hePtr = NULL;
- } else {
- hePtr = hbuf;
}
}
Tcl_MutexUnlock(&compatLock);
@@ -556,25 +583,31 @@ TclpGetHostByName(const char *name, struct hostent *hbuf, char *buf,
*/
struct hostent *
-TclpGetHostByAddr(const char *addr, int length, int type, struct hostent *hbuf,
- char *buf, size_t buflen, int *h_errnop)
+TclpGetHostByAddr(const char *addr, int length, int type)
{
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+
#if defined(HAVE_GETHOSTBYADDR_R_7)
- return gethostbyaddr_r(addr, length, type, hbuf, buf, buflen, h_errnop);
+ int h_errno;
+ return gethostbyaddr_r(addr, length, type, &tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf), &h_errno);
+
#elif defined(HAVE_GETHOSTBYADDR_R_8)
struct hostent *hePtr;
- return (gethostbyaddr_r(addr, length, type, hbuf, buf, buflen,
- &hePtr, h_errnop) == 0) ? hbuf : NULL;
+ int h_errno;
+ return (gethostbyaddr_r(addr, length, type, &tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf), &hePtr, &h_errno) == 0) ?
+ &tsdPtr->hent : NULL;
#else
- struct hostent *hePtr = NULL;
+ struct hostent *hePtr;
Tcl_MutexLock(&compatLock);
hePtr = gethostbyaddr(addr, length, type);
if (hePtr != NULL) {
- *hbuf = *hePtr;
- if (-1 == CopyHostent(hbuf, buf, buflen)) {
+ tsdPtr->hent = *hePtr;
+ hePtr = &tsdPtr->hent;
+ if (CopyHostent(&tsdPtr->hent, tsdPtr->hbuf,
+ sizeof(tsdPtr->hbuf)) == -1) {
hePtr = NULL;
- } else {
- hePtr = hbuf;
}
}
Tcl_MutexUnlock(&compatLock);
diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c
index a517da7..9cd2e1e 100644
--- a/unix/tclUnixFCmd.c
+++ b/unix/tclUnixFCmd.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixFCmd.c,v 1.55 2006/09/06 13:23:37 vasiljevic Exp $
+ * RCS: @(#) $Id: tclUnixFCmd.c,v 1.56 2006/09/07 09:17:33 vasiljevic Exp $
*
* Portions of this code were derived from NetBSD source code which has the
* following copyright notice:
@@ -1290,13 +1290,7 @@ GetGroupAttribute(
Tcl_Obj **attributePtrPtr) /* A pointer to return the object with. */
{
Tcl_StatBuf statBuf;
-#ifdef TCL_THREADS
- int buflen = 512;
- char buf[512]; /* Should be really using sysconf() to get this size */
- struct group gr, *groupPtr = NULL;
-#else
struct group *groupPtr;
-#endif
int result;
result = TclpObjStat(fileName, &statBuf);
@@ -1310,12 +1304,7 @@ GetGroupAttribute(
return TCL_ERROR;
}
-#ifdef TCL_THREADS
- result = TclpGetGrGid(statBuf.st_gid, &gr, buf, buflen, &groupPtr);
-#else
- groupPtr = getgrgid(statBuf.st_gid);
- result = 0;
-#endif
+ groupPtr = TclpGetGrGid(statBuf.st_gid);
if (groupPtr == NULL) {
*attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_gid);
@@ -1356,13 +1345,7 @@ GetOwnerAttribute(
Tcl_Obj **attributePtrPtr) /* A pointer to return the object with. */
{
Tcl_StatBuf statBuf;
-#ifdef TCL_THREADS
- int buflen = 512;
- char buf[512]; /* Should be really using sysconf() to get this size */
- struct passwd pw, *pwPtr = NULL;
-#else
struct passwd *pwPtr;
-#endif
int result;
result = TclpObjStat(fileName, &statBuf);
@@ -1376,12 +1359,7 @@ GetOwnerAttribute(
return TCL_ERROR;
}
-#ifdef TCL_THREADS
- result = TclpGetPwUid(statBuf.st_uid, &pw, buf, buflen, &pwPtr);
-#else
- pwPtr = getpwuid(statBuf.st_uid);
- result = 0;
-#endif
+ pwPtr = TclpGetPwUid(statBuf.st_uid);
if (pwPtr == NULL) {
*attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_uid);
@@ -1471,25 +1449,14 @@ SetGroupAttribute(
if (Tcl_GetLongFromObj(NULL, attributePtr, &gid) != TCL_OK) {
Tcl_DString ds;
-#ifdef TCL_THREADS
- int buflen = 512; /* Should be really using sysconf() to get this size */
- char buf[512];
- struct group gr, *groupPtr = NULL;
-#else
struct group *groupPtr = NULL;
-#endif
CONST char *string;
int length;
string = Tcl_GetStringFromObj(attributePtr, &length);
native = Tcl_UtfToExternalDString(NULL, string, length, &ds);
-#ifdef TCL_THREADS
- result = TclpGetGrNam(native, &gr, buf, buflen, &groupPtr); /* INTL: Native. */
-#else
- groupPtr = getgrnam(native); /* INTL: Native. */
- result = 0;
-#endif
+ groupPtr = TclpGetGrNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (groupPtr == NULL) {
@@ -1548,25 +1515,14 @@ SetOwnerAttribute(
if (Tcl_GetLongFromObj(NULL, attributePtr, &uid) != TCL_OK) {
Tcl_DString ds;
-#ifdef TCL_THREADS
- int buflen = 512;
- char buf[512]; /* Should be really using sysconf() to get this size */
- struct passwd pw, *pwPtr = NULL;
-#else
struct passwd *pwPtr = NULL;
-#endif
CONST char *string;
int length;
string = Tcl_GetStringFromObj(attributePtr, &length);
native = Tcl_UtfToExternalDString(NULL, string, length, &ds);
-#ifdef TCL_THREADS
- result = TclpGetPwNam(native, &pw, buf, buflen, &pwPtr); /* INTL: Native. */
-#else
- pwPtr = getpwnam(native); /* INTL: Native. */
- result = 0;
-#endif
+ pwPtr = TclpGetPwNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (pwPtr == NULL) {
diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h
index 533f205..285533b 100644
--- a/unix/tclUnixPort.h
+++ b/unix/tclUnixPort.h
@@ -19,7 +19,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixPort.h,v 1.53 2006/09/06 16:12:14 vasiljevic Exp $
+ * RCS: @(#) $Id: tclUnixPort.h,v 1.54 2006/09/07 09:17:33 vasiljevic Exp $
*/
#ifndef _TCLUNIXPORT
@@ -652,31 +652,22 @@ EXTERN int pthread_getattr_np _ANSI_ARGS_((pthread_t, pthread_attr_t *));
# endif /* HAVE_PTHREAD_ATTR_GET_NP */
#endif /* TCL_THREADS */
-
/*
- * Compatibility calls
+ * Set of MT-safe implementations of some
+ * known-to-be-MT-unsafe library calls.
+ * Instead of returning pointers to the
+ * static storage, those return pointers
+ * to the TSD data.
*/
+
#include <pwd.h>
#include <grp.h>
-MODULE_SCOPE int
-TclpGetPwNam(const char *name, struct passwd *pwbuf, char *buf, size_t buflen,
- struct passwd **pwbufp);
-MODULE_SCOPE int
-TclpGetPwUid(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen,
- struct passwd **pwbufp);
-MODULE_SCOPE int
-TclpGetGrNam(const char *name, struct group *gbuf, char *buf, size_t buflen,
- struct group **gbufp);
-MODULE_SCOPE int
-TclpGetGrGid(gid_t gid, struct group *gbuf, char *buf, size_t buflen,
- struct group **gbufp);
-
-MODULE_SCOPE struct hostent *
-TclpGetHostByName(const char *name, struct hostent *hbuf, char *buf,
- size_t buflen, int *h_errnop);
-
-MODULE_SCOPE struct hostent *
-TclpGetHostByAddr(const char *addr, int length, int type, struct hostent *hbuf,
- char *buf, size_t buflen, int *h_errnop);
+
+MODULE_SCOPE struct passwd* TclpGetPwNam(const char *name);
+MODULE_SCOPE struct group* TclpGetGrNam(const char *name);
+MODULE_SCOPE struct passwd* TclpGetPwUid(uid_t uid);
+MODULE_SCOPE struct group* TclpGetGrGid(gid_t gid);
+MODULE_SCOPE struct hostent* TclpGetHostByName(const char *name);
+MODULE_SCOPE struct hostent* TclpGetHostByAddr(const char *addr, int length, int type);
#endif /* _TCLUNIXPORT */
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 961110e..819fca6 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixSock.c,v 1.16 2006/09/06 13:23:37 vasiljevic Exp $
+ * RCS: @(#) $Id: tclUnixSock.c,v 1.17 2006/09/07 09:17:33 vasiljevic Exp $
*/
#include "tclInt.h"
@@ -43,11 +43,6 @@ InitializeHostName(
Tcl_Encoding *encodingPtr)
{
CONST char *native = NULL;
-#ifdef TCL_THREADS
- int buflen = 1024, herrno;
- char buf[1024];
- struct hostent he;
-#endif
#ifndef NO_UNAME
struct utsname u;
@@ -55,12 +50,7 @@ InitializeHostName(
(void *) memset((void *) &u, (int) 0, sizeof(struct utsname));
if (uname(&u) > -1) { /* INTL: Native. */
-#ifdef TCL_THREADS
- hp = TclpGetHostByName( /* INTL: Native. */
- u.nodename, &he, buf, buflen, &herrno);
-#else
- hp = gethostbyname(u.nodename); /* INTL: Native. */
-#endif
+ hp = TclpGetHostByName(u.nodename); /* INTL: Native. */
if (hp == NULL) {
/*
* Sometimes the nodename is fully qualified, but gets truncated
@@ -75,11 +65,7 @@ InitializeHostName(
memcpy(node, u.nodename, (size_t) (dot - u.nodename));
node[dot - u.nodename] = '\0';
-#ifdef TCL_THREADS
- hp = TclpGetHostByName(node, &he, buf, buflen, &herrno);
-#else
- hp = gethostbyname(node);
-#endif
+ hp = TclpGetHostByName(node);
ckfree(node);
}
}