コード例 #1
0
ファイル: stream.c プロジェクト: sunfirefox/foundation_lib
static stream_t* _stream_std_clone( stream_t* stream )
{
	stream_std_t* clone = memory_allocate_zero_context( MEMORYCONTEXT_STREAM, sizeof( stream_std_t ), 8, MEMORY_PERSISTENT );
	memcpy( clone, stream, sizeof( stream_std_t ) );
	clone->path = string_clone( stream->path );
	return (stream_t*)clone;
}
コード例 #2
0
ファイル: stream.c プロジェクト: sunfirefox/foundation_lib
stream_t* stream_open_stdin( void )
{
	stream_std_t* stream = memory_allocate_zero_context( MEMORYCONTEXT_STREAM, sizeof( stream_std_t ), 8, MEMORY_PERSISTENT );
	_stream_initialize( (stream_t*)stream, system_byteorder() );
	stream->sequential = 1;
	stream->mode = STREAM_IN;
	stream->type = STREAMTYPE_STDSTREAM;
	stream->vtable = &_stream_stdin_vtable;
	stream->path = string_clone( "stdin://" );
	stream->std = stdin;
	return (stream_t*)stream;
}
コード例 #3
0
ファイル: pipe.c プロジェクト: DanielTillett/foundation_lib
stream_t* pipe_allocate( void )
{
	stream_pipe_t* pipestream = memory_allocate_zero_context( HASH_STREAM, sizeof( stream_pipe_t ), 0, MEMORY_PERSISTENT );
	stream_t* stream = (stream_t*)pipestream;

	_stream_initialize( stream, system_byteorder() );

	pipestream->type = STREAMTYPE_PIPE;
	pipestream->path = string_format( "pipe://0x" PRIfixPTR, pipestream );
	pipestream->mode = STREAM_OUT | STREAM_IN | STREAM_BINARY;
	pipestream->sequential = true;

#if FOUNDATION_PLATFORM_WINDOWS
	{
		//Inheritable by default so process can use for stdstreams
		SECURITY_ATTRIBUTES security_attribs = {0};
		security_attribs.nLength = sizeof( SECURITY_ATTRIBUTES ); 
		security_attribs.bInheritHandle = TRUE; 
		security_attribs.lpSecurityDescriptor = 0;

		if( !CreatePipe( &pipestream->handle_read, &pipestream->handle_write, &security_attribs, 0 ) )
			log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to create unnamed pipe: %s", system_error_message( GetLastError() ) );
	}
#elif FOUNDATION_PLATFORM_POSIX
	int fds[2] = { 0, 0 };
	if( pipe( fds ) < 0 )
		log_warnf( 0, WARNING_SYSTEM_CALL_FAIL, "Unable to create unnamed pipe: %s", system_error_message( 0 ) );
	else
	{
		pipestream->fd_read = fds[0];
		pipestream->fd_write = fds[1];
	}
#endif

	pipestream->vtable = &_pipe_stream_vtable;

	return stream;
}
コード例 #4
0
ファイル: assetstream.c プロジェクト: apprisi/foundation_lib
stream_t* asset_stream_open( const char* path, unsigned int mode )
{
	if( !path || !path[0] )
		return 0;

	if( string_equal_substr( path, "asset://", 8 ) )
		path += 8;
	if( *path == '/' )
		++path;

	AAsset* assetobj = AAssetManager_open( android_app()->activity->assetManager, path, AASSET_MODE_RANDOM );
	if( !assetobj )
	{
		//warn_logf( WARNING_SYSTEM_CALL_FAIL, "Unable to open asset: asset://%s", path );
		return 0;
	}

	stream_asset_t* asset = memory_allocate_zero_context( HASH_STREAM, sizeof( stream_asset_t ), 8, MEMORY_PERSISTENT );
	stream_t* stream = (stream_t*)asset;

	_stream_initialize( stream, BUILD_DEFAULT_STREAM_BYTEORDER );

	stream->type = STREAMTYPE_ASSET;
	stream->sequential = 0;
	stream->reliable = 1;
	stream->inorder = 1;
	stream->swap = 0;
	stream->path = string_format( "asset://%s", path );
	stream->mode = ( mode & STREAM_BINARY ) | STREAM_IN;
	stream->vtable = &_asset_stream_vtable;

	asset->asset = assetobj;
	asset->position = 0;

	return stream;
}