mirror of
https://github.com/reactos/reactos.git
synced 2024-07-12 07:35:10 +00:00
[MSVCRT][CRT]: Improvements/fixes over popen(), from Wine code and ported by Andreas Maier: the popen_handles array, which is used in _pclose, was never filled. _popen correctly fills it now.
Should fix returned codes by popen() and pclose(), which are functions that are called by windres, and this latter expects them to succeed. This was not the case before, in ROS, and therefore trying to e.g. compile ROS within ROS failed from time to time with windres throwing the error that "preprocessing failed". CORE-11568 #resolve svn path=/trunk/; revision=75365
This commit is contained in:
parent
73375485df
commit
1345a5a8a7
|
@ -161,6 +161,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
||||||
/* Deinit of the WINE code */
|
/* Deinit of the WINE code */
|
||||||
msvcrt_free_io();
|
msvcrt_free_io();
|
||||||
if (reserved) break;
|
if (reserved) break;
|
||||||
|
msvcrt_free_popen_data();
|
||||||
msvcrt_free_mt_locks();
|
msvcrt_free_mt_locks();
|
||||||
//msvcrt_free_console();
|
//msvcrt_free_console();
|
||||||
//msvcrt_free_args();
|
//msvcrt_free_args();
|
||||||
|
|
|
@ -98,6 +98,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
||||||
/* Deinit of the WINE code */
|
/* Deinit of the WINE code */
|
||||||
msvcrt_free_io();
|
msvcrt_free_io();
|
||||||
if (reserved) break;
|
if (reserved) break;
|
||||||
|
msvcrt_free_popen_data();
|
||||||
msvcrt_free_mt_locks();
|
msvcrt_free_mt_locks();
|
||||||
//msvcrt_free_console();
|
//msvcrt_free_console();
|
||||||
//msvcrt_free_args();
|
//msvcrt_free_args();
|
||||||
|
|
|
@ -117,6 +117,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
||||||
/* Deinit of the WINE code */
|
/* Deinit of the WINE code */
|
||||||
msvcrt_free_io();
|
msvcrt_free_io();
|
||||||
if (reserved) break;
|
if (reserved) break;
|
||||||
|
msvcrt_free_popen_data();
|
||||||
msvcrt_free_mt_locks();
|
msvcrt_free_mt_locks();
|
||||||
//msvcrt_free_console();
|
//msvcrt_free_console();
|
||||||
//msvcrt_free_args();
|
//msvcrt_free_args();
|
||||||
|
|
|
@ -113,6 +113,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
||||||
/* Deinit of the WINE code */
|
/* Deinit of the WINE code */
|
||||||
msvcrt_free_io();
|
msvcrt_free_io();
|
||||||
if (reserved) break;
|
if (reserved) break;
|
||||||
|
msvcrt_free_popen_data();
|
||||||
msvcrt_free_mt_locks();
|
msvcrt_free_mt_locks();
|
||||||
//msvcrt_free_console();
|
//msvcrt_free_console();
|
||||||
//msvcrt_free_args();
|
//msvcrt_free_args();
|
||||||
|
|
15
reactos/sdk/lib/crt/include/internal/popen.h
Normal file
15
reactos/sdk/lib/crt/include/internal/popen.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef __CRT_INTERNAL_POPEN_H
|
||||||
|
#define __CRT_INTERNAL_POPEN_H
|
||||||
|
|
||||||
|
#ifndef _CRT_PRECOMP_H
|
||||||
|
#error DO NOT INCLUDE THIS HEADER DIRECTLY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct popen_handle {
|
||||||
|
FILE *f;
|
||||||
|
HANDLE proc;
|
||||||
|
};
|
||||||
|
extern struct popen_handle *popen_handles;
|
||||||
|
extern DWORD popen_handles_size;
|
||||||
|
|
||||||
|
#endif
|
|
@ -95,6 +95,7 @@ extern void msvcrt_init_args(void);
|
||||||
extern void msvcrt_free_args(void);
|
extern void msvcrt_free_args(void);
|
||||||
extern void msvcrt_init_signals(void);
|
extern void msvcrt_init_signals(void);
|
||||||
extern void msvcrt_free_signals(void);
|
extern void msvcrt_free_signals(void);
|
||||||
|
extern void msvcrt_free_popen_data(void);
|
||||||
|
|
||||||
extern unsigned create_io_inherit_block(WORD*, BYTE**);
|
extern unsigned create_io_inherit_block(WORD*, BYTE**);
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
||||||
#include <internal/mbstring.h>
|
#include <internal/mbstring.h>
|
||||||
#include <internal/misc.h>
|
#include <internal/misc.h>
|
||||||
#include <internal/mtdll.h>
|
#include <internal/mtdll.h>
|
||||||
|
#include <internal/popen.h>
|
||||||
#include <internal/rterror.h>
|
#include <internal/rterror.h>
|
||||||
#include <internal/safecrt.h>
|
#include <internal/safecrt.h>
|
||||||
#include <internal/time.h>
|
#include <internal/time.h>
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS C runtime library
|
* PROJECT: ReactOS C runtime library
|
||||||
* FILE: lib/sdk/crt/stdio/popen.c
|
* FILE: lib/sdk/crt/stdio/popen.c
|
||||||
* PURPOSE: Pipe Functions
|
* PURPOSE: Pipe Functions
|
||||||
* PROGRAMERS: Eric Kohl
|
* PROGRAMMERS: Eric Kohl
|
||||||
Hartmut Birr
|
* Hartmut Birr
|
||||||
*/
|
* Also adapted from Wine team code by Andreas Maier.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
@ -22,11 +23,13 @@ int msvcrt_alloc_fd(HANDLE hand, int flag); //FIXME: Remove
|
||||||
unsigned split_oflags(unsigned oflags); //FIXME: Remove
|
unsigned split_oflags(unsigned oflags); //FIXME: Remove
|
||||||
|
|
||||||
#ifndef _UNICODE
|
#ifndef _UNICODE
|
||||||
static struct popen_handle {
|
struct popen_handle *popen_handles = NULL;
|
||||||
FILE *f;
|
DWORD popen_handles_size = 0;
|
||||||
HANDLE proc;
|
|
||||||
} *popen_handles;
|
void msvcrt_free_popen_data(void)
|
||||||
static DWORD popen_handles_size;
|
{
|
||||||
|
free(popen_handles);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,12 +40,14 @@ FILE *_tpopen (const _TCHAR *cm, const _TCHAR *md) /* program name, pipe mode */
|
||||||
_TCHAR *szCmdLine=NULL;
|
_TCHAR *szCmdLine=NULL;
|
||||||
_TCHAR *szComSpec=NULL;
|
_TCHAR *szComSpec=NULL;
|
||||||
_TCHAR *s;
|
_TCHAR *s;
|
||||||
FILE *pf;
|
FILE *ret;
|
||||||
HANDLE hReadPipe, hWritePipe;
|
HANDLE hReadPipe, hWritePipe;
|
||||||
BOOL result;
|
BOOL result;
|
||||||
STARTUPINFO StartupInfo;
|
STARTUPINFO StartupInfo;
|
||||||
PROCESS_INFORMATION ProcessInformation;
|
PROCESS_INFORMATION ProcessInformation;
|
||||||
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
|
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
|
||||||
|
struct popen_handle *container;
|
||||||
|
DWORD i;
|
||||||
|
|
||||||
TRACE(MK_STR(_tpopen)"('%"sT"', '%"sT"')\n", cm, md);
|
TRACE(MK_STR(_tpopen)"('%"sT"', '%"sT"')\n", cm, md);
|
||||||
|
|
||||||
|
@ -80,6 +85,7 @@ FILE *_tpopen (const _TCHAR *cm, const _TCHAR *md) /* program name, pipe mode */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&ProcessInformation, 0, sizeof(ProcessInformation));
|
||||||
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
|
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
|
||||||
StartupInfo.cb = sizeof(STARTUPINFO);
|
StartupInfo.cb = sizeof(STARTUPINFO);
|
||||||
|
|
||||||
|
@ -117,20 +123,47 @@ FILE *_tpopen (const _TCHAR *cm, const _TCHAR *md) /* program name, pipe mode */
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(ProcessInformation.hThread);
|
CloseHandle(ProcessInformation.hThread);
|
||||||
CloseHandle(ProcessInformation.hProcess);
|
|
||||||
|
_mlock(_POPEN_LOCK);
|
||||||
|
for(i=0; i<popen_handles_size; i++)
|
||||||
|
{
|
||||||
|
if (!popen_handles[i].f)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i==popen_handles_size)
|
||||||
|
{
|
||||||
|
i = (popen_handles_size ? popen_handles_size*2 : 8);
|
||||||
|
container = realloc(popen_handles, i*sizeof(*container));
|
||||||
|
if (!container) goto error;
|
||||||
|
|
||||||
|
popen_handles = container;
|
||||||
|
container = popen_handles+popen_handles_size;
|
||||||
|
memset(container, 0, (i-popen_handles_size)*sizeof(*container));
|
||||||
|
popen_handles_size = i;
|
||||||
|
}
|
||||||
|
else container = popen_handles+i;
|
||||||
|
|
||||||
if ( *md == 'r' )
|
if ( *md == 'r' )
|
||||||
{
|
{
|
||||||
pf = _tfdopen(msvcrt_alloc_fd(hReadPipe, split_oflags(_fmode)) , _T("r"));
|
ret = _tfdopen(msvcrt_alloc_fd(hReadPipe, split_oflags(_fmode)) , _T("r"));
|
||||||
CloseHandle(hWritePipe);
|
CloseHandle(hWritePipe);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pf = _tfdopen( msvcrt_alloc_fd(hWritePipe, split_oflags(_fmode)) , _T("w"));
|
ret = _tfdopen( msvcrt_alloc_fd(hWritePipe, split_oflags(_fmode)) , _T("w"));
|
||||||
CloseHandle(hReadPipe);
|
CloseHandle(hReadPipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return( pf );
|
container->f = ret;
|
||||||
|
container->proc = ProcessInformation.hProcess;
|
||||||
|
_munlock(_POPEN_LOCK);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (ProcessInformation.hProcess != 0)
|
||||||
|
CloseHandle(ProcessInformation.hProcess);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _UNICODE
|
#ifndef _UNICODE
|
||||||
|
|
Loading…
Reference in a new issue