note
	description: "A package file."
	author: "Louis Marchand"
	date: "Thu, 02 Apr 2015 03:58:25 +0000"
	revision: "2.0"

class 
	CPF_PACKAGE_FILE

create 
	make,
	make_thread_safe,
	make_open,
	make_open_tread_safe

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (a_filename: READABLE_STRING_GENERAL)
			-- Initialisation of the package file
		do
			make_with_name (a_filename)
			create {ARRAYED_LIST [POINTER]} cpf_infos.make (0)
			create {ARRAYED_LIST [TUPLE [pos: INTEGER_32; length: INTEGER_32]]} sub_files_infos.make (0)
			is_thread_safe := False
			is_valid := False
		end

	make_open (a_filename: READABLE_STRING_GENERAL)
			-- Initialisation and opening of the package file
		do
			make (a_filename)
			open
		end

	make_open_tread_safe (a_filename: READABLE_STRING_GENERAL)
			-- Initialisation and opening of the package file with thread safe mecanisme
		do
			make_thread_safe (a_filename)
			open
		end

	make_thread_safe (a_filename: READABLE_STRING_GENERAL)
			-- Initialisation of the package file with thread safe mecanisme
		do
			make (a_filename)
			is_thread_safe := True
		ensure
			make_thread_safe_mutex_valid: internal_mutex.is_set
		end
	
feature -- Initialization

	make_obsolete (fn: STRING_8)
		obsolete "Use any of the `make_...' routines instead to benefit from Unicode file names. [2017-05-31]"
			-- Create file object with fn as file name.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
		ensure -- from FILE
			file_named: internal_name = fn
			file_closed: is_closed
		end

	make_create_read_write (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for both reading and writing;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			create_read_write
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_append (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file in append-only mode.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_append
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_append: is_open_append
		end

	make_open_read (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file in read mode.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_read
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
		end

	make_open_read_append (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for reading anywhere
			-- but writing at the end only.
			-- Create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_read_append
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	make_open_read_write (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for both reading and writing.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_read_write
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_temporary
			-- Create a file object with a unique temporary file name,
			-- with read/write mode.
			-- (from FILE)
		do
			make_open_temporary_with_prefix ("eiftmp")
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_temporary_with_prefix (a_prefix: READABLE_STRING_GENERAL)
			-- Create a file object with a unique temporary file name with prefix a_prefix,
			-- with read/write mode.
			-- (from FILE)
		local
			l_fd: INTEGER_32
		do
			set_name (a_prefix.as_string_32 + {STRING_32}"XXXXXX")
			l_fd := eif_temp_file (internal_name_pointer.item, is_plain_text)
			make_with_name (Buffered_file_info.pointer_to_file_name_32 (internal_name_pointer.item))
			fd_open_read_write (l_fd)
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	make_open_write (fn: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name
			-- and open file for writing;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			string_exists: fn /= Void
			string_not_empty: not fn.is_empty
		do
			make_with_name (fn)
			open_write
		ensure -- from FILE
			file_named: internal_name = fn
			exists: exists
			open_write: is_open_write
		end
	
feature -- Access

	access_date: INTEGER_32
			-- Time stamp of last access made to the inode.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Result := eif_file_access_date (internal_name_pointer.item)
		end

	can_read_16: BOOLEAN
			-- There is another 16 bits in the stream to read.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		do
			Result := count - position > 1
		end

	can_read_32: BOOLEAN
			-- There is another 16 bits in the stream to read.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		do
			Result := count - position > 3
		end

	can_read_64: BOOLEAN
			-- There is another 16 bits in the stream to read.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		do
			Result := count - position > 7
		end

	current_sub_file_count: INTEGER_32
			-- The number of byte of the present sub-file

	current_sub_file_first_position: INTEGER_32
			-- The position in Current that the present sub-file start

	current_sub_file_index: INTEGER_32
			-- Retreive the index of the sub-file that the cursor is presently in.
		require
			cpf_file_is_valid: is_valid
		local
			l_is_found: BOOLEAN
		do
			Result := 0
			from
				l_is_found := False;
				sub_files_infos.start
			until
				l_is_found or else sub_files_infos.exhausted
			loop
				if position >= sub_files_infos.item.pos and then position < sub_files_infos.item.pos + sub_files_infos.item.length then
					Result := sub_files_infos.index
					l_is_found := True
				end;
				sub_files_infos.forth
			end
		end

	current_sub_file_last_position: INTEGER_32
			-- The position in Current that the present sub-file end
		require
			cpf_file_is_valid: is_valid
		do
			Result := current_sub_file_first_position + current_sub_file_count - 1
		end

	current_sub_file_position: INTEGER_32
			-- Return the current stream offset (position) in the file.
		require
			cpf_file_is_valid: is_valid
			file_index_is_in_file: is_position_in_selected_sub_file
		do
			Result := position - current_sub_file_first_position
		end

	date: INTEGER_32
			-- Time stamp (time of last modification)
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Result := eif_file_date (internal_name_pointer.item)
		end

	descriptor: INTEGER_32
			-- File descriptor as used by the operating system.
			-- (from FILE)
		require -- from IO_MEDIUM
			valid_handle: descriptor_available
		require else -- from FILE
			file_opened: not is_closed
		do
			Result := file_fd (file_pointer)
			descriptor_available := True
		end

	descriptor_available: BOOLEAN
			-- Is the handle available after class has been
			-- created?
			-- (from FILE)

	file_index: INTEGER_32
			-- The index identifier of the presently selected sub-file

	file_info: FILE_INFO
			-- Collected information about the file.
			-- (from FILE)
		do
			set_buffer
			Result := Buffered_file_info.twin
		end

	file_pointer: POINTER
			-- File pointer as required in C
			-- (from FILE)

	generating_type: TYPE [detachable CPF_PACKAGE_FILE]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	go_in_current_sub_file (a_offset: INTEGER_32)
			-- Place the stream offset at offset position after the begining of the file.
			-- The offset value must be posifive.
		require
			cpf_file_is_valid: is_valid
			file_seek_from_begining_offset_positive: a_offset >= 0 and then a_offset <= current_sub_file_last_position
		do
			go (a_offset + current_sub_file_first_position)
		ensure
				position = a_offset
		end

	group_id: INTEGER_32
			-- Group identification of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.group_id
		end

	has (v: like item): BOOLEAN
			-- Does structure include an occurrence of v?
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from  CONTAINER
			True
		do
			start
			if not off then
				search (v)
			end
			Result := not exhausted
		ensure -- from CONTAINER
			not_found_in_empty: Result implies not is_empty
		end

	index_of (v: like item; i: INTEGER_32): INTEGER_32
			-- Index of i-th occurrence of v.
			-- 0 if none.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from LINEAR
			positive_occurrences: i > 0
		local
			occur, pos: INTEGER_32
		do
			if object_comparison and v /= Void then
				from
					start
					pos := 1
				until
					exhausted or (occur = i)
				loop
					if item ~ v then
						occur := occur + 1
					end
					forth
					pos := pos + 1
				end
			else
				from
					start
					pos := 1
				until
					exhausted or (occur = i)
				loop
					if item = v then
						occur := occur + 1
					end
					forth
					pos := pos + 1
				end
			end
			if occur = i then
				Result := pos - 1
			end
		ensure -- from LINEAR
			non_negative_result: Result >= 0
		end

	inode: INTEGER_32
			-- I-node number
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.inode
		end

	is_position_in_selected_sub_file: BOOLEAN
			-- True if the present position in Current is in the sub-file that is selected
		require
			cpf_file_is_valid: is_valid
		do
			Result := position >= current_sub_file_first_position and then position <= current_sub_file_last_position
		end

	is_valid: BOOLEAN
			-- Is Current a valid package file

	item: CHARACTER_8
			-- Current item
			-- (from FILE)
		require -- from ACTIVE
			readable: readable
		require -- from TRAVERSABLE
			not_off: not off
		do
			read_character
			Result := last_character
			back
		end

	item_for_iteration: CHARACTER_8
			-- Item at current position
			-- (from LINEAR)
		require -- from LINEAR
			not_off: not off
		do
			Result := item
		end

	links: INTEGER_32
			-- Number of links on file
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.links
		end

	move_in_current_sub_file (a_offset: INTEGER_32)
			-- Place the stream offset at offset position after (or before if offset is negative) the index.
		require
			cpf_file_is_valid: is_valid
			file_seek_from_index_is_in_file: is_position_in_selected_sub_file
			file_seek_from_index__is_valid: (a_offset >= 0 and then a_offset <= current_sub_file_last_position - position) or else (a_offset < 0 and then a_offset.abs <= position)
		do
			go_in_current_sub_file (a_offset + current_sub_file_first_position)
		end

	name: STRING_8
		obsolete "Use `path.name' to ensure that Unicode filenames are not truncated. [2017-05-31]"
			-- File name as a STRING_8 instance. The value might be truncated
			-- from the original name used to create the current FILE instance.
			-- (from FILE)
		require -- from  IO_MEDIUM
			True
		do
			Result := internal_name.as_string_8
		ensure then -- from FILE
			name_not_empty: not Result.is_empty
		end

	null_name: STRING_8
			-- Null device name.
			-- (from FILE)
		do
			if {PLATFORM}.is_windows then
				Result := "nul"
			elseif {PLATFORM}.is_vms then
				Result := "NL:"
			elseif {PLATFORM}.is_vxworks then
				Result := "/null"
			else
				Result := "/dev/null"
			end
		ensure -- from FILE
			instance_free: class
		end

	null_path: PATH
			-- Null device path.
			-- (from FILE)
		do
			create Result.make_from_string (null_name)
		ensure -- from FILE
			instance_free: class
		end

	occurrences (v: like item): INTEGER_32
			-- Number of times v appears.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from LINEAR)
		require -- from  BAG
			True
		do
			from
				start
				search (v)
			until
				exhausted
			loop
				Result := Result + 1
				forth
				search (v)
			end
		ensure -- from BAG
			non_negative_occurrences: Result >= 0
		end

	open
			-- Open the package file
			-- A package file is always read-only
		local
			l_temp_ptr: POINTER
		do
			open_read
			is_valid := True
			process_cpf_file
			if is_valid then
				select_sub_file (0)
				cpf_infos := create {ARRAYED_LIST [POINTER]}.make (sub_files_count)
				from
					sub_files_infos.start
				until
					sub_files_infos.exhausted
				loop
					l_temp_ptr := l_temp_ptr.memory_alloc (Custom_package_file_infos_size)
					{CPF_EXTERNAL}.set_custom_package_infos_struct_file_ptr (l_temp_ptr, file_pointer)
					{CPF_EXTERNAL}.set_custom_package_infos_struct_start_offset (l_temp_ptr, sub_files_infos.item.pos.to_integer_64)
					{CPF_EXTERNAL}.set_custom_package_infos_struct_total_size (l_temp_ptr, sub_files_infos.item.length.to_integer_64);
					cpf_infos.extend (l_temp_ptr);
					sub_files_infos.forth
				end
				select_sub_file (0)
			end
		end

	owner_name: STRING_8
			-- Name of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.owner_name
		end

	path: PATH
			-- Associated path of Current.
			-- (from FILE)
		do
			create Result.make_from_pointer (internal_name_pointer.item)
		ensure -- from FILE
			entry_not_empty: not Result.is_empty
		end

	position: INTEGER_32
			-- Current cursor position.
			-- (from FILE)
		require -- from  LINEAR
			True
		do
			if not is_closed then
				Result := file_tell (file_pointer)
			end
		end

	protection: INTEGER_32
			-- Protection mode, in decimal value
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.protection
		end

	put_double_big_endian (a_value: REAL_64)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of putdouble_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_64_big_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value))
		end

	put_double_little_endian (a_value: REAL_64)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- Was declared in GAME_FILE as synonym of putdouble_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_64_little_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value))
		end

	put_integer_16_big_endian (a_value: INTEGER_16)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		do
			put_natural_16_big_endian (a_value.as_natural_16)
		end

	put_integer_16_little_endian (a_value: INTEGER_16)
			-- Write a_value at current position (Writing in little-Endian order).
			-- (from GAME_FILE)
		do
			put_natural_16_little_endian (a_value.as_natural_16)
		end

	put_integer_32_big_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_big_endian and putint_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_big_endian (a_value.as_natural_32)
		end

	put_integer_32_little_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in little-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_little_endian and putint_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_little_endian (a_value.as_natural_32)
		end

	put_integer_64_big_endian (a_value: INTEGER_64)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		do
			put_natural_64_big_endian (a_value.as_natural_64)
		end

	put_integer_64_little_endian (a_value: INTEGER_64)
			-- Write a_value at current position (Writing in little-Endian order).
			-- (from GAME_FILE)
		do
			put_natural_64_little_endian (a_value.as_natural_64)
		end

	put_integer_big_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_32_big_endian and putint_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_big_endian (a_value.as_natural_32)
		end

	put_integer_little_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in little-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_32_little_endian and putint_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_little_endian (a_value.as_natural_32)
		end

	put_natural_16_big_endian (a_value: NATURAL_16)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_16_big_endian (a_value)
			unlock_mutex
		end

	put_natural_16_little_endian (a_value: NATURAL_16)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_16_little_endian (a_value)
			unlock_mutex
		end

	put_natural_32_big_endian (a_value: NATURAL_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_32_big_endian (a_value)
			unlock_mutex
		end

	put_natural_32_little_endian (a_value: NATURAL_32)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_32_little_endian (a_value)
			unlock_mutex
		end

	put_natural_64_big_endian (a_value: NATURAL_64)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_32_big_endian (a_value.bit_shift_right (32).to_natural_32)
			internal_put_natural_32_big_endian (a_value.bit_and (4294967295).to_natural_32)
			unlock_mutex
		end

	put_natural_64_little_endian (a_value: NATURAL_64)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			lock_mutex
			internal_put_natural_32_little_endian (a_value.bit_and (4294967295).to_natural_32)
			internal_put_natural_32_little_endian (a_value.bit_shift_right (32).to_natural_32)
			unlock_mutex
		end

	put_real_big_endian (a_value: REAL_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of putreal_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_big_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value))
		end

	put_real_little_endian (a_value: REAL_32)
			-- Write a_value at current position (Writing in little-Endian order).
			-- Was declared in GAME_FILE as synonym of putreal_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_little_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value))
		end

	putdouble_big_endian (a_value: REAL_64)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of put_double_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_64_big_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value))
		end

	putdouble_little_endian (a_value: REAL_64)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- Was declared in GAME_FILE as synonym of put_double_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_64_little_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value))
		end

	putint_big_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_32_big_endian and put_integer_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_big_endian (a_value.as_natural_32)
		end

	putint_little_endian (a_value: INTEGER_32)
			-- Write a_value at current position (Writing in little-Endian order).
			-- Was declared in GAME_FILE as synonym of put_integer_32_little_endian and put_integer_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_little_endian (a_value.as_natural_32)
		end

	putreal_big_endian (a_value: REAL_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- Was declared in GAME_FILE as synonym of put_real_big_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_big_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value))
		end

	putreal_little_endian (a_value: REAL_32)
			-- Write a_value at current position (Writing in little-Endian order).
			-- Was declared in GAME_FILE as synonym of put_real_little_endian.
			-- (from GAME_FILE)
		do
			put_natural_32_little_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value))
		end

	read_double_big_endian
			-- Read a new double (Reading in Big-Endian order).
			-- Make result available in last_double.
			-- Was declared in GAME_FILE as synonym of readdouble_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_big_endian
			last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64)
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	read_double_little_endian
			-- Read a new double (Reading in Little-Endian order).
			-- Make result available in last_double.
			-- Was declared in GAME_FILE as synonym of readdouble_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_little_endian
			last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64)
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	read_integer_16_big_endian
			-- Read a new 16-bit integer (Reading in Big-Endian order).
			-- Make result available in last_integer_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_16
		local
			l_old_natural_16: NATURAL_16
		do
			lock_mutex
			l_old_natural_16 := last_natural_16
			internal_read_natural_16_big_endian
			last_integer_16 := last_natural_16.as_integer_16
			last_natural_16 := l_old_natural_16
			unlock_mutex
		end

	read_integer_16_little_endian
			-- Read a new 16-bit integer (Reading in Little-Endian order).
			-- Make result available in last_integer_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_16
		local
			l_old_natural_16: NATURAL_16
		do
			lock_mutex
			l_old_natural_16 := last_natural_16
			internal_read_natural_16_little_endian
			last_integer_16 := last_natural_16.as_integer_16
			last_natural_16 := l_old_natural_16
			unlock_mutex
		end

	read_integer_32_big_endian
			-- Read a new 32-bit integer (Reading in Big-Endian order).
			-- Make result available in last_integer_32.
			-- Was declared in GAME_FILE as synonym of read_integer_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_big_endian
			last_integer := last_natural_32.as_integer_32
			last_natural := l_old_natural
			unlock_mutex
		end

	read_integer_32_little_endian
			-- Read a new 32-bit integer (Reading in Little-Endian order).
			-- Make result available in last_integer_32.
			-- Was declared in GAME_FILE as synonym of read_integer_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_little_endian
			last_integer := last_natural_32.as_integer_32
			last_natural := l_old_natural
			unlock_mutex
		end

	read_integer_64_big_endian
			-- Read a new 64-bit integer (Reading in Big-Endian order).
			-- Make result available in last_integer_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_big_endian
			last_integer_64 := last_natural_64.as_integer_64
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	read_integer_64_little_endian
			-- Read a new 64-bit integer (Reading in Little-Endian order).
			-- Make result available in last_integer_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_little_endian
			last_integer_64 := last_natural_64.as_integer_64
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	read_integer_big_endian
			-- Read a new 32-bit integer (Reading in Big-Endian order).
			-- Make result available in last_integer_32.
			-- Was declared in GAME_FILE as synonym of read_integer_32_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_big_endian
			last_integer := last_natural_32.as_integer_32
			last_natural := l_old_natural
			unlock_mutex
		end

	read_integer_little_endian
			-- Read a new 32-bit integer (Reading in Little-Endian order).
			-- Make result available in last_integer_32.
			-- Was declared in GAME_FILE as synonym of read_integer_32_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_little_endian
			last_integer := last_natural_32.as_integer_32
			last_natural := l_old_natural
			unlock_mutex
		end

	read_natural_16_big_endian
			-- Read the next 16-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_16
		do
			lock_mutex
			internal_read_natural_16_big_endian
			unlock_mutex
		end

	read_natural_16_little_endian
			-- Read the next 16-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_16
		do
			lock_mutex
			internal_read_natural_16_little_endian
			unlock_mutex
		end

	read_natural_32_big_endian
			-- Read the next 32-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_32.
			-- Was declared in GAME_FILE as synonym of read_natural_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		do
			lock_mutex
			internal_read_natural_32_big_endian
			unlock_mutex
		end

	read_natural_32_little_endian
			-- Read the next 32-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_32.
			-- Was declared in GAME_FILE as synonym of read_natural_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		do
			lock_mutex
			internal_read_natural_32_little_endian
			unlock_mutex
		end

	read_natural_64_big_endian
			-- Read the next 64-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		do
			lock_mutex
			internal_read_natural_64_big_endian
			unlock_mutex
		end

	read_natural_64_little_endian
			-- Read the next 64-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		do
			lock_mutex
			internal_read_natural_64_little_endian
			unlock_mutex
		end

	read_natural_big_endian
			-- Read the next 32-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_32.
			-- Was declared in GAME_FILE as synonym of read_natural_32_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		do
			lock_mutex
			internal_read_natural_32_big_endian
			unlock_mutex
		end

	read_natural_little_endian
			-- Read the next 32-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_32.
			-- Was declared in GAME_FILE as synonym of read_natural_32_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		do
			lock_mutex
			internal_read_natural_32_little_endian
			unlock_mutex
		end

	read_real_big_endian
			-- Read a new real (Reading in Big-Endian order).
			-- Make result available in last_real.
			-- Was declared in GAME_FILE as synonym of readreal_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_big_endian
			last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32)
			last_natural := l_old_natural
			unlock_mutex
		end

	read_real_little_endian
			-- Read a new real (Reading in Little-Endian order).
			-- Make result available in last_real.
			-- Was declared in GAME_FILE as synonym of readreal_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_little_endian
			last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32)
			last_natural := l_old_natural
			unlock_mutex
		end

	readdouble_big_endian
			-- Read a new double (Reading in Big-Endian order).
			-- Make result available in last_double.
			-- Was declared in GAME_FILE as synonym of read_double_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_big_endian
			last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64)
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	readdouble_little_endian
			-- Read a new double (Reading in Little-Endian order).
			-- Make result available in last_double.
			-- Was declared in GAME_FILE as synonym of read_double_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_64
		local
			l_old_natural_64: NATURAL_64
		do
			lock_mutex
			l_old_natural_64 := last_natural_64
			internal_read_natural_64_little_endian
			last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64)
			last_natural_64 := l_old_natural_64
			unlock_mutex
		end

	readreal_big_endian
			-- Read a new real (Reading in Big-Endian order).
			-- Make result available in last_real.
			-- Was declared in GAME_FILE as synonym of read_real_big_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_big_endian
			last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32)
			last_natural := l_old_natural
			unlock_mutex
		end

	readreal_little_endian
			-- Read a new real (Reading in Little-Endian order).
			-- Make result available in last_real.
			-- Was declared in GAME_FILE as synonym of read_real_little_endian.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
			can_read: can_read_32
		local
			l_old_natural: NATURAL_32
		do
			lock_mutex
			l_old_natural := last_natural
			internal_read_natural_32_little_endian
			last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32)
			last_natural := l_old_natural
			unlock_mutex
		end

	recede_in_current_sub_file (a_offset: INTEGER_32)
			-- Place the stream offset at offset position before the end of the file.
			-- The offset value must be negative.
		require
			custom_file_seek_from_end_offset_negative: a_offset <= 0
			cpf_file_is_valid: is_valid
		do
			go (current_sub_file_last_position + a_offset)
		end

	retrieved: detachable ANY
			-- Retrieved object structure
			-- To access resulting object under correct type,
			-- use assignment attempt.
			-- Will raise an exception (code Retrieve_exception)
			-- if content is not a stored Eiffel structure.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
			support_storable: Support_storable
		do
			(create {MISMATCH_CORRECTOR}).Mismatch_information.do_nothing
			Result := c_retrieved (descriptor)
		end

	select_sub_file (a_index: INTEGER_32)
			-- In Current, go to the sub-file identified by a_index
		require
			cpf_file_is_valid: is_valid
		do
			if a_index = 0 then
				current_sub_file_first_position := 0
				current_sub_file_count := count
				go_in_current_sub_file (0)
			else
				current_sub_file_first_position := sub_files_infos.at (a_index).pos
				current_sub_file_count := sub_files_infos.at (a_index).length
				go_in_current_sub_file (0)
			end
		end

	separator: CHARACTER_8
			-- ASCII code of character following last word read
			-- (from FILE)

	user_id: INTEGER_32
			-- User identification of owner
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.user_id
		end
	
feature {GAME_RESSOURCE_MANAGER} -- Access

	disable_thread_safe
			-- Make Current unusable in a multi-threaded system.
			-- (from GAME_FILE)
		do
			is_thread_safe := True
		end

	enable_thread_safe
			-- Make Current usable in a multi-threaded system.
			-- (from GAME_FILE)
		do
			is_thread_safe := True
		end

	internal_mutex: MUTEX
			-- A mutex to sinchronize the file input/output and position
			-- (from GAME_FILE)

	is_thread_safe: BOOLEAN
			-- Is Current can be used in a multi-threaded system.
			-- (from GAME_FILE)

	lock_mutex
			-- Lock the internal mutex to prevent multiple access to the package file
			-- (from GAME_FILE)
		do
			if is_thread_safe then
				internal_mutex.lock
			end
		end

	unlock_mutex
			-- Unlock the internal mutex
			-- (from GAME_FILE)
		do
			if is_thread_safe then
				internal_mutex.unlock
			end
		end
	
feature {NATIVE_STRING_HANDLER} -- Access

	pointer_length_in_bytes (a_ptr: POINTER): INTEGER_32
			-- Length in bytes of a platform specific file name pointer, not
			-- including the null-terminating character. If size is too large
			-- to fit into an {INTEGER} instance, the size is truncated to
			-- {INTEGER_32}.max_value.
			-- (from NATIVE_STRING_HANDLER)
		require -- from NATIVE_STRING_HANDLER
			a_ptr_not_null: a_ptr /= default_pointer
		local
			l_length: NATURAL_64
		do
			l_length := c_pointer_length_in_bytes (a_ptr)
			if l_length <= {INTEGER_32}.max_value.to_natural_64 then
				Result := l_length.to_integer_32
			else
				Result := {INTEGER_32}.max_value
			end
		end
	
feature -- Measurement

	count: INTEGER_32
			-- Size in bytes (0 if no associated physical file)
			-- (from FILE)
		do
			if exists then
				if not is_open_write then
					set_buffer
					Result := Buffered_file_info.size
				else
					Result := file_size (file_pointer)
				end
			end
		ensure -- from FINITE
			count_non_negative: Result >= 0
		end
	
feature {NONE} -- Measurement

	estimated_count_of (other: ITERABLE [CHARACTER_8]): INTEGER_32
			-- Estimated number of elements in other.
			-- (from CONTAINER)
		do
			if attached {FINITE [CHARACTER_8]} other as f then
				Result := f.count
			elseif attached {READABLE_INDEXABLE [CHARACTER_8]} other as r then
				Result := r.upper - r.lower + 1
			end
		ensure -- from CONTAINER
			instance_free: class
			non_negative_result: Result >= 0
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: CPF_PACKAGE_FILE): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: CPF_PACKAGE_FILE): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	same_file (fn: READABLE_STRING_GENERAL): BOOLEAN
			-- Is current file the same as a_filename?
			-- (from FILE)
		require -- from FILE
			fn_not_void: fn /= Void
			fn_not_empty: not fn.is_empty
		do
			Result := path.is_same_file_as (create {PATH}.make_from_string (fn))
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "≜" (other: CPF_PACKAGE_FILE): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	access_exists: BOOLEAN
			-- Does physical file exist?
			-- (Uses real UID.)
			-- (from FILE)
		do
			if is_closed then
				Result := file_access (internal_name_pointer.item, 0)
			else
				Result := True
			end
		end

	after: BOOLEAN
			-- Is there no valid cursor position to the right of cursor position?
			-- (from FILE)
		do
			Result := not is_closed and then (end_of_file or count = 0)
		end

	before: BOOLEAN
			-- Is there no valid cursor position to the left of cursor position?
			-- (from FILE)
		do
			Result := is_closed
		end

	bytes_read: INTEGER_32
			-- Last number of bytes read by read_to_managed_pointer.
			-- (from IO_MEDIUM)

	changeable_comparison_criterion: BOOLEAN
			-- May object_comparison be changed?
			-- (Answer: yes by default.)
			-- (from CONTAINER)
		do
			Result := True
		end

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	empty: BOOLEAN
		obsolete "ELKS 2000: Use `is_empty' instead. [2017-05-31]"
			-- Is there no element?
			-- (from CONTAINER)
		do
			Result := is_empty
		end

	end_of_file: BOOLEAN
			-- Has an EOF been detected?
			-- (from FILE)
		require -- from FILE
			opened: not is_closed
		do
			Result := file_feof (file_pointer)
		end

	exhausted: BOOLEAN
			-- Has structure been completely explored?
			-- (from LINEAR)
		do
			Result := off
		ensure -- from LINEAR
			exhausted_when_off: off implies Result
		end

	exists: BOOLEAN
			-- Does physical file exist?
			-- (Uses effective UID.)
			-- (from FILE)
		require -- from  IO_MEDIUM
			True
		do
			if is_closed then
				Result := file_exists (internal_name_pointer.item)
			else
				Result := True
			end
		ensure then -- from FILE
			unchanged_mode: mode = old mode
		end

	extendible: BOOLEAN
			-- May new items be added?
			-- (from FILE)
		require -- from  COLLECTION
			True
		require -- from  IO_MEDIUM
			True
		do
			Result := mode >= Write_file
		end

	file_prunable: BOOLEAN
		obsolete "Use `prunable' instead. [2017-05-31]"
			-- May items be removed?
			-- (from FILE)
		do
		end

	file_readable: BOOLEAN
			-- Is there a current item that may be read?
			-- (from FILE)
		do
			Result := (mode >= Read_write_file or mode = Read_file) and readable
		end

	file_writable: BOOLEAN
			-- Is there a current item that may be modified?
			-- (from FILE)
		do
			Result := mode >= Write_file
		end

	Full: BOOLEAN = False
			-- Is structure filled to capacity?
			-- (from FILE)

	is_access_executable: BOOLEAN
			-- Is file executable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_executable
		end

	is_access_owner: BOOLEAN
			-- Is file owned by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_owner
		end

	is_access_readable: BOOLEAN
			-- Is file readable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_readable
		end

	is_access_writable: BOOLEAN
			-- Is file writable by real UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_access_writable
		end

	is_block: BOOLEAN
			-- Is file a block special file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_block
		end

	is_character: BOOLEAN
			-- Is file a character special file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_character
		end

	is_closed: BOOLEAN
			-- Is file closed?
			-- (from FILE)
		do
			Result := mode = Closed_file
		end

	is_creatable: BOOLEAN
			-- Is file creatable in parent directory?
			-- (Uses effective UID to check that parent is writable
			-- and file does not exist.)
			-- (from FILE)
		do
			Result := file_creatable (internal_name_pointer.item, internal_name_pointer.count)
		end

	is_device: BOOLEAN
			-- Is file a device?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_device
		end

	is_directory: BOOLEAN
			-- Is file a directory?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_directory
		end

	is_empty: BOOLEAN
			-- Is structure empty?
			-- (from FINITE)
		do
			Result := count = 0
		end

	is_executable: BOOLEAN
			-- Is file executable?
			-- (Checks execute permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_executable
		end

	is_fifo: BOOLEAN
			-- Is file a named pipe?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_fifo
		end

	is_inserted (v: CHARACTER_8): BOOLEAN
			-- Has v been inserted by the most recent insertion?
			-- (By default, the value returned is equivalent to calling 
			-- has (v). However, descendants might be able to provide more
			-- efficient implementations.)
			-- (from COLLECTION)
		do
			Result := has (v)
		end

	is_open_append: BOOLEAN
			-- Is file open for appending?
			-- (from FILE)
		do
			Result := mode = Append_file or else mode = Append_read_file
		end

	is_open_read: BOOLEAN
			-- Is file open for reading?
			-- (from FILE)
		do
			Result := mode = Read_file or else mode = Read_write_file or else mode = Append_read_file
		end

	is_open_write: BOOLEAN
			-- Is file open for writing?
			-- (from FILE)
		do
			Result := mode = Write_file or else mode = Read_write_file or else mode = Append_read_file or else mode = Append_file
		end

	is_owner: BOOLEAN
			-- Is file owned by effective UID?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_owner
		end

	is_plain: BOOLEAN
			-- Is file a plain file?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_plain
		end

	is_plain_text: BOOLEAN
			-- Is file reserved for text (character sequences)?
			-- (from IO_MEDIUM)
		do
		end

	is_readable: BOOLEAN
			-- Is file readable?
			-- (Checks permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_readable
		end

	is_setgid: BOOLEAN
			-- Is file setgid?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_setgid
		end

	is_setuid: BOOLEAN
			-- Is file setuid?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_setuid
		end

	is_socket: BOOLEAN
			-- Is file a named socket?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_socket
		end

	is_sticky: BOOLEAN
			-- Is file sticky (for memory swaps)?
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_sticky
		end

	is_symlink: BOOLEAN
			-- Is file a symbolic link?
			-- (from FILE)
		require -- from FILE
			file_exists: path_exists
		local
			l_buffer: like Buffered_file_info
			l_is_following_symbolic_links: BOOLEAN
		do
			l_buffer := Buffered_file_info
			l_is_following_symbolic_links := l_buffer.is_following_symlinks;
			l_buffer.set_is_following_symlinks (False);
			l_buffer.fast_update (internal_name, internal_name_pointer)
			Result := l_buffer.is_symlink;
			l_buffer.set_is_following_symlinks (l_is_following_symbolic_links)
		end

	is_writable: BOOLEAN
			-- Is file writable?
			-- (Checks write permission for effective UID.)
			-- (from FILE)
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.is_writable
		end

	last_character: CHARACTER_8
			-- Last character read by read_character.
			-- (from IO_MEDIUM)

	last_double: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)

	last_integer: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)

	last_integer_16: INTEGER_16
			-- Last 16-bit integer read by read_integer_16
			-- (from IO_MEDIUM)

	last_integer_32: INTEGER_32
			-- Synonymy of last_integer
			-- (from IO_MEDIUM)
		do
			Result := last_integer
		end

	last_integer_64: INTEGER_64
			-- Last 64-bit integer read by read_integer_64
			-- (from IO_MEDIUM)

	last_integer_8: INTEGER_8
			-- Last 8-bit integer read by read_integer_8
			-- (from IO_MEDIUM)

	last_natural: NATURAL_32
			-- Last 32-bit natural read by read_natural
			-- (from IO_MEDIUM)

	last_natural_16: NATURAL_16
			-- Last 16-bit natural read by read_natural_16
			-- (from IO_MEDIUM)

	last_natural_32: NATURAL_32
			-- Synonymy of last_natural
			-- (from IO_MEDIUM)
		do
			Result := last_natural
		end

	last_natural_64: NATURAL_64
			-- Last 64-bit natural read by read_natural_64
			-- (from IO_MEDIUM)

	last_natural_8: NATURAL_8
			-- Last 8-bit natural read by read_natural_8
			-- (from IO_MEDIUM)

	last_real: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)

	last_real_32: REAL_32
			-- Last 32-bit real read by read_real_32.
			-- Synonym of last_real.
			-- (from IO_MEDIUM)
		do
			Result := last_real
		end

	last_real_64: REAL_64
			-- Last 64-bit real read by read_real_64.
			-- Synonym of last_double.
			-- (from IO_MEDIUM)
		do
			Result := last_double
		end

	last_string: STRING_8
			-- Last string read
			-- (from IO_MEDIUM)

	object_comparison: BOOLEAN
			-- Must search operations use equal rather than =
			-- for comparing references? (Default: no, use =.)
			-- (from CONTAINER)

	off: BOOLEAN
			-- Is there no item?
			-- (from FILE)
		require -- from  TRAVERSABLE
			True
		do
			Result := (count = 0) or else is_closed or else end_of_file
		end

	path_exists: BOOLEAN
			-- Does physical file name exist without resolving
			-- symbolic links?
			-- (from FILE)
		do
			Result := file_path_exists (internal_name_pointer.item)
		ensure then -- from FILE
			unchanged_mode: mode = old mode
		end

	readable: BOOLEAN
			-- Is there a current item that may be read?
			-- (from SEQUENCE)
		require -- from  ACTIVE
			True
		require -- from IO_MEDIUM
			handle_exists: exists
		do
			Result := not off
		end

	replaceable: BOOLEAN
			-- Can current item be replaced?
			-- (from FILE)
		do
			Result := False
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end

	Support_storable: BOOLEAN = True
			-- Can medium be used to an Eiffel structure?
			-- (from RAW_FILE)

	writable: BOOLEAN
			-- Is there a current item that may be modified?
			-- (from SEQUENCE)
		do
			Result := not off
		end
	
feature {NONE} -- Status report

	is_in_final_collect: BOOLEAN
			-- Is GC currently performing final collection
			-- after execution of current program?
			-- Safe to use in dispose.
			-- (from DISPOSABLE)
		external
			"C inline use %"eif_memory.h%""
		alias
			"return eif_is_in_final_collect;"
		end
	
feature -- Status setting

	close
			-- Close file.
			-- (from FILE)
		require -- from IO_MEDIUM
			medium_is_open: not is_closed
		do
			file_close (file_pointer)
			mode := Closed_file
			file_pointer := default_pointer
			descriptor_available := False
		ensure then -- from FILE
			is_closed: is_closed
		end

	compare_objects
			-- Ensure that future search operations will use equal
			-- rather than = for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := True
		ensure -- from CONTAINER
				object_comparison
		end

	compare_references
			-- Ensure that future search operations will use =
			-- rather than equal for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := False
		ensure -- from CONTAINER
			reference_comparison: not object_comparison
		end

	create_read_write
			-- Open file in read and write mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 4)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	fd_open_append (fd: INTEGER_32)
			-- Open file of descriptor fd in append mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 2)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	fd_open_read (fd: INTEGER_32)
			-- Open file of descriptor fd in read-only mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 0)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	fd_open_read_append (fd: INTEGER_32)
			-- Open file of descriptor fd
			-- in read and write-at-end mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 5)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	fd_open_read_write (fd: INTEGER_32)
			-- Open file of descriptor fd in read-write mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 3)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	fd_open_write (fd: INTEGER_32)
			-- Open file of descriptor fd in write mode.
			-- (from FILE)
		do
			file_pointer := file_dopen (fd, 1)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end

	open_append
			-- Open file in append-only mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 2)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	open_read
			-- Open file in read-only mode.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 0)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	open_read_append
			-- Open file in read and write-at-end mode;
			-- create it if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 5)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	open_read_write
			-- Open file in read and write mode.
			-- (from FILE)
		require -- from FILE
			is_closed: is_closed
		do
			file_pointer := file_open (internal_name_pointer.item, 3)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	open_write
			-- Open file in write-only mode;
			-- create it if it does not exist.
			-- (from FILE)
		do
			file_pointer := file_open (internal_name_pointer.item, 1)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end

	recreate_read_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-write mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 4, file_pointer)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	reopen_append (fname: READABLE_STRING_GENERAL)
			-- Reopen in append mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 2, file_pointer)
			mode := Append_file
		ensure -- from FILE
			exists: exists
			open_append: is_open_append
		end

	reopen_read (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-only mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 0, file_pointer)
			mode := Read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
		end

	reopen_read_append (fname: READABLE_STRING_GENERAL)
			-- Reopen in read and write-at-end mode with file
			-- of name fname; create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 5, file_pointer)
			mode := Append_read_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_append: is_open_append
		end

	reopen_read_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in read-write mode with file of name fname.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 3, file_pointer)
			mode := Read_write_file
		ensure -- from FILE
			exists: exists
			open_read: is_open_read
			open_write: is_open_write
		end

	reopen_write (fname: READABLE_STRING_GENERAL)
			-- Reopen in write-only mode with file of name fname;
			-- create file if it does not exist.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
			valid_name: fname /= Void
		do
			set_name (fname)
			file_pointer := file_reopen (internal_name_pointer.item, 1, file_pointer)
			mode := Write_file
		ensure -- from FILE
			exists: exists
			open_write: is_open_write
		end
	
feature -- Cursor movement

	back
			-- Go back one position.
			-- (from FILE)
		require -- from BILINEAR
			not_before: not before
		do
			file_move (file_pointer, -1)
		end

	finish
			-- Go to last position.
			-- (from FILE)
		require -- from  LINEAR
			True
		require else -- from FILE
			file_opened: not is_closed
		do
			file_recede (file_pointer, 0)
		end

	forth
			-- Go to next position.
			-- (from FILE)
		require -- from LINEAR
			not_after: not after
		require else -- from FILE
			file_opened: not is_closed
		do
			file_move (file_pointer, 1);
			file_gc (file_pointer).do_nothing
			if not end_of_file then
				back
			end
		end

	go (abs_position: INTEGER_32)
			-- Go to the absolute position.
			-- (New position may be beyond physical length.)
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
			non_negative_argument: abs_position >= 0
		do
			file_go (file_pointer, abs_position)
		end

	move (offset: INTEGER_32)
			-- Advance by offset from current location.
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
		do
			file_move (file_pointer, offset)
		end

	next_line
			-- Move to next input line.
			-- (from FILE)
		require -- from FILE
			is_readable: file_readable
		do
			file_tnil (file_pointer)
		end

	recede (abs_position: INTEGER_32)
			-- Go to the absolute position backwards,
			-- starting from end of file.
			-- (from FILE)
		require -- from FILE
			file_opened: not is_closed
			non_negative_argument: abs_position >= 0
		do
			file_recede (file_pointer, abs_position)
		end

	search (v: like item)
			-- Move to first position (at or after current
			-- position) where item and v are equal.
			-- If structure does not include v ensure that
			-- exhausted will be true.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from BILINEAR)
		do
			if before and not is_empty then
				forth
			end
			Precursor (v)
		ensure -- from LINEAR
			object_found: (not exhausted and object_comparison) implies v ~ item
			item_found: (not exhausted and not object_comparison) implies v = item
		end

	start
			-- Go to first position.
			-- (from FILE)
		require -- from  TRAVERSABLE
			True
		require else -- from FILE
			file_opened: not is_closed
		do
			file_go (file_pointer, 0)
		end
	
feature -- Element change

	add_permission (who, what: STRING_8)
			-- Add read, write, execute or setuid permission
			-- for who ('u', 'g' or 'o') to what.
			-- (from FILE)
		require -- from FILE
			who_is_not_void: who /= Void
			what_is_not_void: what /= Void
			file_descriptor_exists: exists
		local
			ext_who, ext_what: ANY
		do
			ext_who := who.to_c
			ext_what := what.to_c
			file_perm (internal_name_pointer.item, $ext_who.to_pointer, $ext_what.to_pointer, 1)
		end

	append (f: CPF_PACKAGE_FILE)
			-- Append a copy of the contents of f.
			-- (from FILE)
		require -- from SEQUENCE
			argument_not_void: f /= Void
		require else -- from FILE
			target_is_closed: is_closed
			source_is_closed: f.is_closed
		do
			open_append;
			f.open_read
			file_append (file_pointer, f.file_pointer, f.count)
			close;
			f.close
		ensure -- from SEQUENCE
			new_count: count >= old count
		ensure then -- from FILE
			new_count: count = old count + f.count
			files_closed: f.is_closed and is_closed
		end

	basic_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable within current system only.
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_basic_store (descriptor, $object.to_pointer)
		end

	change_date: INTEGER_32
			-- Time stamp of last change.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			set_buffer
			Result := Buffered_file_info.change_date
		end

	change_group (new_group_id: INTEGER_32)
			-- Change group of file to new_group_id found in
			-- system password file.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chgrp (internal_name_pointer.item, new_group_id)
		end

	change_mode (mask: INTEGER_32)
			-- Replace mode by mask.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chmod (internal_name_pointer.item, mask)
		end

	change_name (new_name: STRING_8)
		obsolete "Use `rename_file' instead. [2017-05-31]"
			-- Change file name to new_name.
			-- (from FILE)
		require -- from FILE
			new_name_not_void: new_name /= Void
			new_name_not_empty: not new_name.is_empty
			file_exists: exists
		do
			rename_file (new_name)
		ensure -- from FILE
			name_changed: internal_name = new_name
		end

	change_owner (new_owner_id: INTEGER_32)
			-- Change owner of file to new_owner_id found in
			-- system password file. On some systems this
			-- requires super-user privileges.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_chown (internal_name_pointer.item, new_owner_id)
		end

	extend (v: like item)
			-- Include v at end.
			-- (from FILE)
		require -- from COLLECTION
			extendible: extendible
		do
			put_character (v)
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		end

	fill (other: CONTAINER [CHARACTER_8])
			-- Fill with as many items of other as possible.
			-- The representations of other and current structure
			-- need not be the same.
			-- (from COLLECTION)
		require -- from COLLECTION
			other_not_void: other /= Void
			extendible: extendible
		local
			lin_rep: LINEAR [CHARACTER_8]
		do
			lin_rep := other.linear_representation
			from
				lin_rep.start
			until
				not extendible or else lin_rep.off
			loop
				extend (lin_rep.item);
				lin_rep.forth
			end
		end

	flush
			-- Flush buffered data to disk.
			-- Note that there is no guarantee that the operating
			-- system will physically write the data to the disk.
			-- At least it will end up in the buffer cache,
			-- making the data visible to other processes.
			-- (from FILE)
		require -- from FILE
			is_open: not is_closed
		do
			file_flush (file_pointer)
		end

	force (v: like item)
			-- Add v to end.
			-- (from SEQUENCE)
		require -- from SEQUENCE
			extendible: extendible
		do
			extend (v)
		ensure then -- from SEQUENCE
			new_count: count = old count + 1
			item_inserted: has (v)
		end

	general_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable from other systems for same platform
			-- (machine architecture).
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_general_store (descriptor, $object.to_pointer)
		end

	independent_store (object: ANY)
			-- Produce an external representation of the
			-- entire object structure reachable from object.
			-- Retrievable from other systems for the same or other
			-- platform (machine architecture).
			-- (from FILE)
		require -- from IO_MEDIUM
			object_not_void: object /= Void
			extendible: extendible
			support_storable: Support_storable
		do
			c_independent_store (descriptor, $object.to_pointer)
		end

	link (fn: READABLE_STRING_GENERAL)
			-- Link current file to fn.
			-- fn must not already exist.
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := Buffered_file_info.file_name_to_pointer (fn, Void)
			file_link (internal_name_pointer.item, l_ptr.item)
		end

	new_line
			-- Write a new line character at current position.
			-- Was declared in FILE as synonym of put_new_line.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_tnwl (file_pointer)
		end

	put (v: like item)
			-- Add v to end.
			-- (from SEQUENCE)
		require -- from COLLECTION
			extendible: extendible
		do
			extend (v)
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		ensure then -- from SEQUENCE
			new_count: count = old count + 1
		end

	put_character (c: CHARACTER_8)
			-- Write c at current position.
			-- Was declared in FILE as synonym of putchar.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pc (file_pointer, c)
		end

	put_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
			-- Put data of length nb_bytes pointed by start_pos index in p at
			-- current position.
			-- (from FILE)
		require -- from IO_MEDIUM
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			extendible: extendible
		do
			file_ps (file_pointer, p.item + start_pos, nb_bytes)
		end

	put_new_line
			-- Write a new line character at current position.
			-- Was declared in FILE as synonym of new_line.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_tnwl (file_pointer)
		end

	put_string (s: READABLE_STRING_8)
			-- Write s at current position.
			-- Was declared in FILE as synonym of putstring.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
			non_void: s /= Void
		local
			n: like {READABLE_STRING_8}.count
			ext_s: ANY
		do
			n := s.count
			if n > 0 then
				ext_s := s.area
				file_ps (file_pointer, $ext_s.to_pointer, n)
			end
		end

	putchar (c: CHARACTER_8)
			-- Write c at current position.
			-- Was declared in FILE as synonym of put_character.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pc (file_pointer, c)
		end

	putstring (s: READABLE_STRING_8)
			-- Write s at current position.
			-- Was declared in FILE as synonym of put_string.
			-- (from FILE)
		require -- from IO_MEDIUM
			extendible: extendible
			non_void: s /= Void
		local
			n: like {READABLE_STRING_8}.count
			ext_s: ANY
		do
			n := s.count
			if n > 0 then
				ext_s := s.area
				file_ps (file_pointer, $ext_s.to_pointer, n)
			end
		end

	remove_permission (who, what: STRING_8)
			-- Remove read, write, execute or setuid permission
			-- for who ('u', 'g' or 'o') to what.
			-- (from FILE)
		require -- from FILE
			who_is_not_void: who /= Void
			what_is_not_void: what /= Void
			file_descriptor_exists: exists
		local
			ext_who, ext_what: ANY
		do
			ext_who := who.to_c
			ext_what := what.to_c
			file_perm (internal_name_pointer.item, $ext_who.to_pointer, $ext_what.to_pointer, 0)
		end

	rename_file (new_name: READABLE_STRING_GENERAL)
			-- Change file name to new_name
			-- (from FILE)
		require -- from FILE
			new_name_not_void: new_name /= Void
			new_name_not_empty: not new_name.is_empty
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := Buffered_file_info.file_name_to_pointer (new_name, Void)
			file_rename (internal_name_pointer.item, l_ptr.item)
			set_name (new_name)
		ensure -- from FILE
			name_changed: internal_name = new_name
		end

	rename_path (new_path: PATH)
			-- Change file name to new_path
			-- (from FILE)
		require -- from FILE
			new_path_not_void: new_path /= Void
			new_path_not_empty: not new_path.is_empty
			file_exists: exists
		local
			l_ptr: MANAGED_POINTER
		do
			l_ptr := new_path.to_pointer
			file_rename (internal_name_pointer.item, l_ptr.item)
			set_path (new_path)
		ensure -- from FILE
			name_changed: internal_name.same_string (new_path.name)
		end

	set_access (time: INTEGER_32)
			-- Stamp with time (access only).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 0)
		ensure -- from FILE
			acess_date_updated: access_date = time
			date_unchanged: date = old date
		end

	set_date (time: INTEGER_32)
			-- Stamp with time (modification time only).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 1)
		ensure -- from FILE
			access_date_unchanged: access_date = old access_date
			date_updated: date = time
		end

	stamp (time: INTEGER_32)
			-- Stamp with time (for both access and modification).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_utime (internal_name_pointer.item, time, 2)
		ensure -- from FILE
			date_updated: date = time
		end

	touch
			-- Update time stamp (for both access and modification).
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			file_touch (internal_name_pointer.item)
		ensure -- from FILE
			date_changed: date /= old date
		end
	
feature -- Removal

	delete
			-- Remove link with physical file.
			-- File does not physically disappear from the disk
			-- until no more processes reference it.
			-- I/O operations on it are still possible.
			-- A directory must be empty to be deleted.
			-- (from FILE)
		require -- from FILE
			exists: path_exists
		do
			file_unlink (internal_name_pointer.item)
		end

	dispose
			-- Ensure this medium is closed when garbage collected.
			-- (from IO_MEDIUM)
		do
			if not is_closed then
				close
			end
		end

	prune_all (v: like item)
			-- Remove all occurrences of v; go off.
			-- (from SEQUENCE)
		require -- from COLLECTION
			prunable: prunable
		do
			from
				start
			until
				exhausted
			loop
				search (v)
				if not exhausted then
					remove
				end
			end
		ensure -- from COLLECTION
			no_more_occurrences: not has (v)
		end

	reset (fn: READABLE_STRING_GENERAL)
			-- Change file name to fn and reset
			-- file descriptor and all information.
			-- (from FILE)
		require -- from FILE
			valid_file_name: fn /= Void
		do
			set_name (fn)
			if mode /= Closed_file then
				close
			end
			last_integer := 0
			last_real := 0.0
			last_double := 0.0
			last_character := '%U';
			last_string.wipe_out
		ensure -- from FILE
			file_renamed: internal_name = fn
			file_closed: is_closed
		end

	reset_path (fp: PATH)
			-- Change file name to fp and reset
			-- file descriptor and all information.
			-- (from FILE)
		require -- from FILE
			valid_file_name: fp /= Void
		do
			set_path (fp)
			if mode /= Closed_file then
				close
			end
			last_integer := 0
			last_real := 0.0
			last_double := 0.0
			last_character := '%U';
			last_string.wipe_out
		ensure -- from FILE
			file_closed: is_closed
		end

	wipe_out
			-- Remove all items.
			-- (from FILE)
		require -- from COLLECTION
			prunable: prunable
		require else -- from FILE
			is_closed: is_closed
		do
			open_write
			close
		ensure -- from COLLECTION
			wiped_out: is_empty
		end
	
feature -- Conversion

	linear_representation: LINEAR [CHARACTER_8]
			-- Representation as a linear structure
			-- (from LINEAR)
		require -- from  CONTAINER
			True
		do
			Result := Current
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: CPF_PACKAGE_FILE)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: CPF_PACKAGE_FILE)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: CPF_PACKAGE_FILE
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: CPF_PACKAGE_FILE)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: CPF_PACKAGE_FILE
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: CPF_PACKAGE_FILE
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached CPF_PACKAGE_FILE
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable CPF_PACKAGE_FILE
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature -- Obsolete

	lastchar: CHARACTER_8
			-- Last character read by read_character
			-- (from IO_MEDIUM)
		do
			Result := last_character
		end

	lastdouble: REAL_64
			-- Last double read by read_double
			-- (from IO_MEDIUM)
		do
			Result := last_double
		end

	lastint: INTEGER_32
			-- Last integer read by read_integer
			-- (from IO_MEDIUM)
		do
			Result := last_integer
		end

	lastreal: REAL_32
			-- Last real read by read_real
			-- (from IO_MEDIUM)
		do
			Result := last_real
		end

	laststring: like last_string
			-- Last string read
			-- (from IO_MEDIUM)
		do
			Result := last_string
		end
	
feature {NONE} -- Inapplicable

	go_to (r: CURSOR)
			-- Move to position marked r.
			-- (from FILE)
		do
		end
	
feature -- Inapplicable

	prune (v: like item)
			-- Remove an occurrence of v if any.
			-- (from FILE)
		require -- from COLLECTION
			prunable: prunable
		do
		ensure then -- from FILE
				count <= old count
		end

	remove
			-- Remove current item.
			-- (from FILE)
		require -- from ACTIVE
			prunable: prunable
			writable: writable
		do
		end

	replace (v: like item)
			-- Replace current item by v.
			-- (from FILE)
		require -- from ACTIVE
			writable: writable
			replaceable: replaceable
		do
		ensure -- from ACTIVE
			item_replaced: item = v
		end
	
feature -- Implementation

	make_with_name (a_name: READABLE_STRING_GENERAL)
			-- Create file object with fn as file name.
			-- (from GAME_FILE)
		require -- from FILE
			fn_exists: a_name /= Void
			fn_not_empty: not a_name.is_empty
		do
			Precursor (a_name)
			create internal_mutex.make
		ensure -- from FILE
			file_named: internal_name = a_name
			file_closed: is_closed
		end

	make_with_path (a_path: PATH)
			-- Create file object with a_path as path.
			-- (from GAME_FILE)
		require -- from FILE
			a_path_attached: a_path /= Void
			a_path_not_empty: not a_path.is_empty
		do
			Precursor (a_path)
			create internal_mutex.make
		ensure -- from FILE
			path_set: path.same_as (a_path)
			file_closed: is_closed
		end
	
feature {NONE} -- Implementation

	Buffered_file_info: FILE_INFO
			-- Information about the file.
			-- (from FILE)
		once
			create Result.make
		end

	c_basic_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"estore"
		end

	c_general_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"eestore"
		end

	c_independent_store (file_handle: INTEGER_32; object: POINTER)
			-- Store object structure reachable form current object
			-- in file pointer file_ptr.
			-- (from FILE)
		external
			"C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
		alias
			"sstore"
		end

	c_pointer_length_in_bytes (a_ptr: POINTER): NATURAL_64
			-- Length in bytes of a platform specific file name pointer, not
			-- including the null-terminating character.
			-- (from NATIVE_STRING_HANDLER)
		require -- from NATIVE_STRING_HANDLER
			a_ptr_not_null: a_ptr /= default_pointer
		external
			"C inline use %"eif_eiffel.h%""
		alias
			"{
			#ifdef EIF_WINDOWS
				return (EIF_NATURAL_64) wcslen($a_ptr) * sizeof(wchar_t);
			#else
				return (EIF_NATURAL_64) strlen($a_ptr) * sizeof(char);
			#endif
			}"
		end

	c_retrieved (file_handle: INTEGER_32): detachable ANY
			-- Object structured retrieved from file of pointer
			-- file_ptr
			-- (from FILE)
		external
			"C use %"eif_retrieve.h%""
		alias
			"eretrieve"
		end

	create_last_string (a_min_size: INTEGER_32)
		obsolete "Implementors should create `last_string' directly. [2017-05-31]"
			-- Create new instance of last_string with a least a_min_size
			-- as capacity.
			-- (from FILE)
		require -- from FILE
			last_string_void: last_string = Void
			a_min_size_non_negative: a_min_size >= 0
		do
			create last_string.make (Default_last_string_size.max (a_min_size))
		ensure -- from FILE
			last_string_attached: last_string /= Void
			capacity_set: attached last_string as l and then l.capacity >= a_min_size
		end

	Default_last_string_size: INTEGER_32 = 256
			-- Default size for creating last_string
			-- (from FILE)

	eif_file_access_date (a_path: POINTER): INTEGER_32
			-- Access date of a file named a_path.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_access_date"
		end

	eif_file_date (a_path: POINTER): INTEGER_32
			-- Modification date of file named a_path.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_date"
		end

	eif_temp_file (a_name_template: POINTER; a_text_mode: BOOLEAN): INTEGER_32
			-- Generate a temporary file and return an file descriptor to the file.
			-- a_name_template: pattern used to create the temporary file.
			-- a_text_mode:, if text mode is True, the temporary file is created in text mode,
			-- otherwise in binary mode.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_BOOLEAN): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_mkstemp"
		end

	False_string: STRING_8
			-- Character string "false"
			-- (from FILE)
		once
			Result := "False"
		end

	file_access (fname: POINTER; which: INTEGER_32): BOOLEAN
			-- Perform access test which on fname using real UID.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_access"
		end

	file_append (file, from_file: POINTER; length: INTEGER_32)
			-- Append a copy of from_file to file
			-- (from FILE)
		external
			"C signature (FILE *, FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_append"
		end

	file_chgrp (fname: POINTER; new_group: INTEGER_32)
			-- Change group of fname to new_group
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chgrp"
		end

	file_chmod (fname: POINTER; mask: INTEGER_32)
			-- Change mode of fname to mask.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chmod"
		end

	file_chown (fname: POINTER; new_owner: INTEGER_32)
			-- Change owner of fname to new_owner
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int) use %"eif_file.h%""
		alias
			"eif_file_chown"
		end

	file_creatable (fname: POINTER; n: INTEGER_32): BOOLEAN
			-- Is fname with n bytes creatable.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_creatable"
		end

	file_dopen (fd, how: INTEGER_32): POINTER
			-- File pointer for file of descriptor fd in mode how
			-- (which must fit the way fd was obtained).
			-- (from RAW_FILE)
		external
			"C signature (int, int): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_binary_dopen"
		end

	file_exists (fname: POINTER): BOOLEAN
			-- Does fname exist.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_exists"
		end

	file_fd (file: POINTER): INTEGER_32
			-- Operating system's file descriptor
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_fd"
		end

	file_feof (file: POINTER): BOOLEAN
			-- End of file?
			-- (from FILE)
		external
			"C signature (FILE *): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_feof"
		end

	file_flush (file: POINTER)
			-- Flush file.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_flush"
		end

	file_gc (file: POINTER): CHARACTER_8
			-- Access the next character
			-- (from FILE)
		external
			"C blocking signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
		alias
			"eif_file_gc"
		end

	file_gdb (file: POINTER): REAL_64
			-- Read a double from file
			-- (from RAW_FILE)
		external
			"C signature (FILE *): EIF_REAL_64 use %"eif_file.h%""
		alias
			"eif_file_gdb"
		end

	file_gib (file: POINTER): INTEGER_32
			-- Get an integer from file
			-- (from RAW_FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gib"
		end

	file_go (file: POINTER; abs_position: INTEGER_32)
			-- Go to absolute position, originated from start.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_go"
		end

	file_grb (file: POINTER): REAL_32
			-- Read a real from file
			-- (from RAW_FILE)
		external
			"C signature (FILE *): EIF_REAL_32 use %"eif_file.h%""
		alias
			"eif_file_grb"
		end

	file_gs (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- a_string updated with characters read from file
			-- until new line, with begin characters already read.
			-- If it does not fit, result is length - begin + 1.
			-- If it fits, result is number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gs"
		end

	file_gs_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Same as file_gs but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gs"
		end

	file_gss (file: POINTER; a_string: POINTER; length: INTEGER_32): INTEGER_32
			-- Read min (length, remaining bytes in file) characters
			-- into a_string. If it does not fit, result is length + 1.
			-- Otherwise, result is the number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gss"
		end

	file_gss_ta (file: POINTER; a_string: POINTER; length: INTEGER_32): INTEGER_32
			-- Same as file_gss but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gss"
		end

	file_gw (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Read a string excluding white space and stripping
			-- leading white space from file into a_string.
			-- White space characters are: blank, new_line,
			-- tab, vertical tab, formfeed or end of file.
			-- If it does not fit, result is length - begin + 1,
			-- otherwise result is number of characters read.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gw"
		end

	file_gw_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER_32): INTEGER_32
			-- Same as file_gw but it won't prevent garbage collection from occurring
			-- while blocked waiting for data.			
			-- (from FILE)
		external
			"C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_gw"
		end

	file_lh (file: POINTER): CHARACTER_8
			-- Look ahead in file and find out the value of the next
			-- character. Do not read over character.
			-- (from FILE)
		external
			"C signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
		alias
			"eif_file_lh"
		end

	file_link (from_name, to_name: POINTER)
			-- Link to_name to from_name
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_link"
		end

	file_move (file: POINTER; offset: INTEGER_32)
			-- Move file pointer by offset.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_move"
		end

	file_path_exists (fname: POINTER): BOOLEAN
			-- Does fname exist.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_path_exists"
		end

	file_pc (file: POINTER; c: CHARACTER_8)
			-- Put c to end of file.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_CHARACTER) use %"eif_file.h%""
		alias
			"eif_file_pc"
		end

	file_pdb (file: POINTER; d: REAL_64)
			-- Put d to end of file.
			-- (from RAW_FILE)
		external
			"C signature (FILE *, EIF_REAL_64) use %"eif_file.h%""
		alias
			"eif_file_pdb"
		end

	file_perm (fname, who, what: POINTER; flag: INTEGER_32)
			-- Change permissions for fname to who and what.
			-- flag = 1 -> add permissions,
			-- flag = 0 -> remove permissions.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, char *, char *, int) use %"eif_file.h%""
		alias
			"eif_file_perm"
		end

	file_pib (file: POINTER; n: INTEGER_32)
			-- Put n to end of file.
			-- (from RAW_FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_pib"
		end

	file_prb (file: POINTER; r: REAL_32)
			-- Put r to end of file.
			-- (from RAW_FILE)
		external
			"C signature (FILE *, EIF_REAL_32) use %"eif_file.h%""
		alias
			"eif_file_prb"
		end

	file_ps (file: POINTER; a_string: POINTER; length: INTEGER_32)
			-- Print a_string to file.
			-- (from FILE)
		external
			"C signature (FILE *, char *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_ps"
		end

	file_recede (file: POINTER; abs_position: INTEGER_32)
			-- Go to absolute position, originated from end.
			-- (from FILE)
		external
			"C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
		alias
			"eif_file_recede"
		end

	file_rename (old_name, new_name: POINTER)
			-- Change file name from old_name to new_name.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_rename"
		end

	file_reopen (fname: POINTER; how: INTEGER_32; file: POINTER): POINTER
			-- File pointer to file, reopened to have new name f_name
			-- in a mode specified by how.
			-- (from RAW_FILE)
		external
			"C signature (EIF_FILENAME, int, FILE *): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_binary_reopen"
		end

	file_size (file: POINTER): INTEGER_32
			-- Size of file
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_size"
		end

	file_tell (file: POINTER): INTEGER_32
			-- Current cursor position in file.
			-- (from FILE)
		external
			"C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_tell"
		end

	file_tnil (file: POINTER)
			-- Read upto next input line.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_tnil"
		end

	file_tnwl (file: POINTER)
			-- Print a new-line to file.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_tnwl"
		end

	file_touch (fname: POINTER)
			-- Touch file fname.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_touch"
		end

	file_unlink (fname: POINTER)
			-- Delete file fname.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME) use %"eif_file.h%""
		alias
			"eif_file_unlink"
		end

	file_utime (fname: POINTER; time, how: INTEGER_32)
			-- Set access, modification time or both (how = 0,1,2) on
			-- fname, using time as time stamp.
			-- (from FILE)
		external
			"C signature (EIF_FILENAME, int, int) use %"eif_file.h%""
		alias
			"eif_file_utime"
		end

	integer_buffer: MANAGED_POINTER
			-- Buffer used to read INTEGER_64, INTEGER_16, INTEGER_8
			-- (from RAW_FILE)
		do
			Result := internal_integer_buffer
			if Result = Void then
				create Result.make (16)
				internal_integer_buffer := Result
			end
		end

	internal_detachable_name_pointer: detachable MANAGED_POINTER
			-- (from FILE)
		note
			option: stable, transient
		attribute
		end

	internal_integer_buffer: detachable MANAGED_POINTER
			-- Internal integer buffer
			-- (from RAW_FILE)

	internal_name: READABLE_STRING_GENERAL
			-- Store the name of the file as it was given to us by the user
			-- to avoid conversion on storing as it is not necessary.
			-- (from FILE)

	internal_name_pointer: MANAGED_POINTER
			-- File system specific encoding of internal_name.
			-- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
			-- (from FILE)
		do
			if attached internal_detachable_name_pointer as l_ptr then
				Result := l_ptr
			else
				check
					internal_name_pointer_set: False
				then
				end
			end
		end

	internal_put_natural_16_big_endian (a_value: NATURAL_16)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			put_natural_8 (a_value.bit_shift_right (8).to_natural_8)
			put_natural_8 (a_value.bit_and (255).to_natural_8)
		end

	internal_put_natural_16_little_endian (a_value: NATURAL_16)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			put_natural_8 (a_value.bit_and (255).to_natural_8)
			put_natural_8 (a_value.bit_shift_right (8).to_natural_8)
		end

	internal_put_natural_32_big_endian (a_value: NATURAL_32)
			-- Write a_value at current position (Writing in Big-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			internal_put_natural_16_big_endian (a_value.bit_shift_right (16).to_natural_16)
			internal_put_natural_16_big_endian (a_value.bit_and (65535).to_natural_16)
		end

	internal_put_natural_32_little_endian (a_value: NATURAL_32)
			-- Write a_value at current position (Writing in Little-Endian order).
			-- (from GAME_FILE)
		require -- from GAME_FILE
			extendible: extendible
		do
			internal_put_natural_16_little_endian (a_value.bit_and (65535).to_natural_16)
			internal_put_natural_16_little_endian (a_value.bit_shift_right (16).to_natural_16)
		end

	internal_read_natural_16_big_endian
			-- Read the next 16-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_16
			l_old_natural_8: NATURAL_8
		do
			l_old_natural_8 := last_natural_8
			read_natural_8
			l_temp := last_natural_8.to_natural_16.bit_shift_left (8)
			read_natural_8
			last_natural_16 := last_natural_8.to_natural_16.bit_or (l_temp)
			last_natural_8 := l_old_natural_8
		end

	internal_read_natural_16_little_endian
			-- Read the next 16-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_16.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_16
			l_old_natural_8: NATURAL_8
		do
			l_old_natural_8 := last_natural_8
			read_natural_8
			l_temp := last_natural_8.to_natural_16
			read_natural_8
			last_natural_16 := l_temp.bit_or (last_natural_8.to_natural_16.bit_shift_left (8))
			last_natural_8 := l_old_natural_8
		end

	internal_read_natural_32_big_endian
			-- Read the next 32-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_32.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_32
			l_old_natural_16: NATURAL_16
		do
			l_old_natural_16 := last_natural_16
			internal_read_natural_16_big_endian
			l_temp := last_natural_16.to_natural_32.bit_shift_left (16)
			internal_read_natural_16_big_endian
			last_natural := last_natural_16.to_natural_32.bit_or (l_temp)
			last_natural_16 := l_old_natural_16
		end

	internal_read_natural_32_little_endian
			-- Read the next 32-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_32.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_32
			l_old_natural_16: NATURAL_16
		do
			l_old_natural_16 := last_natural_16
			internal_read_natural_16_little_endian
			l_temp := last_natural_16.to_natural_32
			internal_read_natural_16_little_endian
			last_natural := l_temp.bit_or (last_natural_16.to_natural_32.bit_shift_left (16))
			last_natural_16 := l_old_natural_16
		end

	internal_read_natural_64_big_endian
			-- Read the next 64-bit natural in the file (Reading in Big-Endian order).
			-- Make the result available in last_natural_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_64
			l_old_natural: NATURAL_32
		do
			l_old_natural := last_natural
			internal_read_natural_32_big_endian
			l_temp := last_natural_32.to_natural_64.bit_shift_left (16)
			internal_read_natural_32_big_endian
			last_natural_64 := last_natural_32.to_natural_64.bit_or (l_temp)
			last_natural := l_old_natural
		end

	internal_read_natural_64_little_endian
			-- Read the next 64-bit natural in the file (Reading in Little-Endian order).
			-- Make the result available in last_natural_64.
			-- (from GAME_FILE)
		require -- from GAME_FILE
			file_readable: is_readable
		local
			l_temp: NATURAL_64
			l_old_natural: NATURAL_32
		do
			l_old_natural := last_natural
			internal_read_natural_32_little_endian
			l_temp := last_natural_32.to_natural_64
			internal_read_natural_32_little_endian
			last_natural_64 := l_temp.bit_or (last_natural_32.to_natural_64.bit_shift_left (16))
			last_natural := l_old_natural
		end

	Read_data_buffer: C_STRING
			-- Buffer to read data in a thread aware context.
			-- (from FILE)
		once
			create Result.make_empty (Default_last_string_size)
		ensure -- from FILE
			read_data_buffer_not_void: Result /= Void
		end

	set_buffer
			-- Resynchronizes information on file
			-- (from FILE)
		require -- from FILE
			file_exists: exists
		do
			Buffered_file_info.fast_update (internal_name, internal_name_pointer)
		end

	set_name (a_name: READABLE_STRING_GENERAL)
			-- Set name with a_name.
			-- (from FILE)
		require -- from FILE
			a_name_not_void: a_name /= Void
		do
			internal_name := a_name
			internal_detachable_name_pointer := Buffered_file_info.file_name_to_pointer (a_name, internal_detachable_name_pointer)
		ensure -- from FILE
			name_set: internal_name = a_name
		end

	set_path (a_path: PATH)
			-- Set internal_name_pointer with a content matching a_path.
			-- (from FILE)
		require -- from FILE
			a_path_not_void: a_path /= Void
		do
			internal_name := a_path.name
			internal_detachable_name_pointer := a_path.to_pointer
		ensure -- from FILE
			path_set: path.same_as (a_path)
		end

	True_string: STRING_8
			-- Character string "true"
			-- (from FILE)
		once
			Result := "True"
		end
	
feature {FILE_ITERATION_CURSOR} -- Implementation

	file_open (f_name: POINTER; how: INTEGER_32): POINTER
			-- File pointer for file f_name, in mode how.
			-- (from RAW_FILE)
		external
			"C signature (EIF_FILENAME, int): EIF_POINTER use %"eif_file.h%""
		alias
			"eif_file_binary_open"
		end
	
feature {FILE} -- Implementation

	Append_file: INTEGER_32 = 3
			-- (from FILE)

	Append_read_file: INTEGER_32 = 5
			-- (from FILE)

	Closed_file: INTEGER_32 = 0
			-- (from FILE)

	mode: INTEGER_32
			-- Input-output mode
			-- (from FILE)

	Read_file: INTEGER_32 = 1
			-- (from FILE)

	Read_write_file: INTEGER_32 = 4
			-- (from FILE)

	set_read_mode
			-- Define file mode as read.
			-- (from FILE)
		do
			mode := Read_file
		end

	set_write_mode
			-- Define file mode as write.
			-- (from FILE)
		do
			mode := Write_file
		end

	Write_file: INTEGER_32 = 2
			-- (from FILE)
	
feature -- CPF informations

	prunable: BOOLEAN
			-- Is there an item to be removed?
		require -- from  COLLECTION
			True
		do
			Result := False
		end

	sub_files_count: INTEGER_32
			-- The number of sub-file inside Current
		require
			cpf_file_is_valid: is_valid
		do
			Result := sub_files_infos.count
		end

	sub_files_infos: LIST [TUPLE [pos: INTEGER_32; length: INTEGER_32]]
			-- Position and length of every sub files in the package file
	
feature -- Convenience

	copy_to (file: CPF_PACKAGE_FILE)
			-- Copy content of current from current cursor
			-- position to end of file into file from
			-- current cursor position of file.
			-- (from FILE)
		require -- from FILE
			file_not_void: file /= Void
			file_is_open_write: file.is_open_write
			current_is_open_read: is_open_read
		local
			l_modulo, l_read, nb: INTEGER_32
			l_pos: INTEGER_32
			l_old_last_string: like last_string
		do
			from
				l_read := 0
				nb := count
				l_modulo := 51200
				l_old_last_string := last_string
				create last_string.make (l_modulo)
				l_pos := position
				if l_pos /= 0 then
					go (0)
				end
			until
				l_read >= nb
			loop
				read_stream (l_modulo);
				file.put_string (last_string)
				l_read := l_read + l_modulo
			end
			if l_pos /= 0 then
				go (l_pos)
			end
			last_string := l_old_last_string
		end
	
feature {NONE} -- Implementation - Routine

	process_cpf_file
			-- Valid that Current is a valid CPF file and retreive the informations
			-- of the file.
		local
			nbr: NATURAL_16
			pos, length: NATURAL_32
			i: INTEGER_32
		do
			go (0)
			read_natural_8
			if last_natural_8 /= 67 then
				is_valid := False
			end
			read_natural_8
			if last_natural_8 /= 80 then
				is_valid := False
			end
			read_natural_8
			if last_natural_8 /= 70 then
				is_valid := False
			end
			if can_read_16 then
				read_natural_16_big_endian
				nbr := last_natural_16
				sub_files_infos := create {ARRAYED_LIST [TUPLE [pos: INTEGER_32; length: INTEGER_32]]}.make (nbr.to_integer_32)
				from
					i := 1
				until
					i > nbr.to_integer_32 or not is_valid
				loop
					if can_read_32 then
						read_natural_32_big_endian
						pos := last_natural_32
						if can_read_32 then
							read_natural_32_big_endian
							length := last_natural_32;
							sub_files_infos.extend ([pos.to_integer_32, length.to_integer_32])
							i := i + 1
						else
							is_valid := False
						end
					else
						is_valid := False
					end
				end
			else
				is_valid := False
			end
		end
	
feature {NONE} -- Implemetntation - Variables

	cpf_infos: LIST [POINTER]
			-- The internal CustomPackageFileInfos C structures

	Custom_package_file_infos_size: INTEGER_32
			-- The size in byte of a CustomPackageFileInfos C structure
		once
			Result := {CPF_EXTERNAL}.c_sizeof_custom_package_file_infos
		end
	
feature -- Input

	read_character
			-- Read a new character.
			-- Make result available in last_character.
			-- Was declared in FILE as synonym of readchar.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_character := file_gc (file_pointer)
		end

	read_data (p: POINTER; nb_bytes: INTEGER_32)
		obsolete "Use `read_to_managed_pointer' instead. [2017-05-31]"
			-- Read a string of at most nb_bytes bound bytes
			-- or until end of file.
			-- Make result available in p.
			-- (from RAW_FILE)
		require -- from RAW_FILE
			p_not_null: p /= default_pointer
			is_readable: file_readable
		do
			bytes_read := file_fread (p, 1, nb_bytes, file_pointer)
		end

	read_double
			-- Read the binary representation of a new double
			-- from file. Make result available in last_double.
			-- Was declared in RAW_FILE as synonym of readdouble and read_real_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := file_gdb (file_pointer)
		end

	read_integer
			-- Read the binary representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in RAW_FILE as synonym of readint and read_integer_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_integer := file_gib (file_pointer)
		end

	read_integer_16
			-- Read the binary representation of a new 16-bit integer
			-- from file. Make result available in last_integer_16.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 2)
			last_integer_16 := integer_buffer.read_integer_16 (0)
		end

	read_integer_32
			-- Read the binary representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in RAW_FILE as synonym of read_integer and readint.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			last_integer := file_gib (file_pointer)
		end

	read_integer_64
			-- Read the binary representation of a new 64-bit integer
			-- from file. Make result available in last_integer_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 8)
			last_integer_64 := integer_buffer.read_integer_64 (0)
		end

	read_integer_8
			-- Read the binary representation of a new 8-bit integer
			-- from file. Make result available in last_integer_8.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 1)
			last_integer_8 := integer_buffer.read_integer_8 (0)
		end

	read_line
			-- Read a string until new line or end of file.
			-- Make result available in last_string.
			-- New line will be consumed but not part of last_string.
			-- Was declared in FILE as synonym of readline.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			str_area: ANY
			done: BOOLEAN
			l: like last_string
		do
			l := last_string
			from
				str_area := l.area
				str_cap := l.capacity
			until
				done
			loop
				read := read + file_gs (file_pointer, $str_area.to_pointer, str_cap, read)
				if read > str_cap then
					l.set_count (str_cap)
					if str_cap < 2048 then
						l.grow (str_cap + 1024)
					else
						l.automatic_grow
					end
					str_cap := l.capacity
					read := read - 1
					str_area := l.area
				else
					l.set_count (read)
					done := True
				end
			end
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_line_thread_aware
			-- Read characters until a new line or
			-- end of medium.
			-- Make result available in last_string.
			-- Functionally identical to read_line but
			-- won't prevent garbage collection from occurring
			-- while blocked waiting for data, though data must
			-- be copied an extra time.			
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			done: BOOLEAN
			l: like last_string
			l_old_count, l_new_count: INTEGER_32
			l_buffer: like Read_data_buffer
		do
			l := last_string
			l_buffer := Read_data_buffer
			from
				l.wipe_out
				str_cap := l_buffer.capacity
			until
				done
			loop
				read := file_gs_ta (file_pointer, l_buffer.item, str_cap, 0)
				l_old_count := l.count
				l_new_count := l_old_count + read.min (str_cap)
				done := read <= str_cap;
				l.grow (l_new_count);
				l.set_count (l_new_count);
				l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
			end
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_natural
			-- Read the binary representation of a new 32-bit natural
			-- from file. Make result available in last_natural.
			-- Was declared in RAW_FILE as synonym of read_natural_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 4)
			last_natural := integer_buffer.read_natural_32 (0)
		end

	read_natural_16
			-- Read the binary representation of a new 16-bit natural
			-- from file. Make result available in last_natural_16.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 2)
			last_natural_16 := integer_buffer.read_natural_16 (0)
		end

	read_natural_32
			-- Read the binary representation of a new 32-bit natural
			-- from file. Make result available in last_natural.
			-- Was declared in RAW_FILE as synonym of read_natural.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 4)
			last_natural := integer_buffer.read_natural_32 (0)
		end

	read_natural_64
			-- Read the binary representation of a new 64-bit natural
			-- from file. Make result available in last_natural_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 8)
			last_natural_64 := integer_buffer.read_natural_64 (0)
		end

	read_natural_8
			-- Read the binary representation of a new 8-bit natural
			-- from file. Make result available in last_natural_8.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		do
			read_to_managed_pointer (integer_buffer, 0, 1)
			last_natural_8 := integer_buffer.read_natural_8 (0)
		end

	read_real
			-- Read the binary representation of a new real
			-- from file. Make result available in last_real.
			-- Was declared in RAW_FILE as synonym of readreal and read_real_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := file_grb (file_pointer)
		end

	read_real_32
			-- Read the binary representation of a new real
			-- from file. Make result available in last_real.
			-- Was declared in RAW_FILE as synonym of read_real and readreal.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := file_grb (file_pointer)
		end

	read_real_64
			-- Read the binary representation of a new double
			-- from file. Make result available in last_double.
			-- Was declared in RAW_FILE as synonym of read_double and readdouble.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := file_gdb (file_pointer)
		end

	read_stream (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- or until end of file.
			-- Make result available in last_string.
			-- Was declared in FILE as synonym of readstream.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			str_area: ANY
			l: like last_string
		do
			l := last_string;
			l.grow (nb_char)
			str_area := l.area;
			l.set_count (file_gss (file_pointer, $str_area.to_pointer, nb_char))
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_stream_thread_aware (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- or until end of medium is encountered.
			-- Make result available in last_string.
			-- Functionally identical to read_stream but
			-- won't prevent garbage collection from occurring
			-- while blocked waiting for data, though data must
			-- be copied an extra time.			
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			new_count: INTEGER_32
			l_buffer: like Read_data_buffer
			l_str: like last_string
		do
			l_str := last_string
			l_buffer := Read_data_buffer;
			l_buffer.set_count (nb_char)
			new_count := file_gss_ta (file_pointer, l_buffer.item, nb_char);
			l_buffer.set_count (new_count);
			l_str.grow (new_count);
			l_str.set_count (new_count);
			l_buffer.read_string_into (l_str)
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
			-- Read at most nb_bytes bound bytes and make result
			-- available in p at position start_pos.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			nb_bytes_non_negative: nb_bytes >= 0
			is_readable: readable
		require else -- from FILE
			p_not_void: p /= Void
			p_large_enough: p.count >= nb_bytes + start_pos
			is_readable: file_readable
		do
			bytes_read := file_fread (p.item + start_pos, 1, nb_bytes, file_pointer)
		ensure -- from IO_MEDIUM
			bytes_read_non_negative: bytes_read >= 0
			bytes_read_not_too_big: bytes_read <= nb_bytes
		end

	read_to_string (a_string: STRING_8; pos, nb: INTEGER_32): INTEGER_32
			-- Fill a_string, starting at position pos with at
			-- most nb characters read from current file.
			-- Return the number of characters actually read.
			-- (from RAW_FILE)
		require -- from FILE
			is_readable: file_readable
			not_end_of_file: not end_of_file
			a_string_not_void: a_string /= Void
			valid_position: a_string.valid_index (pos)
			nb_large_enough: nb > 0
			nb_small_enough: nb <= a_string.count - pos + 1
		do
			Result := file_gss (file_pointer, a_string.area.item_address (pos - 1), nb);
			a_string.reset_hash_codes
		ensure -- from FILE
			nb_char_read_large_enough: Result >= 0
			nb_char_read_small_enough: Result <= nb
			character_read: not end_of_file implies Result > 0
		end

	read_word
			-- Read a string, excluding white space and stripping
			-- leading white space.
			-- Make result available in last_string.
			-- White space characters are: blank, new_line, tab,
			-- vertical tab, formfeed, end of file.
			-- Was declared in FILE as synonym of readword.
			-- (from FILE)
		require -- from FILE
			is_readable: file_readable
		local
			str_area: ANY
			str_cap: INTEGER_32
			read: INTEGER_32
			l: like last_string
		do
			l := last_string
			from
				str_area := l.area
				str_cap := l.capacity
			until
				read > str_cap
			loop
				read := read + file_gw (file_pointer, $str_area.to_pointer, str_cap, read)
				if read > str_cap then
					if str_cap < 2048 then
						l.grow (str_cap + 1024)
					else
						l.automatic_grow
					end
					str_area := l.area
					str_cap := l.capacity
					read := read - 1
				else
					l.set_count (read)
					read := str_cap + 1
				end
			end
			separator := file_lh (file_pointer)
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end

	read_word_thread_aware
			-- Read a string, excluding white space and stripping
			-- leading white space.
			-- Make result available in last_string.
			-- White space characters are: blank, new_line, tab,
			-- vertical tab, formfeed, end of file.
			-- (from FILE)
		require -- from FILE
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			done: BOOLEAN
			l: like last_string
			l_old_count, l_new_count: INTEGER_32
			l_buffer: like Read_data_buffer
		do
			l := last_string
			l_buffer := Read_data_buffer
			from
				l.wipe_out
				str_cap := l_buffer.capacity
			until
				done
			loop
				read := file_gw_ta (file_pointer, l_buffer.item, str_cap, 0)
				l_old_count := l.count
				l_new_count := l_old_count + read.min (str_cap)
				done := read <= str_cap;
				l.grow (l_new_count);
				l.set_count (l_new_count);
				l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
			end
			separator := file_lh (file_pointer)
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end

	readchar
			-- Read a new character.
			-- Make result available in last_character.
			-- Was declared in FILE as synonym of read_character.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_character := file_gc (file_pointer)
		end

	readdouble
			-- Read the binary representation of a new double
			-- from file. Make result available in last_double.
			-- Was declared in RAW_FILE as synonym of read_double and read_real_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_double := file_gdb (file_pointer)
		end

	readint
			-- Read the binary representation of a new 32-bit integer
			-- from file. Make result available in last_integer.
			-- Was declared in RAW_FILE as synonym of read_integer and read_integer_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_integer := file_gib (file_pointer)
		end

	readline
			-- Read a string until new line or end of file.
			-- Make result available in last_string.
			-- New line will be consumed but not part of last_string.
			-- Was declared in FILE as synonym of read_line.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			str_cap: INTEGER_32
			read: INTEGER_32
			str_area: ANY
			done: BOOLEAN
			l: like last_string
		do
			l := last_string
			from
				str_area := l.area
				str_cap := l.capacity
			until
				done
			loop
				read := read + file_gs (file_pointer, $str_area.to_pointer, str_cap, read)
				if read > str_cap then
					l.set_count (str_cap)
					if str_cap < 2048 then
						l.grow (str_cap + 1024)
					else
						l.automatic_grow
					end
					str_cap := l.capacity
					read := read - 1
					str_area := l.area
				else
					l.set_count (read)
					done := True
				end
			end
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	readreal
			-- Read the binary representation of a new real
			-- from file. Make result available in last_real.
			-- Was declared in RAW_FILE as synonym of read_real and read_real_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		do
			last_real := file_grb (file_pointer)
		end

	readstream (nb_char: INTEGER_32)
			-- Read a string of at most nb_char bound characters
			-- or until end of file.
			-- Make result available in last_string.
			-- Was declared in FILE as synonym of read_stream.
			-- (from FILE)
		require -- from IO_MEDIUM
			is_readable: readable
		require else -- from FILE
			is_readable: file_readable
		local
			str_area: ANY
			l: like last_string
		do
			l := last_string;
			l.grow (nb_char)
			str_area := l.area;
			l.set_count (file_gss (file_pointer, $str_area.to_pointer, nb_char))
		ensure -- from IO_MEDIUM
			last_string_not_void: last_string /= Void
		end

	readword
			-- Read a string, excluding white space and stripping
			-- leading white space.
			-- Make result available in last_string.
			-- White space characters are: blank, new_line, tab,
			-- vertical tab, formfeed, end of file.
			-- Was declared in FILE as synonym of read_word.
			-- (from FILE)
		require -- from FILE
			is_readable: file_readable
		local
			str_area: ANY
			str_cap: INTEGER_32
			read: INTEGER_32
			l: like last_string
		do
			l := last_string
			from
				str_area := l.area
				str_cap := l.capacity
			until
				read > str_cap
			loop
				read := read + file_gw (file_pointer, $str_area.to_pointer, str_cap, read)
				if read > str_cap then
					if str_cap < 2048 then
						l.grow (str_cap + 1024)
					else
						l.automatic_grow
					end
					str_area := l.area
					str_cap := l.capacity
					read := read - 1
				else
					l.set_count (read)
					read := str_cap + 1
				end
			end
			separator := file_lh (file_pointer)
		ensure -- from FILE
			last_string_not_void: last_string /= Void
		end
	
feature {FILE_ITERATION_CURSOR} -- Iteration

	file_fread (dest: POINTER; elem_size, nb_elems: INTEGER_32; file: POINTER): INTEGER_32
			-- Read nb_elems of size elem_size in file file and store them
			-- in location dest.
			-- (from RAW_FILE)
		external
			"C signature (void *, size_t, size_t, FILE *): EIF_INTEGER use <stdio.h>"
		alias
			"fread"
		end
	
feature -- Iteration

	do_all (action: PROCEDURE [CHARACTER_8])
			-- Apply action to every item.
			-- Semantics not guaranteed if action changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			action_exists: action /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after
			loop
				action.call ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end

	do_if (action: PROCEDURE [CHARACTER_8]; test: FUNCTION [CHARACTER_8, BOOLEAN])
			-- Apply action to every item that satisfies test.
			-- Semantics not guaranteed if action or test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			action_exists: action /= Void
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after
			loop
				if test.item ([item]) then
					action.call ([item])
				end
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end

	for_all (test: FUNCTION [CHARACTER_8, BOOLEAN]): BOOLEAN
			-- Is test true for all items?
			-- Semantics not guaranteed if test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
				Result := True
			until
				after or not Result
			loop
				Result := test.item ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		ensure then -- from LINEAR
			empty: is_empty implies Result
		end

	new_cursor: FILE_ITERATION_CURSOR
			-- Fresh cursor associated with current structure
			-- (from FILE)
		do
			create Result.make_open_read (internal_name_pointer)
		ensure -- from ITERABLE
			result_attached: Result /= Void
		end

	there_exists (test: FUNCTION [CHARACTER_8, BOOLEAN]): BOOLEAN
			-- Is test true for at least one item?
			-- Semantics not guaranteed if test changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
			-- (from LINEAR)
		require -- from TRAVERSABLE
			test_exists: test /= Void
		local
			c: detachable CURSOR
			cs: detachable CURSOR_STRUCTURE [CHARACTER_8]
		do
			if attached {CURSOR_STRUCTURE [CHARACTER_8]} Current as acs then
				cs := acs
				c := acs.cursor
			end
			from
				start
			until
				after or Result
			loop
				Result := test.item ([item])
				forth
			end
			if cs /= Void and c /= Void then
				cs.go_to (c)
			end
		end
	
feature {FILE_ITERATION_CURSOR} -- Iteration

	file_close (file: POINTER)
			-- Close file.
			-- (from FILE)
		external
			"C signature (FILE *) use %"eif_file.h%""
		alias
			"eif_file_close"
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	put_boolean (b: BOOLEAN)
			-- Write binary value of b at current position.
			-- Was declared in RAW_FILE as synonym of putbool.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			if b then
				put_character ('%/1/')
			else
				put_character ('%U')
			end
		end

	put_data (p: POINTER; size: INTEGER_32)
		obsolete "Use `put_managed_pointer' instead. [2017-05-31]"
			-- Put data of length size pointed by p at
			-- current position.
			-- (from RAW_FILE)
		require -- from RAW_FILE
			p_not_null: p /= default_pointer
			extendible: extendible
		do
			file_ps (file_pointer, p, size)
		end

	put_double (d: REAL_64)
			-- Write binary value d at current position.
			-- Was declared in RAW_FILE as synonym of putdouble and put_real_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pdb (file_pointer, d)
		end

	put_integer (i: INTEGER_32)
			-- Write binary value of i at current position.
			-- Was declared in RAW_FILE as synonym of putint and put_integer_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pib (file_pointer, i)
		end

	put_integer_16 (i: INTEGER_16)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_integer_16 (i, 0)
			put_managed_pointer (integer_buffer, 0, 2)
		end

	put_integer_32 (i: INTEGER_32)
			-- Write binary value of i at current position.
			-- Was declared in RAW_FILE as synonym of put_integer and putint.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pib (file_pointer, i)
		end

	put_integer_64 (i: INTEGER_64)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_integer_64 (i, 0)
			put_managed_pointer (integer_buffer, 0, 8)
		end

	put_integer_8 (i: INTEGER_8)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_integer_8 (i, 0)
			put_managed_pointer (integer_buffer, 0, 1)
		end

	put_natural (i: NATURAL_32)
			-- Write binary value of i at current position.
			-- Was declared in RAW_FILE as synonym of put_natural_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_natural_32 (i, 0)
			put_managed_pointer (integer_buffer, 0, 4)
		end

	put_natural_16 (i: NATURAL_16)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_natural_16 (i, 0)
			put_managed_pointer (integer_buffer, 0, 2)
		end

	put_natural_32 (i: NATURAL_32)
			-- Write binary value of i at current position.
			-- Was declared in RAW_FILE as synonym of put_natural.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_natural_32 (i, 0)
			put_managed_pointer (integer_buffer, 0, 4)
		end

	put_natural_64 (i: NATURAL_64)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_natural_64 (i, 0)
			put_managed_pointer (integer_buffer, 0, 8)
		end

	put_natural_8 (i: NATURAL_8)
			-- Write binary value of i at current position.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			integer_buffer.put_natural_8 (i, 0)
			put_managed_pointer (integer_buffer, 0, 1)
		end

	put_real (r: REAL_32)
			-- Write binary value of r at current position.
			-- Was declared in RAW_FILE as synonym of putreal and put_real_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_prb (file_pointer, r)
		end

	put_real_32 (r: REAL_32)
			-- Write binary value of r at current position.
			-- Was declared in RAW_FILE as synonym of put_real and putreal.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_prb (file_pointer, r)
		end

	put_real_64 (d: REAL_64)
			-- Write binary value d at current position.
			-- Was declared in RAW_FILE as synonym of put_double and putdouble.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pdb (file_pointer, d)
		end

	putbool (b: BOOLEAN)
			-- Write binary value of b at current position.
			-- Was declared in RAW_FILE as synonym of put_boolean.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			if b then
				put_character ('%/1/')
			else
				put_character ('%U')
			end
		end

	putdouble (d: REAL_64)
			-- Write binary value d at current position.
			-- Was declared in RAW_FILE as synonym of put_double and put_real_64.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pdb (file_pointer, d)
		end

	putint (i: INTEGER_32)
			-- Write binary value of i at current position.
			-- Was declared in RAW_FILE as synonym of put_integer and put_integer_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_pib (file_pointer, i)
		end

	putreal (r: REAL_32)
			-- Write binary value of r at current position.
			-- Was declared in RAW_FILE as synonym of put_real and put_real_32.
			-- (from RAW_FILE)
		require -- from IO_MEDIUM
			extendible: extendible
		do
			file_prb (file_pointer, r)
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
feature {CPF_RESSOURCE_MANAGER} -- The C pointer to the file infos structure

	internal_pointer: POINTER
			-- The internal pointer of the package file C structure
		require
			cpf_file_is_valid: is_valid
				current_sub_file_index /= 0
		do
			Result := cpf_infos.at (current_sub_file_index)
		end
	
invariant
	file_stream_ptr_not_null: not file_pointer.is_default_pointer

		-- from GAME_FILE
	file_ptr_not_null: not (is_closed xor file_pointer.is_default_pointer)

		-- from RAW_FILE
	not_plain_text: not is_plain_text

		-- from FILE
	valid_mode: Closed_file <= mode and mode <= Append_read_file
	name_exists: internal_name /= Void
	name_not_empty: not internal_name.is_empty

		-- from FINITE
	empty_definition: is_empty = (count = 0)

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

		-- from ACTIVE
	writable_constraint: writable implies readable
	empty_constraint: is_empty implies (not readable) and (not writable)

		-- from BILINEAR
	not_both: not (after and before)
	before_constraint: before implies off

		-- from LINEAR
	after_constraint: after implies off

		-- from TRAVERSABLE
	empty_constraint: is_empty implies off

end -- class CPF_PACKAGE_FILE

Generated by ISE EiffelStudio