diff options
author | vasiljevic <zv@archiware.com> | 2006-09-07 08:50:35 (GMT) |
---|---|---|
committer | vasiljevic <zv@archiware.com> | 2006-09-07 08:50:35 (GMT) |
commit | 6bf316cc8d180ece75a2b6b0af4594401fde93de (patch) | |
tree | 630550c33708da4db9bfae0e0d0e97e56d313261 | |
parent | 48340de4f3c6a13746e2c082d9ed8cf5c42b8a99 (diff) | |
download | tcl-6bf316cc8d180ece75a2b6b0af4594401fde93de.zip tcl-6bf316cc8d180ece75a2b6b0af4594401fde93de.tar.gz tcl-6bf316cc8d180ece75a2b6b0af4594401fde93de.tar.bz2 |
Rewritten MT-safe wrappers to return ptrs to TSD storage
-rw-r--r-- | ChangeLog | 30 | ||||
-rw-r--r-- | unix/tclUnixChan.c | 42 | ||||
-rw-r--r-- | unix/tclUnixCompat.c | 239 | ||||
-rw-r--r-- | unix/tclUnixFCmd.c | 58 | ||||
-rw-r--r-- | unix/tclUnixPort.h | 36 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 15 |
6 files changed, 185 insertions, 235 deletions
@@ -1,16 +1,24 @@ +2006-09-07 Zoran Vasiljevic <vasiljevic@users.sourceforge.net> + + * unix/tclUnixChan.c Rewritten MT-safe wrappers to + * unix/tclUnixCompat.c return ptrs to TSD storage + * unix/tclUnixFCmd.c making them all look like their + * unix/tclUnixPort.h MT-unsafe pendants API-wise. + * unix/tclUnixSock.c + 2006-09-06 Zoran Vasiljevic <vasiljevic@users.sourceforge.net> - * unix/tclUnixChan.c: Added TCL_THREADS ifdef'ed usage - * unix/tclUnixFCmd.c: of MT-safe calls like: - * unix/tclUnixSock.c: getpwuid, getpwnam, getgrgid, getgrnam, - * unix/tclUnixPort.h: gethostbyname and gethostbyaddr. - * unix/Makefile.in: See Tcl Bug: 999544 - * unix/configure.in: - * unix/tcl.m4: - * unix/configure: Regenerated. - - * unix/tclUnixCompat.c: New file containing MT-safe implementation - of some library calls. + * unix/tclUnixChan.c: Added TCL_THREADS ifdef'ed usage + * unix/tclUnixFCmd.c: of MT-safe calls like: + * unix/tclUnixSock.c: getpwuid, getpwnam, getgrgid, getgrnam, + * unix/tclUnixPort.h: gethostbyname and gethostbyaddr. + * unix/Makefile.in: See Tcl Bug: 999544 + * unix/configure.in: + * unix/tcl.m4: + * unix/configure: Regenerated. + + * unix/tclUnixCompat.c: New file containing MT-safe implementation + of some library calls. 2006-09-04 Don Porter <dgp@users.sourceforge.net> diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 22da743..0d2c046 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.42.2.8 2006/09/06 13:08:30 vasiljevic Exp $ + * RCS: @(#) $Id: tclUnixChan.c,v 1.42.2.9 2006/09/07 08:50:35 vasiljevic Exp $ */ #include "tclInt.h" /* Internal definitions for Tcl. */ @@ -2301,26 +2301,15 @@ TcpGetOptionProc(instanceData, interp, optionName, dsPtr) (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) { + if (hostEntPtr != (struct hostent *) NULL) { Tcl_DString ds; Tcl_ExternalToUtfDString(NULL, hostEntPtr->h_name, -1, &ds); @@ -2359,25 +2348,14 @@ TcpGetOptionProc(instanceData, interp, optionName, dsPtr) (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 != (struct hostent *) NULL) { Tcl_DString ds; @@ -2708,16 +2686,8 @@ CreateSocketAddress(sockaddrPtr, host, port) * on either 32 or 64 bits systems. */ if (addr.s_addr == 0xFFFFFFFF) { -#ifdef TCL_THREADS - int buflen = 1024, herrno; - char hbuf[1024]; - struct hostent he; - hostent = TclpGetHostByName( /* INTL: Native. */ - native, &he, hbuf, buflen, &herrno); -#else - hostent = gethostbyname(native); /* INTL: Native. */ -#endif - if (hostent != NULL) { + hostent = TclpGetHostByName(native); /* INTL: Native. */ + if (hostent != (struct hostent *) NULL) { memcpy((VOID *) &addr, (VOID *) hostent->h_addr_list[0], (size_t) hostent->h_length); diff --git a/unix/tclUnixCompat.c b/unix/tclUnixCompat.c index be13aaf..bb29c44 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.1.2.1 2006/09/06 13:24:32 vasiljevic Exp $ + * RCS: @(#) $Id: tclUnixCompat.c,v 1.1.2.2 2006/09/07 08:50:35 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 group *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 group *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->buf.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->buf.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->buf.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 581113d..dc003ce 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.28.2.11 2006/09/06 13:08:30 vasiljevic Exp $ + * RCS: @(#) $Id: tclUnixFCmd.c,v 1.28.2.12 2006/09/07 08:50:36 vasiljevic Exp $ * * Portions of this code were derived from NetBSD source code which has * the following copyright notice: @@ -1259,13 +1259,7 @@ GetGroupAttribute(interp, objIndex, fileName, attributePtrPtr) 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); @@ -1277,12 +1271,7 @@ GetGroupAttribute(interp, objIndex, fileName, attributePtrPtr) 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 (result == -1 || groupPtr == NULL) { *attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_gid); @@ -1323,13 +1312,7 @@ GetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr) 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); @@ -1341,12 +1324,7 @@ GetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr) 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 (result == -1 || pwPtr == NULL) { *attributePtrPtr = Tcl_NewIntObj((int) statBuf.st_uid); @@ -1435,24 +1413,13 @@ SetGroupAttribute(interp, objIndex, fileName, attributePtr) 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 + struct group *groupPtr; 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 (result == -1 || groupPtr == NULL) { @@ -1508,24 +1475,13 @@ SetOwnerAttribute(interp, objIndex, fileName, attributePtr) 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 + struct passwd *pwPtr; 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 (result == -1 || pwPtr == NULL) { diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index 52fa194..46d14fa 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.27.2.15 2006/09/06 13:08:30 vasiljevic Exp $ + * RCS: @(#) $Id: tclUnixPort.h,v 1.27.2.16 2006/09/07 08:50:36 vasiljevic Exp $ */ #ifndef _TCLUNIXPORT @@ -687,30 +687,22 @@ typedef int TclpMutex; /* - * 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> -EXTERN int -TclpGetPwNam(const char *name, struct passwd *pwbuf, char *buf, size_t buflen, - struct passwd **pwbufp); -EXTERN int -TclpGetPwUid(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, - struct passwd **pwbufp); -EXTERN int -TclpGetGrNam(const char *name, struct group *gbuf, char *buf, size_t buflen, - struct group **gbufp); -EXTERN int -TclpGetGrGid(gid_t gid, struct group *gbuf, char *buf, size_t buflen, - struct group **gbufp); - -EXTERN struct hostent * -TclpGetHostByName(const char *name, struct hostent *hbuf, char *buf, - size_t buflen, int *h_errnop); - -EXTERN struct hostent * -TclpGetHostByAddr(const char *addr, int length, int type, struct hostent *hbuf, - char *buf, size_t buflen, int *h_errnop); + +EXTERN struct passwd* TclpGetPwNam(const char *name); +EXTERN struct group* TclpGetGrNam(const char *name); +EXTERN struct passwd* TclpGetPwUid(uid_t uid); +EXTERN struct group* TclpGetGrGid(gid_t gid); +EXTERN struct hostent* TclpGetHostByName(const char *name); +EXTERN struct hostent* TclpGetHostByAddr(const char *addr, int length, int type); #include "tclPlatDecls.h" #include "tclIntPlatDecls.h" diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 8d6114f..eae4906 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.6.2.2 2006/09/06 13:08:30 vasiljevic Exp $ + * RCS: @(#) $Id: tclUnixSock.c,v 1.6.2.3 2006/09/07 08:50:36 vasiljevic Exp $ */ #include "tcl.h" @@ -88,12 +88,7 @@ Tcl_GetHostName() #ifndef NO_UNAME (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 @@ -105,11 +100,7 @@ Tcl_GetHostName() char *node = ckalloc((unsigned) (dot - u.nodename + 1)); 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); } } |