Beispiel #1
1
int main (int argc, char ** argv)
{
    int reti = 0;

    procAutoLocale();
    presetFLTKenv();

    mpg123wrap_init();

#ifdef R_DEBUG
    AllocConsole();

    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
    int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
    FILE* hf_out = _fdopen(hCrt, "w");
    setvbuf(hf_out, NULL, _IONBF, 1);
    *stdout = *hf_out;

    HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
    hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
    FILE* hf_in = _fdopen(hCrt, "r");
    setvbuf(hf_in, NULL, _IONBF, 128);
    *stdin = *hf_in;
#endif // R_DEBUG

    wMain* pWMain = new wMain( argc, argv );

    if ( pWMain != NULL )
    {
        reti = pWMain->Run();
    }

    mpg123wrap_exit();

    return reti;
}
Beispiel #2
0
void CreateConsole()
{
  if(g_flgConsoleExist) 
    return;
#ifdef WIN32
	BOOL resAllocConsole = AllocConsole();
  if(resAllocConsole==false)
    return;
	// Out
  int hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
	FILE *hf = _fdopen( hCrt, "w" );
	*stdout = *hf;
#endif
  g_flgConsoleExist = true;
}
Beispiel #3
0
void create_crt_fd(fd_set *os_set, fd_set *crt_set)
{
  int i;
  crt_set->fd_count = os_set->fd_count;
  for (i = 0; i < os_set->fd_count; i++) {
    WSAPROTOCOL_INFO wsa_pi;
    // dupicate the SOCKET
    int r = WSADuplicateSocket(os_set->fd_array[i], GetCurrentProcessId(), &wsa_pi);
    SOCKET s = WSASocket(wsa_pi.iAddressFamily, wsa_pi.iSocketType, wsa_pi.iProtocol, &wsa_pi, 0, 0);
    // create the CRT fd so ruby can get back to the SOCKET
    int fd = _open_osfhandle(s, O_RDWR|O_BINARY);
    os_set->fd_array[i] = s;
    crt_set->fd_array[i] = fd;
  }
}
Beispiel #4
0
/* TempConsole */
void AllocTempConsole(void)
{
        if (s_console)
                return;

        if (AllocConsole())
        {
                HANDLE ha = GetStdHandle(STD_OUTPUT_HANDLE);
                int hCrt = _open_osfhandle((long) ha, 0x4000);
                FILE *hf = _fdopen( hCrt, "w" );
                stdout_old = *stdout;
                *stdout = *hf;

                ha = GetStdHandle(STD_ERROR_HANDLE);
                hCrt = _open_osfhandle((long) ha, 0x4000);
                hf = _fdopen( hCrt, "w" );
                stderr_old = *stderr;
                *stderr = *hf;
                setvbuf( stdout, NULL, _IONBF, 0 );
                setvbuf( stderr, NULL, _IONBF, 0 );

                s_console = 1;
        }
}
Beispiel #5
0
void InitInjectedConsole()
{
    AllocConsole();
    SetConsoleTitle("PlayLethalLeague");
    SetConsoleCtrlHandler(InjectedConsoleCtrlHandler, TRUE);
    SetConsoleOutputCP(CP_UTF8);  // also this is needed when you want to use UTF8

#ifdef ENABLE_REDIRECT_STDINOUT
    const int in = _open_osfhandle(INT_PTR(GetStdHandle(STD_INPUT_HANDLE)), OPEN_MODE);
    const int out = _open_osfhandle(INT_PTR(GetStdHandle(STD_OUTPUT_HANDLE)), OPEN_MODE);
    const int err = _open_osfhandle(INT_PTR(GetStdHandle(STD_ERROR_HANDLE)), OPEN_MODE);
    oldStdin = in;
    oldStdout = out;
    oldStderr = err;
    *stdin = *_fdopen(in, "r");
    *stdout = *_fdopen(out, "w");
    *stderr = *_fdopen(err, "w");

    // Redirect the CRT standard input, output, and error handles to the console
    freopen("CONIN$", "r", stdin);
    freopen("CONOUT$", "w", stdout);
    freopen("CONOUT$", "w", stderr);
#endif

    //Clear the error state for each of the C++ standard stream objects. We need to do this, as
    //attempts to access the standard streams before they refer to a valid target will cause the
    //iostream objects to enter an error state. In versions of Visual Studio after 2005, this seems
    //to always occur during startup regardless of whether anything has been read from or written to
    //the console or not.
    std::wcout.clear();
    std::cout.clear();
    std::wcerr.clear();
    std::cerr.clear();
    std::wcin.clear();
    std::cin.clear();
}
Beispiel #6
0
int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index,
                            unsigned fd_index) {
  grpc_tcp_listener *sp;
  if (fd_index != 0) {
    /* Windows implementation has only one fd per port_index. */
    return -1;
  }
  for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index)
    ;
  if (sp) {
    return _open_osfhandle(sp->socket->socket, 0);
  } else {
    return -1;
  }
}
Beispiel #7
0
// From http://dslweb.nwnexus.com/~ast/dload/guicon.htm
// Is there a more recent and easier way to do this?
void RedirectIOToConsole()
{
    int hConHandle;
    long lStdHandle;
    CONSOLE_SCREEN_BUFFER_INFO coninfo;
    FILE *fp;

    // allocate a console for this app
    AllocConsole();

    // set the screen buffer to be big enough to let us scroll text
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
    coninfo.dwSize.Y = MAX_CONSOLE_LINES;
    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);

    // redirect unbuffered STDOUT to the console
    lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    fp = _fdopen( hConHandle, "w" );
    *stdout = *fp;
    setvbuf( stdout, NULL, _IONBF, 0 );

    // redirect unbuffered STDIN to the console
    lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    fp = _fdopen( hConHandle, "r" );
    *stdin = *fp;
    setvbuf( stdin, NULL, _IONBF, 0 );

    // redirect unbuffered STDERR to the console
    lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
    fp = _fdopen( hConHandle, "w" );
    *stderr = *fp;
    setvbuf( stderr, NULL, _IONBF, 0 );
}
CConsolePrinter::CConsolePrinter(bool in)   
{   
    // create a new console to the process   
    AllocConsole();
	pFile = NULL;
	if (in == true)
	{
		hConsoleMode = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);   
		pFile  = _fdopen(hConsoleMode, "r");   
		
		// use default stream buffer   
		setvbuf(pFile, NULL, _IONBF, 0);   
		*stdin = *pFile;
	}
	else
	{
		hConsoleMode = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);   
		pFile  = _fdopen(hConsoleMode, "w");   
		
		// use default stream buffer   
		setvbuf(pFile, NULL, _IONBF, 0);   
		*stdout = *pFile;
	}
}   
Beispiel #9
0
/* Uncompress using Windows handles */
int64_t bled_uncompress_with_handles(HANDLE hSrc, HANDLE hDst, int type)
{
	transformer_state_t xstate;

	if (!bled_initialized) {
		bb_error_msg("The library has not been initialized");
		return -1;
	}

	bb_total_rb = 0;
	init_transformer_state(&xstate);
	xstate.src_fd = -1;
	xstate.dst_fd = -1;
	xstate.check_signature = 1;

	xstate.src_fd = _open_osfhandle((intptr_t)hSrc, _O_RDONLY);
	if (xstate.src_fd < 0) {
		bb_error_msg("Could not get source descriptor (errno: %d)", errno);
		return -1;
	}

	xstate.dst_fd = _open_osfhandle((intptr_t)hDst, 0);
	if (xstate.dst_fd < 0) {
		bb_error_msg("Could not get target descriptor (errno: %d)", errno);
		return -1;
	}

	if ((type < 0) || (type >= BLED_COMPRESSION_MAX)) {
		bb_error_msg("Unsupported compression format");
		return -1;
	}

	if (setjmp(bb_error_jmp))
		return -1;
	return unpacker[type](&xstate);
}
// Convert an OS file handle to a C runtime file descriptor.
static PyObject *msvcrt_open_osfhandle(PyObject *self, PyObject *args)
{
	long handle;
	int flags;
	int fd;

	if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))
		return NULL;

	fd = _open_osfhandle(handle, flags);
	if (fd == -1)
		return PyErr_SetFromErrno(PyExc_IOError);

	return PyInt_FromLong(fd);
}
void OgreApp::redirectIOToConsole()
{
	//using namespace std;
	int hConHandle;
	long lStdHandle;
	CONSOLE_SCREEN_BUFFER_INFO coninfo;
	FILE *fp;
	// allocate a console for this app
	AllocConsole();
	// set the screen buffer to be big enough to let us scroll text
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
	coninfo.dwSize.Y = 1000;
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
		coninfo.dwSize);
	// redirect unbuffered STDOUT to the console
	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen( hConHandle, "w" );
	*stdout = *fp;
	setvbuf( stdout, NULL, _IONBF, 0 );
	// redirect unbuffered STDIN to the console
	lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen( hConHandle, "r" );
	*stdin = *fp;
	setvbuf( stdin, NULL, _IONBF, 0 );
	// redirect unbuffered STDERR to the console
	lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen( hConHandle, "w" );
	*stderr = *fp;
	setvbuf( stderr, NULL, _IONBF, 0 );
	// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
	// point to console as well
	std::ios::sync_with_stdio();
}
Beispiel #12
0
bool DXWindow::InitWnd(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, PSTR _pCmdLine, int _nShowCmd, DisplayMode _displayMode)
{
	AllocConsole();

	HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
	int hCrt = _open_osfhandle((long)handle_out, _O_TEXT);
	FILE* hf_out = _fdopen(hCrt, "w");
	setvbuf(hf_out, NULL, _IONBF, 1);
	*stdout = *hf_out;

	HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
	hCrt = _open_osfhandle((long)handle_in, _O_TEXT);
	FILE* hf_in = _fdopen(hCrt, "r");
	setvbuf(hf_in, NULL, _IONBF, 128);
	*stdin = *hf_in;

	if (!InitWndApp(_hInstance, _nShowCmd, _displayMode))
	{
		::MessageBox(0, "Initalaization Failed", "Error", MB_OK);
		return false;
	}

	return true;
}
Beispiel #13
0
/* creates a temporary file with the data in it */
int
regress_make_tmpfile(const void *data, size_t datalen)
{
#ifndef WIN32
	char tmpfilename[32];
	int fd;
	strcpy(tmpfilename, "/tmp/eventtmp.XXXXXX");
#ifdef _EVENT_HAVE_UMASK
	umask(0077);
#endif
	fd = mkstemp(tmpfilename);
	if (fd == -1)
		return (-1);
	if (write(fd, data, datalen) != (int)datalen) {
		close(fd);
		return (-1);
	}
	lseek(fd, 0, SEEK_SET);
	/* remove it from the file system */
	unlink(tmpfilename);
	return (fd);
#else
	/* XXXX actually delete the file later */
	char tmpfilepath[MAX_PATH];
	char tmpfilename[MAX_PATH];
	DWORD r, written;
	int tries = 16;
	HANDLE h;
	r = GetTempPathA(MAX_PATH, tmpfilepath);
	if (r > MAX_PATH || r == 0)
		return (-1);
	for (; tries > 0; --tries) {
		r = GetTempFileNameA(tmpfilepath, "LIBEVENT", 0, tmpfilename);
		if (r == 0)
			return (-1);
		h = CreateFileA(tmpfilename, GENERIC_READ|GENERIC_WRITE,
		    0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (h != INVALID_HANDLE_VALUE)
			break;
	}
	if (tries == 0)
		return (-1);
	written = 0;
	WriteFile(h, data, (DWORD)datalen, &written, NULL);
	/* Closing the fd returned by this function will indeed close h. */
	return _open_osfhandle((intptr_t)h,_O_RDONLY);
#endif
}
	// libavformat uses open (in the file_open function) so we need to override that too.
	// Following the same rules as ADM_fopen.
	int ADM_open(const char *path, int oflag, ...)
	{
		int fileNameLength = utf8StringToWideChar(path, -1, NULL);
		wchar_t wcFile[fileNameLength];
		int creation = 0, access = 0;
		HANDLE hFile;

		utf8StringToWideChar(path, -1, wcFile);

		if (oflag & O_WRONLY || oflag & O_RDWR)
		{
			access = GENERIC_WRITE;

			if (oflag & O_RDWR)
				access |= GENERIC_READ;

			if (oflag & O_CREAT)
			{
				if (oflag & O_EXCL)
					creation = CREATE_NEW;
				else if (oflag & O_TRUNC)
					creation = CREATE_ALWAYS;
				else
					creation = OPEN_ALWAYS;
			}
			else if (oflag & O_TRUNC)
				creation = TRUNCATE_EXISTING;
		}
		else if (oflag & O_RDONLY)
			creation = OPEN_EXISTING;

		if (creation & GENERIC_WRITE)
		{
			hFile = CreateFileW(wcFile, access, 0, NULL, creation, 0, NULL);

			if (hFile == INVALID_HANDLE_VALUE)
				return -1;
			else
				CloseHandle(hFile);
		}

		hFile = CreateFileW(wcFile, access, FILE_SHARE_READ, NULL, creation, 0, NULL);

		if (hFile == INVALID_HANDLE_VALUE)
			return -1;
		else
			return _open_osfhandle((intptr_t)hFile, oflag);
	}
Beispiel #15
0
PipedReader::PipedReader(std::shared_ptr<ISource> &src):
    FilterBase(src), m_thread(0), m_position(0)
{
    HANDLE hr, hw;
    int fd;
    FILE *fp;

    uint32_t bpf = src->getSampleFormat().mBytesPerFrame;
    if (!CreatePipe(&hr, &hw, 0, NSAMPLES * bpf * PIPE_BUF_FACTOR))
        win32::throw_error("CreatePipe", GetLastError());
    CHECKCRT((fd = _open_osfhandle(reinterpret_cast<intptr_t>(hr),
                                   _O_RDONLY|_O_BINARY)) < 0);
    CHECKCRT((fp = _fdopen(fd, "rb")) == 0);
    m_readPipe.reset(fp, std::fclose);
    m_writePipe.reset(hw, CloseHandle);
}
//
// Attaches a console window to a regular Win32 app.
//
bool CreateConsole( void )
{
	if( NULL == AllocConsole( ) )
	{
		wchar_t error[64];
		_snwprintf_s( error, sizeof error, L"Failed to attach console window. Error code: %u", GetLastError( ) );
		MessageBox( NULL, error, L"Error", MB_ICONEXCLAMATION | MB_OK );
		return false;
	}

	int crt = _open_osfhandle( (long)GetStdHandle( STD_OUTPUT_HANDLE ), _O_TEXT );
	*stdout = *_fdopen( crt, "w" );
	setvbuf( stdout, NULL, _IONBF, NULL );

	return true;
}
Beispiel #17
0
static VALUE rb_mysql_client_socket(VALUE self) {
    GET_CLIENT(self);
    REQUIRE_OPEN_DB(wrapper);
    int fd_set_fd = wrapper->client->net.fd;
#ifdef _WIN32
    WSAPROTOCOL_INFO wsa_pi;
    // dupicate the SOCKET from libmysql
    int r = WSADuplicateSocket(wrapper->client->net.fd, GetCurrentProcessId(), &wsa_pi);
    SOCKET s = WSASocket(wsa_pi.iAddressFamily, wsa_pi.iSocketType, wsa_pi.iProtocol, &wsa_pi, 0, 0);
    // create the CRT fd so ruby can get back to the SOCKET
    fd_set_fd = _open_osfhandle(s, O_RDWR|O_BINARY);
    return INT2NUM(fd_set_fd);
#else
    return INT2NUM(fd_set_fd);
#endif
}
Beispiel #18
0
void pipeline(const char *const *argv, struct pipeline *pl)
{
	HANDLE in_read_handle, in_write_handle;
	SECURITY_ATTRIBUTES sec_attr;
	PROCESS_INFORMATION proc_info;
	STARTUPINFO start_info;
	char *cmdline = make_command_line(argv);

	sec_attr.nLength = sizeof sec_attr;
	sec_attr.bInheritHandle = TRUE;
	sec_attr.lpSecurityDescriptor = NULL;

	if (!CreatePipe(&in_read_handle, &in_write_handle, &sec_attr, 0))
		die_windows_error("CreatePipe");

	if (!SetHandleInformation(in_write_handle, HANDLE_FLAG_INHERIT, 0))
		die_windows_error("SetHandleInformation");

	/* when in Rome... */
	ZeroMemory(&proc_info, sizeof proc_info);
	ZeroMemory(&start_info, sizeof start_info);

	start_info.cb = sizeof start_info;
	start_info.dwFlags |= STARTF_USESTDHANDLES;

	if ((start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE))
	                                             == INVALID_HANDLE_VALUE
	    || (start_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE))
	                                             == INVALID_HANDLE_VALUE)
		die_windows_error("GetStdHandle");

	start_info.hStdInput = in_read_handle;

	if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0,
			   NULL, NULL, &start_info, &proc_info))
		die_windows_error("CreateProcess");

	free(cmdline);

	if (!CloseHandle(proc_info.hThread))
		die_windows_error("CloseHandle for thread");
	if (!CloseHandle(in_read_handle))
		die_windows_error("CloseHandle");

	pl->proc_handle = proc_info.hProcess;
	pl->infd = _open_osfhandle((intptr_t)in_write_handle, 0);
}
Beispiel #19
0
static int win32_serial_port_open( struct serial_opt *serial )
{
	static DCB dcb = {0};

	HANDLE hComm = CreateFile(
		serial->name,
		GENERIC_WRITE | GENERIC_READ,
		0,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL
	);

	if ( hComm == INVALID_HANDLE_VALUE )
	{
		printf("CreateFile() failed with error %d\n",  GetLastError());
	}

	if ( GetCommState(hComm, &dcb) )
	{
		dcb.BaudRate = serial->baud;
		dcb.ByteSize = 8;
		dcb.Parity = NOPARITY;
		dcb.StopBits = ONESTOPBIT;
	}
	else
	{
		printf( "Failed to get the comm state - Error: %d\n", GetLastError() );
		CloseHandle( hComm );
	}

	if ( !SetCommState( hComm, &dcb ) )
	{
		printf("Failed to set the comm state - Error: %d", GetLastError());
		CloseHandle(hComm);
	}

	serial->handler = _open_osfhandle( (intptr_t) hComm, O_TEXT );
	if ( serial->handler == -1 ) 
	{
		printf("Error in _open_osfhandle\n");
		CloseHandle(hComm);
	}

	return serial->handler;
}
Beispiel #20
0
FILE *eC_stdin(void)  {
#if defined(__WIN32__)
   if(!fStdIn)
   {
      stdinHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
      osfStdin = _open_osfhandle(stdinHandle, _O_TEXT);
      if(osfStdin != -1)
         fStdIn = _fdopen( osfStdin, "rb");
      else
         fStdIn = stdin;
      setvbuf( fStdIn, NULL, _IONBF, 0 );
   }
   return fStdIn;
#else
return stdin;
#endif
}
Beispiel #21
0
//-----------------------------------SetStdOutToNewConsole---------------------------
//	This opens up a console to display standard out
//-----------------------------------------------------------------------------------
void SetStdOutToNewConsole()
{
  int hConHandle;
  long lStdHandle;
  FILE *fp;

  // allocate a console for this app
  AllocConsole();

  // redirect unbuffered STDOUT to the console
  lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
  hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
  fp = _fdopen( hConHandle, "w" );
  *stdout = *fp;

  setvbuf( stdout, NULL, _IONBF, 0 );
}
Beispiel #22
0
int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
{
	int sockfd2;

	SOCKET s1 = (SOCKET)_get_osfhandle(sockfd1);
	SOCKET s2 = accept(s1, sa, sz);

	/* convert into a file descriptor */
	if ((sockfd2 = _open_osfhandle(s2, O_RDWR|O_BINARY)) < 0) {
		int err = errno;
		closesocket(s2);
		bb_error_msg("unable to make a socket file descriptor: %s",
			strerror(err));
		return -1;
	}
	return sockfd2;
}
Beispiel #23
0
void CMiniDebugger::InitializeConsole()
{
	AllocConsole();

	CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;

	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ScreenBufferInfo);
	ScreenBufferInfo.dwSize.Y = 1000;
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), ScreenBufferInfo.dwSize);

	(*stdout) = *_fdopen(_open_osfhandle(
		reinterpret_cast<intptr_t>(GetStdHandle(STD_OUTPUT_HANDLE)),
		_O_TEXT), "w");

	setvbuf(stdout, NULL, _IONBF, 0);
	std::ios::sync_with_stdio();	
}
Beispiel #24
0
KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
krb5_storage_from_fd(krb5_socket_t fd_in)
{
    krb5_storage *sp;
    int fd;

#ifdef SOCKET_IS_NOT_AN_FD
#ifdef _MSC_VER
    if (_get_osfhandle(fd_in) != -1) {
	fd = dup(fd_in);
    } else {
	fd = _open_osfhandle(fd_in, 0);
    }
#else
#error Dont know how to deal with fd that may or may not be a socket.
#endif
#else  /* SOCKET_IS_NOT_AN_FD */
    fd = dup(fd_in);
#endif

    if (fd < 0)
	return NULL;

    sp = malloc(sizeof(krb5_storage));
    if (sp == NULL) {
	close(fd);
	return NULL;
    }

    sp->data = malloc(sizeof(fd_storage));
    if (sp->data == NULL) {
	close(fd);
	free(sp);
	return NULL;
    }
    sp->flags = 0;
    sp->eof_code = HEIM_ERR_EOF;
    FD(sp) = fd;
    sp->fetch = fd_fetch;
    sp->store = fd_store;
    sp->seek = fd_seek;
    sp->trunc = fd_trunc;
    sp->free = fd_free;
    return sp;
}
Beispiel #25
0
FILE *eC_stdout(void)
{
#if 0 //defined(__WIN32__)
   if(!fStdOut)
   {
      stdoutHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
      osfStdout = _open_osfhandle(stdoutHandle, _O_TEXT);
      if(osfStdout != -1)
         fStdOut = _fdopen( osfStdout, "wb");
      else
         fStdOut = stdout;
      setvbuf( fStdOut, NULL, _IONBF, 0 );
   }
   return fStdOut;
#else
   return stdout;
#endif
}
Beispiel #26
0
FILE * my_win_fdopen(File fd, const char *type)
{
  FILE *file;
  int crt_fd;
  int flags= 0;

  DBUG_ENTER("my_win_fdopen");

  if(strchr(type,'a') != NULL)
    flags= O_APPEND;
  /* Convert OS file handle to CRT file descriptor and then call fdopen*/
  crt_fd= _open_osfhandle((intptr_t)my_get_osfhandle(fd), flags);
  if(crt_fd < 0)
    file= NULL;
  else
    file= fdopen(crt_fd, type);
  DBUG_RETURN(file);
}
Beispiel #27
0
struct NaClDesc *NaClDescIoDescMakeFromHandle(NaClHandle handle) {
  int posix_d;
  struct NaClHostDesc *nhdp;
  struct NaClDescIoDesc *desc;

#if NACL_WINDOWS
  posix_d = _open_osfhandle((intptr_t) handle, _O_RDWR | _O_BINARY);
  if (-1 == posix_d)
    return NULL;
#else
  posix_d = handle;
#endif
  nhdp = NaClHostDescPosixMake(posix_d, NACL_ABI_O_RDWR);
  if (NULL == nhdp)
    return NULL;
  desc = NaClDescIoDescMake(nhdp);
  return &desc->base;
}
Beispiel #28
0
void glutInit(int *argcp, char **argv)
{
	int i;
	int hCrt;
	FILE *hf;

	for (i = 0; i < 256; i++) gKeymap[i] = 0;

	// Make printf work!
	AllocConsole();
	hCrt = _open_osfhandle(
		(long) GetStdHandle(STD_OUTPUT_HANDLE),
		_O_TEXT
		);
	hf = _fdopen( hCrt, "w" );
	*stdout = *hf;
	i = setvbuf( stdout, NULL, _IONBF, 0 );
}
Beispiel #29
0
	void redirect()
	{
		auto redir = [](DWORD from_handle, FILE *to_handle, char *mode){
			auto std_handle = GetStdHandle(from_handle);
			auto con_handle = _open_osfhandle((intptr_t)std_handle, _O_TEXT);
			auto fp = _fdopen(con_handle, mode);
			*to_handle = *fp;
			setvbuf(to_handle, nullptr, _IONBF, 0);
		};

		redir(STD_OUTPUT_HANDLE, stdout, "w"); // redirect stdout
		redir(STD_INPUT_HANDLE, stdin, "r"); // redirect stdin
		redir(STD_ERROR_HANDLE, stderr, "w"); // redirect stderr

		// make std::cout, std::cin, std::cerr, std::wcin, std::wcout, std::wcerr, 
		// std::clog and std::wclog point to console as well
		std::ios::sync_with_stdio();
	}
/*
Allocates a console process to the application process
*/
void WindowObject::CreateConsole()
{
	// Create the Console
	AllocConsole();

	// Create Console Output Handle
	HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
	int hCrt = _open_osfhandle((long)handle_out, _O_TEXT);
	FILE* hf_out = _fdopen(hCrt, "w");
	setvbuf(hf_out, NULL, _IONBF, 1);
	*stdout = *hf_out;

	// Create Console Input Handle
	HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
	hCrt = _open_osfhandle((long)handle_in, _O_TEXT);
	FILE* hf_in = _fdopen(hCrt, "r");
	setvbuf(hf_in, NULL, _IONBF, 128);
	*stdin = *hf_in;

	// Get the Console Window Handle
	hWnd = GetConsoleWindow();

	SetConsoleTitle("Console");
}