Bugzilla bug #2248: PR_ImportFile, PR_ImportTCPSocket, and
authorwtc%netscape.com
Fri, 08 Jan 1999 22:24:14 +0000
changeset 386 334adafd8c45e97eb1f212da74f76606665a0116
parent 385 27db748016a311675a62ab23764014d479e13747
child 387 6af983154475b96f74fa8948ddc0d71e0ceb450b
push idunknown
push userunknown
push dateunknown
bugs2248
Bugzilla bug #2248: PR_ImportFile, PR_ImportTCPSocket, and PR_ImportUDPSocket should initialize NSPR implicitly. Thanks to John McMullen <mcmullen@netscape.com> for the bug report and fix.
pr/src/io/prfile.c
pr/src/io/prsocket.c
pr/src/pthreads/ptio.c
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -405,16 +405,18 @@ PRInt32 rv;
 
 /*
 ** Import an existing OS file to NSPR 
 */
 PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
 {
     PRFileDesc *fd = NULL;
 
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
     fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
     if( !fd ) {
         (void) _PR_MD_CLOSE_FILE(osfd);
     }
 
     return fd;
 }
 
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -162,28 +162,30 @@ PRInt32 iov_size, PRIntervalTime timeout
 }
 
 /************************************************************************/
 
 PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPSocket(PRInt32 osfd)
 {
 PRFileDesc *fd;
 
+	if (!_pr_initialized) _PR_ImplicitInitialization();
 	fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
 	if (fd != NULL)
 		_PR_MD_MAKE_NONBLOCK(fd);
 	else
 		_PR_MD_CLOSE_SOCKET(osfd);
 	return(fd);
 }
 
 PR_IMPLEMENT(PRFileDesc *) PR_ImportUDPSocket(PRInt32 osfd)
 {
 PRFileDesc *fd;
 
+	if (!_pr_initialized) _PR_ImplicitInitialization();
 	fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
 	if (fd != NULL)
 		_PR_MD_MAKE_NONBLOCK(fd);
 	else
 		_PR_MD_CLOSE_SOCKET(osfd);
 	return(fd);
 }
 
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -3276,31 +3276,40 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritab
 }
 
 /*****************************************************************************/
 /***************************** I/O friends methods ***************************/
 /*****************************************************************************/
 
 PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
 {
-    PRFileDesc *fd = pt_SetMethods(osfd, PR_DESC_FILE);
+    PRFileDesc *fd;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    fd = pt_SetMethods(osfd, PR_DESC_FILE);
     if (NULL == fd) close(osfd);
     return fd;
 }  /* PR_ImportFile */
 
 PR_IMPLEMENT(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd)
 {
-    PRFileDesc *fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP);
+    PRFileDesc *fd;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP);
     if (NULL == fd) close(osfd);
     return fd;
 }  /* PR_ImportTCPSocket */
 
 PR_IMPLEMENT(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd)
 {
-    PRFileDesc *fd = pt_SetMethods(osfd, PR_DESC_SOCKET_UDP);
+    PRFileDesc *fd;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    fd = pt_SetMethods(osfd, PR_DESC_SOCKET_UDP);
     if (NULL != fd) close(osfd);
     return fd;
 }  /* PR_ImportUDPSocket */
 
 PR_IMPLEMENT(PRInt32) PR_FileDesc2NativeHandle(PRFileDesc *bottom)
 {
     PRInt32 osfd = -1;
     bottom = (NULL == bottom) ?