note description: "Sequential files, viewed as persistent sequences of characters" library: "Free implementation of ELKS library" status: "See notice at end of class." legal: "See notice at end of class." date: "$Date: 2020-05-28 16:02:59 +0000 (Thu, 28 May 2020) $" revision: "$Revision: 104378 $" deferred class interface FILE feature -- Initialization make_with_name (fn: READABLE_STRING_GENERAL) -- Create file object with fn as file name. require fn_exists: fn /= Void fn_not_empty: not fn.is_empty ensure file_named: internal_name = fn file_closed: is_closed make_with_path (a_path: PATH) -- Create file object with a_path as path. require a_path_attached: a_path /= Void a_path_not_empty: not a_path.is_empty ensure path_set: path.same_as (a_path) file_closed: is_closed make_open_read (fn: READABLE_STRING_GENERAL) -- Create file object with fn as file name -- and open file in read mode. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_read: is_open_read 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. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_write: is_open_write make_open_append (fn: READABLE_STRING_GENERAL) -- Create file object with fn as file name -- and open file in append-only mode. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_append: is_open_append make_open_read_write (fn: READABLE_STRING_GENERAL) -- Create file object with fn as file name -- and open file for both reading and writing. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_read: is_open_read open_write: is_open_write 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. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_read: is_open_read open_write: is_open_write 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. require string_exists: fn /= Void string_not_empty: not fn.is_empty ensure file_named: internal_name = fn exists: exists open_read: is_open_read open_append: is_open_append make_open_temporary -- Create a file object with a unique temporary file name, -- with read/write mode. ensure exists: exists open_read: is_open_read open_write: is_open_write 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. ensure exists: exists open_read: is_open_read open_write: is_open_write feature -- Access path: PATH -- Associated path of Current. ensure entry_not_empty: not Result.is_empty item: CHARACTER_8 -- Current item position: INTEGER_32 -- Current cursor position. descriptor: INTEGER_32 -- File descriptor as used by the operating system. require else file_opened: not is_closed descriptor_available: BOOLEAN -- Is the handle available after class has been -- created? separator: CHARACTER_8 -- ASCII code of character following last word read file_pointer: POINTER -- File pointer as required in C file_info: FILE_INFO -- Collected information about the file. inode: INTEGER_32 -- I-node number require file_exists: exists links: INTEGER_32 -- Number of links on file require file_exists: exists user_id: INTEGER_32 -- User identification of owner require file_exists: exists group_id: INTEGER_32 -- Group identification of owner require file_exists: exists protection: INTEGER_32 -- Protection mode, in decimal value require file_exists: exists owner_name: STRING_8 -- Name of owner require file_exists: exists date: INTEGER_32 -- Time stamp (time of last modification) require file_exists: exists access_date: INTEGER_32 -- Time stamp of last access made to the inode. require file_exists: exists 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. null_path: PATH -- Null device path. ensure instance_free: class null_name: STRING_8 -- Null device name. ensure instance_free: class feature -- Measurement count: INTEGER_32 -- Size in bytes (0 if no associated physical file) feature -- Status report after: BOOLEAN -- Is there no valid cursor position to the right of cursor position? before: BOOLEAN -- Is there no valid cursor position to the left of cursor position? off: BOOLEAN -- Is there no item? end_of_file: BOOLEAN -- Has an EOF been detected? require opened: not is_closed exists: BOOLEAN -- Does physical file exist? -- (Uses effective UID.) ensure then unchanged_mode: mode = old mode access_exists: BOOLEAN -- Does physical file exist? -- (Uses real UID.) path_exists: BOOLEAN -- Does physical file name exist without resolving -- symbolic links? ensure then unchanged_mode: mode = old mode is_readable: BOOLEAN -- Is file readable? -- (Checks permission for effective UID.) is_writable: BOOLEAN -- Is file writable? -- (Checks write permission for effective UID.) is_executable: BOOLEAN -- Is file executable? -- (Checks execute permission for effective UID.) is_creatable: BOOLEAN -- Is file creatable in parent directory? -- (Uses effective UID to check that parent is writable -- and file does not exist.) is_plain: BOOLEAN -- Is file a plain file? require file_exists: exists is_device: BOOLEAN -- Is file a device? require file_exists: exists is_directory: BOOLEAN -- Is file a directory? require file_exists: exists is_symlink: BOOLEAN -- Is file a symbolic link? require file_exists: path_exists is_fifo: BOOLEAN -- Is file a named pipe? require file_exists: exists is_socket: BOOLEAN -- Is file a named socket? require file_exists: exists is_block: BOOLEAN -- Is file a block special file? require file_exists: exists is_character: BOOLEAN -- Is file a character special file? require file_exists: exists is_setuid: BOOLEAN -- Is file setuid? require file_exists: exists is_setgid: BOOLEAN -- Is file setgid? require file_exists: exists is_sticky: BOOLEAN -- Is file sticky (for memory swaps)? require file_exists: exists is_owner: BOOLEAN -- Is file owned by effective UID? require file_exists: exists is_access_readable: BOOLEAN -- Is file readable by real UID? require file_exists: exists is_access_writable: BOOLEAN -- Is file writable by real UID? require file_exists: exists is_access_executable: BOOLEAN -- Is file executable by real UID? require file_exists: exists is_access_owner: BOOLEAN -- Is file owned by real UID? require file_exists: exists file_readable: BOOLEAN -- Is there a current item that may be read? is_closed: BOOLEAN -- Is file closed? is_open_read: BOOLEAN -- Is file open for reading? is_open_write: BOOLEAN -- Is file open for writing? is_open_append: BOOLEAN -- Is file open for appending? file_writable: BOOLEAN -- Is there a current item that may be modified? extendible: BOOLEAN -- May new items be added? replaceable: BOOLEAN -- Can current item be replaced? Full: BOOLEAN = False -- Is structure filled to capacity? prunable: BOOLEAN -- Is there an item to be removed? feature -- Comparison same_file (fn: READABLE_STRING_GENERAL): BOOLEAN -- Is current file the same as a_filename? require fn_not_void: fn /= Void fn_not_empty: not fn.is_empty feature -- Status setting open_read -- Open file in read-only mode. require is_closed: is_closed ensure exists: exists open_read: is_open_read open_write -- Open file in write-only mode; -- create it if it does not exist. ensure exists: exists open_write: is_open_write open_append -- Open file in append-only mode; -- create it if it does not exist. require is_closed: is_closed ensure exists: exists open_append: is_open_append open_read_write -- Open file in read and write mode. require is_closed: is_closed ensure exists: exists open_read: is_open_read open_write: is_open_write create_read_write -- Open file in read and write mode; -- create it if it does not exist. require is_closed: is_closed ensure exists: exists open_read: is_open_read open_write: is_open_write open_read_append -- Open file in read and write-at-end mode; -- create it if it does not exist. require is_closed: is_closed ensure exists: exists open_read: is_open_read open_append: is_open_append fd_open_read (fd: INTEGER_32) -- Open file of descriptor fd in read-only mode. ensure exists: exists open_read: is_open_read fd_open_write (fd: INTEGER_32) -- Open file of descriptor fd in write mode. ensure exists: exists open_write: is_open_write fd_open_append (fd: INTEGER_32) -- Open file of descriptor fd in append mode. ensure exists: exists open_append: is_open_append fd_open_read_write (fd: INTEGER_32) -- Open file of descriptor fd in read-write mode. ensure exists: exists open_read: is_open_read open_write: is_open_write fd_open_read_append (fd: INTEGER_32) -- Open file of descriptor fd -- in read and write-at-end mode. ensure exists: exists open_read: is_open_read open_append: is_open_append reopen_read (fname: READABLE_STRING_GENERAL) -- Reopen in read-only mode with file of name fname; -- create file if it does not exist. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_read: is_open_read reopen_write (fname: READABLE_STRING_GENERAL) -- Reopen in write-only mode with file of name fname; -- create file if it does not exist. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_write: is_open_write reopen_append (fname: READABLE_STRING_GENERAL) -- Reopen in append mode with file of name fname; -- create file if it does not exist. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_append: is_open_append reopen_read_write (fname: READABLE_STRING_GENERAL) -- Reopen in read-write mode with file of name fname. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_read: is_open_read open_write: is_open_write recreate_read_write (fname: READABLE_STRING_GENERAL) -- Reopen in read-write mode with file of name fname; -- create file if it does not exist. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_read: is_open_read open_write: is_open_write 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. require is_open: not is_closed valid_name: fname /= Void ensure exists: exists open_read: is_open_read open_append: is_open_append close -- Close file. ensure then is_closed: is_closed feature -- Cursor movement start -- Go to first position. require else file_opened: not is_closed finish -- Go to last position. require else file_opened: not is_closed forth -- Go to next position. require else file_opened: not is_closed back -- Go back one position. move (offset: INTEGER_32) -- Advance by offset from current location. require file_opened: not is_closed go (abs_position: INTEGER_32) -- Go to the absolute position. -- (New position may be beyond physical length.) require file_opened: not is_closed non_negative_argument: abs_position >= 0 recede (abs_position: INTEGER_32) -- Go to the absolute position backwards, -- starting from end of file. require file_opened: not is_closed non_negative_argument: abs_position >= 0 next_line -- Move to next input line. require is_readable: file_readable feature -- Iteration new_cursor: FILE_ITERATION_CURSOR -- Fresh cursor associated with current structure feature -- Element change extend (v: like item) -- Include v at 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. require is_open: not is_closed link (fn: READABLE_STRING_GENERAL) -- Link current file to fn. -- fn must not already exist. require file_exists: exists append (f: like Current) -- Append a copy of the contents of f. require else target_is_closed: is_closed source_is_closed: f.is_closed ensure then new_count: count = old count + f.count files_closed: f.is_closed and is_closed put_integer (i: INTEGER_32) -- Write i at current position. -- Was declared in FILE as synonym of putint. putint (i: INTEGER_32) -- Write i at current position. -- Was declared in FILE as synonym of put_integer. put_boolean (b: BOOLEAN) -- Write b at current position. -- Was declared in FILE as synonym of putbool. putbool (b: BOOLEAN) -- Write b at current position. -- Was declared in FILE as synonym of put_boolean. put_real (r: REAL_32) -- Write r at current position. -- Was declared in FILE as synonym of putreal. putreal (r: REAL_32) -- Write r at current position. -- Was declared in FILE as synonym of put_real. put_double (d: REAL_64) -- Write d at current position. -- Was declared in FILE as synonym of putdouble. putdouble (d: REAL_64) -- Write d at current position. -- Was declared in FILE as synonym of put_double. put_string (s: READABLE_STRING_8) -- Write s at current position. -- Was declared in FILE as synonym of putstring. putstring (s: READABLE_STRING_8) -- Write s at current position. -- Was declared in FILE as synonym of put_string. 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. put_character (c: CHARACTER_8) -- Write c at current position. -- Was declared in FILE as synonym of putchar. putchar (c: CHARACTER_8) -- Write c at current position. -- Was declared in FILE as synonym of put_character. put_new_line -- Write a new line character at current position. -- Was declared in FILE as synonym of new_line. new_line -- Write a new line character at current position. -- Was declared in FILE as synonym of put_new_line. stamp (time: INTEGER_32) -- Stamp with time (for both access and modification). require file_exists: exists ensure date_updated: date = time set_access (time: INTEGER_32) -- Stamp with time (access only). require file_exists: exists ensure acess_date_updated: access_date = time date_unchanged: date = old date set_date (time: INTEGER_32) -- Stamp with time (modification time only). require file_exists: exists ensure access_date_unchanged: access_date = old access_date date_updated: date = time rename_file (new_name: READABLE_STRING_GENERAL) -- Change file name to new_name require new_name_not_void: new_name /= Void new_name_not_empty: not new_name.is_empty file_exists: exists ensure name_changed: internal_name = new_name rename_path (new_path: PATH) -- Change file name to new_path require new_path_not_void: new_path /= Void new_path_not_empty: not new_path.is_empty file_exists: exists ensure name_changed: internal_name.same_string (new_path.name) add_permission (who, what: STRING_8) -- Add read, write, execute or setuid permission -- for who ('u', 'g' or 'o') to what. require who_is_not_void: who /= Void what_is_not_void: what /= Void file_descriptor_exists: exists remove_permission (who, what: STRING_8) -- Remove read, write, execute or setuid permission -- for who ('u', 'g' or 'o') to what. require who_is_not_void: who /= Void what_is_not_void: what /= Void file_descriptor_exists: exists change_mode (mask: INTEGER_32) -- Replace mode by mask. require file_exists: exists 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. require file_exists: exists change_group (new_group_id: INTEGER_32) -- Change group of file to new_group_id found in -- system password file. require file_exists: exists change_date: INTEGER_32 -- Time stamp of last change. require file_exists: exists touch -- Update time stamp (for both access and modification). require file_exists: exists ensure date_changed: date /= old date basic_store (object: ANY) -- Produce an external representation of the -- entire object structure reachable from object. -- Retrievable within current system only. 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). 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). feature -- Removal wipe_out -- Remove all items. require else is_closed: is_closed 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. require exists: path_exists reset (fn: READABLE_STRING_GENERAL) -- Change file name to fn and reset -- file descriptor and all information. require valid_file_name: fn /= Void ensure file_renamed: internal_name = fn file_closed: is_closed reset_path (fp: PATH) -- Change file name to fp and reset -- file descriptor and all information. require valid_file_name: fp /= Void ensure file_closed: is_closed feature -- Input read_real -- Read a new real. -- Make result available in last_real. -- Was declared in FILE as synonym of readreal and read_real_32. require else is_readable: file_readable readreal -- Read a new real. -- Make result available in last_real. -- Was declared in FILE as synonym of read_real and read_real_32. require else is_readable: file_readable read_real_32 -- Read a new real. -- Make result available in last_real. -- Was declared in FILE as synonym of read_real and readreal. require else is_readable: file_readable read_double -- Read a new double. -- Make result available in last_double. -- Was declared in FILE as synonym of readdouble and read_real_64. require else is_readable: file_readable readdouble -- Read a new double. -- Make result available in last_double. -- Was declared in FILE as synonym of read_double and read_real_64. require else is_readable: file_readable read_real_64 -- Read a new double. -- Make result available in last_double. -- Was declared in FILE as synonym of read_double and readdouble. require else is_readable: file_readable read_character -- Read a new character. -- Make result available in last_character. -- Was declared in FILE as synonym of readchar. require else is_readable: file_readable readchar -- Read a new character. -- Make result available in last_character. -- Was declared in FILE as synonym of read_character. require else is_readable: file_readable read_integer -- Read a new integer. -- Make result available in last_integer. -- Was declared in FILE as synonym of readint. require else is_readable: file_readable readint -- Read a new integer. -- Make result available in last_integer. -- Was declared in FILE as synonym of read_integer. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else is_readable: file_readable 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. require else p_not_void: p /= Void p_large_enough: p.count >= nb_bytes + start_pos is_readable: file_readable 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. require 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 ensure nb_char_read_large_enough: Result >= 0 nb_char_read_small_enough: Result <= nb character_read: not end_of_file implies Result > 0 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. require is_readable: file_readable ensure last_string_not_void: last_string /= Void 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. require is_readable: file_readable ensure last_string_not_void: last_string /= Void 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. require is_readable: file_readable ensure last_string_not_void: last_string /= Void feature -- Convenience copy_to (file: like Current) -- Copy content of current from current cursor -- position to end of file into file from -- current cursor position of file. require file_not_void: file /= Void file_is_open_write: file.is_open_write current_is_open_read: is_open_read feature -- Inapplicable replace (v: like item) -- Replace current item by v. remove -- Remove current item. prune (v: like item) -- Remove an occurrence of v if any. ensure then count <= old count invariant valid_mode: Closed_file <= mode and mode <= Append_read_file name_exists: internal_name /= Void name_not_empty: not internal_name.is_empty 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
Generated by ISE EiffelStudio