Beispiel #1
0
static void file_defineConst(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KFileStdIn  = new_File(kctx, OnGlobalConstList, stdin, TEXTSIZE("/dev/stdin"), trace);
	KFileStdOut = new_File(kctx, OnGlobalConstList, stdout, TEXTSIZE("/dev/stdout"), trace);
	KFileStdErr = new_File(kctx, OnGlobalConstList, stderr, TEXTSIZE("/dev/stderr"), trace);
	KDEFINE_FILE_CONST FileData[] = {
		{"stdin", KType_File,  KFileStdIn},
		{"stdout", KType_File, KFileStdOut},
		{"stderr", KType_File, KFileStdErr},
		{NULL}, /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(FileData), trace);
	KDEFINE_INT_CONST IntData[] = {
		{"EOF", KType_Int,  EOF},
		{NULL}, /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(IntData), trace);

}
Beispiel #2
0
int File_copyTo( const IFile* self, const IPath* targetPath, int force )
{
	bool status = 0;

	char* target = NULL;
	IFile* target_file = NULL;
	IDirectory* target_dir = new_Directory_path( targetPath );
	if ( Directory_exists( target_dir ) )
	{
		target = CharString_cat3( Path_getCommon( targetPath ), "/", Path_getBasename( self->path ) );
	} else {
		target = CharString_copy( Path_getCommon( targetPath ) );
	}

	target_file = new_File( target );
	if ( !File_exists( target_file ) || force )
	{
		if ( File_open( target_file, "w" ) )
		{
			byte buffer[256];
			int read;
		
			while ( (read = File_read( self, buffer, 256 )) )
			{
				File_write( target_file, buffer, read );
				status = 1;
			}
			if ( !status )
			{
				fprintf( stdout, "File.c::copyTo: could not copy data\n" );
			}
		}
		File_close( target_file );
	}		
	free_Directory( target_dir );
	free_File( target_file );
	free_CharString( target );	

	return status;
}