note
	description: "Internal file information"
	library: "Free implementation of ELKS library"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	date: "$Date: 2020-05-19 14:29:33 +0000 (Tue, 19 May 2020) $"
	revision: "$Revision: 104259 $"

class 
	FILE_INFO

create 
	make

convert
	to_unix_file_info: {UNIX_FILE_INFO}

feature {NONE} -- Initialization

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

	make
			-- Creation procedure
		do
			make_filled_area (0, stat_size)
			is_following_symlinks := True
			exists := False
		ensure
			not_exists: not exists
			is_following_symlinks_set: is_following_symlinks
		end

	make_buffered_file_info (n: INTEGER_32)
			-- Creates a special object for n entries.
			-- (from TO_SPECIAL)
		require -- from TO_SPECIAL
			non_negative_argument: n >= 0
		do
			create buffered_file_info.make_empty (n)
		ensure -- from TO_SPECIAL
			area_allocated: buffered_file_info /= Void
			capacity_set: buffered_file_info.capacity = n
			count_set: buffered_file_info.count = 0
		end

	make_filled_area (a_default_value: NATURAL_8; n: INTEGER_32)
			-- Creates a special object for n entries.
			-- (from TO_SPECIAL)
		require -- from TO_SPECIAL
			non_negative_argument: n >= 0
		do
			create buffered_file_info.make_filled (a_default_value, n)
		ensure -- from TO_SPECIAL
			area_allocated: buffered_file_info /= Void
			capacity_set: buffered_file_info.capacity = n
			count_set: buffered_file_info.count = n
			area_filled: buffered_file_info.filled_with (a_default_value, 0, n - 1)
		end
	
feature -- Access

	access_date: INTEGER_32
			-- Date of last access
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 8)
		end

	buffered_file_info: SPECIAL [NATURAL_8]
			-- Special data zone.
			-- (from TO_SPECIAL)

	at alias "@" (i: INTEGER_32): NATURAL_8 assign put
			-- Entry at index i, if in index interval.
			-- Was declared in TO_SPECIAL as synonym of item.
			-- (from TO_SPECIAL)
		require -- from TO_SPECIAL
			valid_index: valid_index (i)
		do
			Result := buffered_file_info.item (i)
		end

	change_date: INTEGER_32
			-- Date of last status change
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 9)
		end

	date: INTEGER_32
			-- Last modification date
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 7)
		end

	device: INTEGER_32
			-- Device number on which inode resides
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 2)
		end

	device_type: INTEGER_32
			-- Device type on which inode resides
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 3)
		end

	file_entry: detachable PATH
			-- Associated entry for Current.
		do
			if attached internal_name_pointer as l_ptr then
				create Result.make_from_pointer (l_ptr.item)
			end
		end

	file_name: detachable STRING_8
		obsolete "Use `file_entry' to ensure that 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.
		do
			if attached internal_file_name as l_name then
				Result := l_name.as_string_8
			end
		end

	generating_type: TYPE [detachable FILE_INFO]
			-- 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

	group_id: INTEGER_32
			-- GID of the file
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 5)
		end

	group_name: STRING_8
			-- Name of the file group, if available from /etc/group.
			-- Otherwise, the GID
		require
			exists: exists
		do
			Result := file_group (group_id)
		end

	inode: INTEGER_32
			-- Inode number
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 1)
		end

	item alias "[]" (i: INTEGER_32): NATURAL_8 assign put
			-- Entry at index i, if in index interval.
			-- Was declared in TO_SPECIAL as synonym of at.
			-- (from TO_SPECIAL)
		require -- from TO_SPECIAL
			valid_index: valid_index (i)
		do
			Result := buffered_file_info.item (i)
		end

	links: INTEGER_32
			-- Number of links
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 10)
		end

	owner_name: STRING_8
			-- Name of the file owner, if available from /etc/passwd.
			-- Otherwise, the UID
		require
			exists: exists
		do
			Result := file_owner (user_id)
		end

	protection: INTEGER_32
			-- Protection mode of file (12 lower bits)
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 0)
		end

	size: INTEGER_32
			-- File size, in bytes
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 6)
		end

	type: INTEGER_32
			-- File type (4 bits, 12 lowest bits zeroed)
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 11)
		end

	user_id: INTEGER_32
			-- UID of the file owner
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 4)
		end
	
feature {NATIVE_STRING_HANDLER} -- Access

	file_name_to_pointer (a_name: READABLE_STRING_GENERAL; a_ptr: detachable MANAGED_POINTER): MANAGED_POINTER
			-- File system specific encoding of a_name that will be stored in a_ptr if provided
			-- otherwise a new instance is created.
			-- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
		require
			a_name_not_empty: not a_name.is_empty
		local
			u: UTF_CONVERTER
			l_c_string: C_STRING
		do
			Result := a_ptr
			if {PLATFORM}.is_windows then
				if attached {READABLE_STRING_32} a_name then
					if attached Result then
						Result.resize ((a_name.count + 1) * 2)
					else
						create Result.make ((a_name.count + 1) * 2)
					end;
					u.escaped_utf_32_substring_into_utf_16_0_pointer (a_name, 1, a_name.count, Result, 0, Void)
				else
					create l_c_string.make (a_name)
					if attached Result then
						Result.resize (multi_byte_to_utf_16 (l_c_string.item, default_pointer, 0))
					else
						create Result.make (multi_byte_to_utf_16 (l_c_string.item, default_pointer, 0))
					end;
					multi_byte_to_utf_16 (l_c_string.item, Result.item, Result.count).do_nothing
				end
			else
				if attached Result then
					Result.resize (a_name.count + 1)
				else
					create Result.make (a_name.count + 1)
				end
				if attached {READABLE_STRING_32} a_name then
					u.escaped_utf_32_substring_into_utf_8_0_pointer (a_name, 1, a_name.count, Result, 0, Void)
				else
					(create {C_STRING}.make_shared_from_pointer_and_count (Result.item, a_name.count)).set_string (a_name)
				end
			end
		end

	pointer_to_file_name_32 (a_ptr: POINTER): STRING_32
			-- Given a file system name represented by a_ptr provides a STRING_32 instance which
			-- could be escaped when underlying encoding is not valid.
		local
			u: UTF_CONVERTER
			l_managed: MANAGED_POINTER
		do
			create l_managed.share_from_pointer (a_ptr, pointer_length_in_bytes (a_ptr))
			if {PLATFORM}.is_windows then
				Result := u.utf_16_0_pointer_to_escaped_string_32 (l_managed)
			else
				Result := u.utf_8_0_pointer_to_escaped_string_32 (l_managed)
			end
		end

	pointer_to_file_name_8 (a_ptr: POINTER): STRING_8
			-- Given a file system name represented by a_ptr provides a STRING_8 instance.
			-- This is used for backward compatibility for APIs using STRING_8.
		local
			l_cstring: C_STRING
			l_count: INTEGER_32
		do
			if {PLATFORM}.is_windows then
				l_count := utf_16_to_multi_byte (a_ptr, default_pointer, 0)
				create l_cstring.make_empty (l_count)
				l_count := utf_16_to_multi_byte (a_ptr, l_cstring.item, l_count)
				Result := l_cstring.substring_8 (1, l_count - 1)
			else
				create l_cstring.make_shared_from_pointer (a_ptr)
				Result := l_cstring.string_8
			end
		end
	
feature {FILE_INFO} -- Access

	internal_file_name: detachable READABLE_STRING_GENERAL
			-- Store the name of the file as it was given to us by the user

	internal_name_pointer: detachable MANAGED_POINTER
			-- File system specific encoding of internal_file_name.
			-- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
			-- to avoid conversion on storing as it is not necessary.
	
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 -- 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: FILE_INFO): 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: like Current): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
		require -- from ANY
			other_not_void: other /= Void
		do
			if other = Current then
				Result := True
			elseif attached internal_file_name as l_file_name and attached other.internal_file_name as l_other_file_name then
				Result := l_file_name.same_string (l_other_file_name) and is_following_symlinks = other.is_following_symlinks
			end
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		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: FILE_INFO): 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

	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

	exists: BOOLEAN
			-- Does current file exists?

	is_access_executable: BOOLEAN
			-- Is file executable by real UID?
		require
			is_ready: is_ready
		do
			if attached internal_name_pointer as l_ptr then
				Result := file_access (l_ptr.item, 1)
			end
		end

	is_access_owner: BOOLEAN
			-- Is file owned by real UID?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 7)
		end

	is_access_readable: BOOLEAN
			-- Is file readable by real UID?
		require
			is_ready: is_ready
		do
			if attached internal_name_pointer as l_ptr then
				Result := file_access (l_ptr.item, 3)
			end
		end

	is_access_writable: BOOLEAN
			-- Is file writable by real UID?
		require
			is_ready: is_ready
		do
			if attached internal_name_pointer as l_ptr then
				Result := file_access (l_ptr.item, 2)
			end
		end

	is_block: BOOLEAN
			-- Is file a device block special file?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 16) /= 0
		end

	is_character: BOOLEAN
			-- Is file a character block special file?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 15) /= 0
		end

	is_device: BOOLEAN
			-- Is file a device?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 14) /= 0
		end

	is_directory: BOOLEAN
			-- Is file a directory?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 12) /= 0
		end

	is_executable: BOOLEAN
			-- Is file executable by effective UID?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 2)
		end

	is_fifo: BOOLEAN
			-- Is file a named pipe?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 17) /= 0
		end

	is_following_symlinks: BOOLEAN
			-- Does current follow symbolic links when retrieving properties?

	is_owner: BOOLEAN
			-- Is file owned by effective UID?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 6)
		end

	is_plain: BOOLEAN
			-- Is file a plain file?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 13) /= 0
		end

	is_readable: BOOLEAN
			-- Is file readable by effective UID?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 0)
		end

	is_ready: BOOLEAN
			-- Is current ready to perform a query?
		do
			Result := internal_file_name /= Void
		end

	is_setgid: BOOLEAN
			-- Is file setgid?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 4)
		end

	is_setuid: BOOLEAN
			-- Is file setuid?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 3)
		end

	is_socket: BOOLEAN
			-- Is file a named socket?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 19) /= 0
		end

	is_sticky: BOOLEAN
			-- Is file sticky?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 5)
		end

	is_symlink: BOOLEAN
			-- Is file a symbolic link?
		require
			exists: exists
		do
			Result := file_info ($buffered_file_info.to_pointer, 18) /= 0
		end

	is_writable: BOOLEAN
			-- Is file writable by effective UID?
		require
			exists: exists
		do
			Result := file_eaccess ($buffered_file_info.to_pointer, 1)
		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

	valid_index (i: INTEGER_32): BOOLEAN
			-- Is i within the bounds of Current?
			-- (from TO_SPECIAL)
		do
			Result := buffered_file_info.valid_index (i)
		end
	
feature -- Element change

	put (v: NATURAL_8; i: INTEGER_32)
			-- Replace i-th entry, if in index interval, by v.
			-- (from TO_SPECIAL)
		require -- from TO_SPECIAL
			valid_index: valid_index (i)
		do
			buffered_file_info.put (v, i)
		ensure -- from TO_SPECIAL
			inserted: item (i) = v
		end

	set_is_following_symlinks (v: BOOLEAN)
			-- Should update follow symlinks or not?
		do
			is_following_symlinks := v
		ensure
			is_following_symlinks_set: is_following_symlinks = v
		end

	update (f_name: READABLE_STRING_GENERAL)
			-- Update information buffer: fill it in with information
			-- from the inode of f_name.
		require
			f_name_not_empty: not f_name.is_empty
		do
			fast_update (f_name, file_name_to_pointer (f_name, internal_name_pointer))
		end
	
feature {FILE, DIRECTORY} -- Element change

	fast_update (f_name: READABLE_STRING_GENERAL; a_ptr: MANAGED_POINTER)
			-- Update information buffer: fill it in with information
			-- from the inode of f_name.
		require
			f_name_not_empty: not f_name.is_empty
			a_ptr_not_empty: a_ptr.count > 0
		do
			internal_file_name := f_name
			internal_name_pointer := a_ptr
			exists := eif_file_stat (a_ptr.item, $buffered_file_info.to_pointer, is_following_symlinks) = 0
		ensure
			file_name_set: internal_file_name = f_name
		end
	
feature {NONE} -- Element change

	set_area (other: like buffered_file_info)
			-- Make other the new area.
			-- (from TO_SPECIAL)
		do
			buffered_file_info := other
		ensure -- from TO_SPECIAL
			area_set: buffered_file_info = other
		end
	
feature -- Conversion

	to_unix_file_info: UNIX_FILE_INFO
		obsolete "Use `FILE_INFO' as type instead of `UNIX_FILE_INFO'. [2017-05-31]"
			-- Convert current to old format UNIX_FILE_INFO for backward compatibility.
		do
			create Result.make
			if attached internal_file_name as l_name then
				Result.update (l_name)
			end
		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: like Current)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		do
			if other /= Current then
				standard_copy (other)
				set_area (other.buffered_file_info.twin)
				if attached other.internal_name_pointer as l_pointer then
					internal_name_pointer := l_pointer.twin
				end
				if attached other.internal_file_name as l_file_name then
					internal_file_name := l_file_name.twin
				end
			end
		ensure -- from ANY
			is_equal: Current ~ other
		ensure then
			not_shared_if_different: other /= Current implies buffered_file_info /= other.buffered_file_info
			equal_buffered_file_infos: buffered_file_info ~ other.buffered_file_info
		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: FILE_INFO)
			-- 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: FILE_INFO
			-- 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: FILE_INFO)
			-- 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: FILE_INFO
			-- 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: FILE_INFO
			-- 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 FILE_INFO
		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 FILE_INFO
			-- 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 {NONE} -- Implementation

	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

	eif_file_stat (fname, stat_buf: POINTER; follow_symlinks: BOOLEAN): INTEGER_32
			-- Get information from file name into stat_buf
		external
			"C signature (EIF_FILENAME, rt_stat_buf *, int): EIF_INTEGER use %"eif_file.h%""
		end

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

	file_eaccess (stat_buf: POINTER; which: INTEGER_32): BOOLEAN
			-- Perform access tests using effective ID.
		external
			"C signature (rt_stat_buf *, int): EIF_BOOLEAN use %"eif_file.h%""
		alias
			"eif_file_eaccess"
		end

	file_group (gid: INTEGER_32): STRING_8
			-- Convert GID to group name if possible
		external
			"C signature (int): EIF_REFERENCE use %"eif_file.h%""
		alias
			"eif_file_group"
		end

	file_info (stat_buf: POINTER; which: INTEGER_32): INTEGER_32
			-- Extract information which from information buffer
		external
			"C signature (rt_stat_buf *, int): EIF_INTEGER use %"eif_file.h%""
		alias
			"eif_file_info"
		end

	file_owner (uid: INTEGER_32): STRING_8
			-- Convert UID to login name if possible
		external
			"C signature (int): EIF_REFERENCE use %"eif_file.h%""
		alias
			"eif_file_owner"
		end

	multi_byte_to_utf_16 (a_ptr, a_output: POINTER; a_output_length: INTEGER_32): INTEGER_32
			-- Given a 8-bit string a_ptr, fill a_output of length a_output_length with the UTF-16
			-- encoding of a_ptr but only if a_output is not the default_pointer, otherwise it returns
			-- the number of expected bytes to fill a_output including the null-terminating character.
		require
				{PLATFORM}.is_windows
		external
			"C inline use %"eif_eiffel.h%""
		alias
			"{
			#ifdef EIF_WINDOWS
				return (EIF_INTEGER) MultiByteToWideChar(CP_ACP, 0, (LPSTR) $a_ptr, -1, (LPWSTR) $a_output, (int) $a_output_length) * sizeof(wchar_t);
			#else
				return $a_output_length;
			#endif
			}"
		end

	stat_size: INTEGER_32
			-- Get size of 'rt_stat_buf' (in bytes)
		external
			"C use %"eif_file.h%""
		end

	utf_16_to_multi_byte (a_ptr: POINTER; a_output: POINTER; a_output_length: INTEGER_32): INTEGER_32
			-- Given a 16-bit string a_ptr encoded in UTF-16, fill a_output of length a_output_length with the
			-- 8-bit encoding of a_ptr but only if a_output is not the default_pointer, otherwise it returns
			-- the number of expected bytes to fill a_output including the null-terminated character.
		require
				{PLATFORM}.is_windows
		external
			"C inline use %"eif_eiffel.h%""
		alias
			"{
			#ifdef EIF_WINDOWS
				return (EIF_INTEGER) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) $a_ptr, -1, (LPSTR) $a_output, (int) $a_output_length, NULL, NULL);
			#else
				return $a_output_length;
			#endif
			}"
		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

	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
	
invariant
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class FILE_INFO

Generated by ISE EiffelStudio