/[eiffelstudio]/FreeELKS/trunk/library/kernel/file.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/file.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92166 - (show annotations)
Sun Feb 3 22:18:37 2013 UTC (6 years, 11 months ago) by manus_eiffel
File size: 48172 byte(s)
Made it compile by adding inheritance to NATIVE_STRING_HANDLER.

1 note
2 description:
3 "Sequential files, viewed as persistent sequences of characters"
4 library: "Free implementation of ELKS library"
5 copyright: "Copyright (c) 1986-2008, Eiffel Software and others"
6 license: "Eiffel Forum License v2 (see forum.txt)"
7 date: "$Date$"
8 revision: "$Revision$"
9
10 deferred class FILE inherit
11
12 UNBOUNDED [CHARACTER]
13
14 SEQUENCE [CHARACTER]
15 undefine
16 prune
17 redefine
18 off, append
19 end
20
21 IO_MEDIUM
22 rename
23 handle as descriptor,
24 handle_available as descriptor_available
25 redefine
26 read_stream_thread_aware,
27 read_line_thread_aware
28 end
29
30 NATIVE_STRING_HANDLER
31
32 feature -- Initialization
33
34 make (fn: STRING)
35 -- Create file object with `fn' as file name.
36 require
37 string_exists: fn /= Void
38 string_not_empty: not fn.is_empty
39 do
40 make_with_name (fn)
41 ensure
42 file_named: internal_name = fn
43 file_closed: is_closed
44 end
45
46 make_with_name (fn: STRING)
47 -- Create file object with `fn' as file name.
48 require
49 fn_exists: fn /= Void
50 fn_not_empty: not fn.is_empty
51 do
52 set_name (fn)
53 mode := Closed_file
54 file_pointer := default_pointer
55 create last_string.make_empty
56 ensure
57 file_closed: is_closed
58 end
59
60 make_open_read (fn: STRING)
61 -- Create file object with `fn' as file name
62 -- and open file in read mode.
63 require
64 string_exists: fn /= Void
65 string_not_empty: not fn.is_empty
66 do
67 make_with_name (fn)
68 open_read
69 ensure
70 file_named: internal_name = fn
71 exists: exists
72 open_read: is_open_read
73 end
74
75 make_open_write (fn: STRING)
76 -- Create file object with `fn' as file name
77 -- and open file for writing;
78 -- create it if it does not exist.
79 require
80 string_exists: fn /= Void
81 string_not_empty: not fn.is_empty
82 do
83 make_with_name (fn)
84 open_write
85 ensure
86 file_named: internal_name = fn
87 exists: exists
88 open_write: is_open_write
89 end
90
91 make_open_append (fn: STRING)
92 -- Create file object with `fn' as file name
93 -- and open file in append-only mode.
94 require
95 string_exists: fn /= Void
96 string_not_empty: not fn.is_empty
97 do
98 make_with_name (fn)
99 open_append
100 ensure
101 file_named: internal_name = fn
102 exists: exists
103 open_append: is_open_append
104 end
105
106 make_open_read_write (fn: STRING)
107 -- Create file object with `fn' as file name
108 -- and open file for both reading and writing.
109 require
110 string_exists: fn /= Void
111 string_not_empty: not fn.is_empty
112 do
113 make_with_name (fn)
114 open_read_write
115 ensure
116 file_named: internal_name = fn
117 exists: exists
118 open_read: is_open_read
119 open_write: is_open_write
120 end
121
122 make_create_read_write (fn: STRING)
123 -- Create file object with `fn' as file name
124 -- and open file for both reading and writing;
125 -- create it if it does not exist.
126 require
127 string_exists: fn /= Void
128 string_not_empty: not fn.is_empty
129 do
130 make_with_name (fn)
131 create_read_write
132 ensure
133 file_named: internal_name = fn
134 exists: exists
135 open_read: is_open_read
136 open_write: is_open_write
137 end
138
139 make_open_read_append (fn: STRING)
140 -- Create file object with `fn' as file name
141 -- and open file for reading anywhere
142 -- but writing at the end only.
143 -- Create file if it does not exist.
144 require
145 string_exists: fn /= Void
146 string_not_empty: not fn.is_empty
147 do
148 make_with_name (fn)
149 open_read_append
150 ensure
151 file_named: internal_name = fn
152 exists: exists
153 open_read: is_open_read
154 open_append: is_open_append
155 end
156
157 feature -- Access
158
159 name: STRING
160 -- File name as a STRING_8 instance. The value might be truncated
161 -- from the original name used to create the current FILE instance.
162 do
163 Result := internal_name.as_string_8
164 ensure then
165 name_not_empty: not Result.is_empty
166 end
167
168 item: CHARACTER
169 -- Current item
170 do
171 read_character
172 Result := last_character
173 back
174 end
175
176 position: INTEGER
177 -- Current cursor position.
178 do
179 if not is_closed then
180 Result := file_tell (file_pointer)
181 end
182 end
183
184 descriptor: INTEGER
185 -- File descriptor as used by the operating system.
186 require else
187 file_opened: not is_closed
188 do
189 Result := file_fd (file_pointer)
190 descriptor_available := True
191 end
192
193 descriptor_available: BOOLEAN
194
195 separator: CHARACTER
196 -- ASCII code of character following last word read
197
198 file_pointer: POINTER
199 -- File pointer as required in C
200
201 file_info: FILE_INFO
202 -- Collected information about the file.
203 do
204 set_buffer
205 Result := buffered_file_info.twin
206 end
207
208 inode: INTEGER
209 -- I-node number
210 require
211 file_exists: exists
212 do
213 set_buffer
214 Result := buffered_file_info.inode
215 end
216
217 links: INTEGER
218 -- Number of links on file
219 require
220 file_exists: exists
221 do
222 set_buffer
223 Result := buffered_file_info.links
224 end
225
226 user_id: INTEGER
227 -- User identification of owner
228 require
229 file_exists: exists
230 do
231 set_buffer
232 Result := buffered_file_info.user_id
233 end
234
235 group_id: INTEGER
236 -- Group identification of owner
237 require
238 file_exists: exists
239 do
240 set_buffer
241 Result := buffered_file_info.group_id
242 end
243
244 protection: INTEGER
245 -- Protection mode, in decimal value
246 require
247 file_exists: exists
248 do
249 set_buffer
250 Result := buffered_file_info.protection
251 end
252
253 owner_name: STRING
254 -- Name of owner
255 require
256 file_exists: exists
257 do
258 set_buffer
259 Result := buffered_file_info.owner_name
260 end
261
262 date: INTEGER
263 -- Time stamp (time of last modification)
264 require
265 file_exists: exists
266 do
267 Result := eif_file_date (internal_name_pointer.item)
268 end
269
270 access_date: INTEGER
271 -- Time stamp of last access made to the inode.
272 require
273 file_exists: exists
274 do
275 Result := eif_file_access_date (internal_name_pointer.item)
276 end
277
278 retrieved: ANY
279 -- Retrieved object structure
280 -- To access resulting object under correct type,
281 -- use assignment attempt.
282 -- Will raise an exception (code `Retrieve_exception')
283 -- if content is not a stored Eiffel structure.
284 do
285 (create {MISMATCH_CORRECTOR}).mismatch_information.do_nothing
286 Result := c_retrieved (descriptor)
287 end
288
289 feature -- Measurement
290
291 count: INTEGER
292 -- Size in bytes (0 if no associated physical file)
293 do
294 if exists then
295 if not is_open_write then
296 set_buffer
297 Result := buffered_file_info.size
298 else
299 Result := file_size (file_pointer)
300 end
301 end
302 end
303
304 feature -- Status report
305
306 after: BOOLEAN
307 -- Is there no valid cursor position to the right of cursor position?
308 do
309 Result := not is_closed and then (end_of_file or count = 0)
310 end
311
312 before: BOOLEAN
313 -- Is there no valid cursor position to the left of cursor position?
314 do
315 Result := is_closed
316 end
317
318 off: BOOLEAN
319 -- Is there no item?
320 do
321 Result := (count = 0) or else is_closed or else end_of_file
322 end
323
324 end_of_file: BOOLEAN
325 -- Has an EOF been detected?
326 require
327 opened: not is_closed
328 do
329 Result := file_feof (file_pointer)
330 end
331
332 exists: BOOLEAN
333 -- Does physical file exist?
334 -- (Uses effective UID.)
335 do
336 Result := file_exists (internal_name_pointer.item)
337 ensure then
338 unchanged_mode: mode = old mode
339 end
340
341 access_exists: BOOLEAN
342 -- Does physical file exist?
343 -- (Uses real UID.)
344 do
345 Result := file_access (internal_name_pointer.item, 0)
346 end
347
348 path_exists: BOOLEAN
349 -- Does physical file `name' exist without resolving
350 -- symbolic links?
351 do
352 Result := file_path_exists (internal_name_pointer.item)
353 ensure then
354 unchanged_mode: mode = old mode
355 end
356
357 is_readable: BOOLEAN
358 -- Is file readable?
359 -- (Checks permission for effective UID.)
360 do
361 set_buffer
362 Result := buffered_file_info.is_readable
363 end
364
365 is_writable: BOOLEAN
366 -- Is file writable?
367 -- (Checks write permission for effective UID.)
368 do
369 set_buffer
370 Result := buffered_file_info.is_writable
371 end
372
373 is_executable: BOOLEAN
374 -- Is file executable?
375 -- (Checks execute permission for effective UID.)
376 do
377 set_buffer
378 Result := buffered_file_info.is_executable
379 end
380
381 is_creatable: BOOLEAN
382 -- Is file creatable in parent directory?
383 -- (Uses effective UID to check that parent is writable
384 -- and file does not exist.)
385 do
386 Result := file_creatable (internal_name_pointer.item, internal_name_pointer.count)
387 end
388
389 is_plain: BOOLEAN
390 -- Is file a plain file?
391 require
392 file_exists: exists
393 do
394 set_buffer
395 Result := buffered_file_info.is_plain
396 end
397
398 is_device: BOOLEAN
399 -- Is file a device?
400 require
401 file_exists: exists
402 do
403 set_buffer
404 Result := buffered_file_info.is_device
405 end
406
407 is_directory: BOOLEAN
408 -- Is file a directory?
409 require
410 file_exists: exists
411 do
412 set_buffer
413 Result := buffered_file_info.is_directory
414 end
415
416 is_symlink: BOOLEAN
417 -- Is file a symbolic link?
418 require
419 file_exists: exists
420 local
421 l_buffer: like buffered_file_info
422 l_is_following_symbolic_links: BOOLEAN
423 do
424 l_buffer := buffered_file_info
425 l_is_following_symbolic_links := l_buffer.is_following_symlinks
426 l_buffer.set_is_following_symlinks (False)
427 set_buffer
428 Result := l_buffer.is_symlink
429 l_buffer.set_is_following_symlinks (l_is_following_symbolic_links)
430 end
431
432 is_fifo: BOOLEAN
433 -- Is file a named pipe?
434 require
435 file_exists: exists
436 do
437 set_buffer
438 Result := buffered_file_info.is_fifo
439 end
440
441 is_socket: BOOLEAN
442 -- Is file a named socket?
443 require
444 file_exists: exists
445 do
446 set_buffer
447 Result := buffered_file_info.is_socket
448 end
449
450 is_block: BOOLEAN
451 -- Is file a block special file?
452 require
453 file_exists: exists
454 do
455 set_buffer
456 Result := buffered_file_info.is_block
457 end
458
459 is_character: BOOLEAN
460 -- Is file a character special file?
461 require
462 file_exists: exists
463 do
464 set_buffer
465 Result := buffered_file_info.is_character
466 end
467
468 is_setuid: BOOLEAN
469 -- Is file setuid?
470 require
471 file_exists: exists
472 do
473 set_buffer
474 Result := buffered_file_info.is_setuid
475 end
476
477 is_setgid: BOOLEAN
478 -- Is file setgid?
479 require
480 file_exists: exists
481 do
482 set_buffer
483 Result := buffered_file_info.is_setgid
484 end
485
486 is_sticky: BOOLEAN
487 -- Is file sticky (for memory swaps)?
488 require
489 file_exists: exists
490 do
491 set_buffer
492 Result := buffered_file_info.is_sticky
493 end
494
495 is_owner: BOOLEAN
496 -- Is file owned by effective UID?
497 require
498 file_exists: exists
499 do
500 set_buffer
501 Result := buffered_file_info.is_owner
502 end
503
504 is_access_readable: BOOLEAN
505 -- Is file readable by real UID?
506 require
507 file_exists: exists
508 do
509 set_buffer
510 Result := buffered_file_info.is_access_readable
511 end
512
513 is_access_writable: BOOLEAN
514 -- Is file writable by real UID?
515 require
516 file_exists: exists
517 do
518 set_buffer
519 Result := buffered_file_info.is_access_writable
520 end
521
522 is_access_executable: BOOLEAN
523 -- Is file executable by real UID?
524 require
525 file_exists: exists
526 do
527 set_buffer
528 Result := buffered_file_info.is_access_executable
529 end
530
531 is_access_owner: BOOLEAN
532 -- Is file owned by real UID?
533 require
534 file_exists: exists
535 do
536 set_buffer
537 Result := buffered_file_info.is_access_owner
538 end
539
540 file_readable: BOOLEAN
541 -- Is there a current item that may be read?
542 do
543 Result := (mode >= Read_write_file or mode = Read_file)
544 and readable
545 end
546
547 is_closed: BOOLEAN
548 -- Is file closed?
549 do
550 Result := mode = Closed_file
551 end
552
553 is_open_read: BOOLEAN
554 -- Is file open for reading?
555 do
556 Result := mode = Read_file or else
557 mode = Read_write_file or else
558 mode = Append_read_file
559 end
560
561 is_open_write: BOOLEAN
562 -- Is file open for writing?
563 do
564 Result := mode = Write_file or else
565 mode = Read_write_file or else
566 mode = Append_read_file or else
567 mode = Append_file
568 end
569
570 is_open_append: BOOLEAN
571 -- Is file open for appending?
572 do
573 Result := mode = Append_file or else
574 mode = Append_read_file
575 end
576
577 file_writable: BOOLEAN
578 -- Is there a current item that may be modified?
579 do
580 Result := mode >= Write_file
581 end
582
583 extendible: BOOLEAN
584 -- May new items be added?
585 do
586 Result := mode >= Write_file
587 end
588
589 file_prunable: BOOLEAN
590 -- May items be removed?
591 obsolete
592 "Use `prunable' instead."
593 do
594 end
595
596 full: BOOLEAN = False
597 -- Is structure filled to capacity?
598
599 prunable: BOOLEAN
600 -- Is there an item to be removed?
601 do
602 end
603
604 feature -- Comparison
605
606 same_file (fn: STRING): BOOLEAN
607 -- Is current file the same as `a_filename'?
608 require
609 fn_not_void: fn /= Void
610 fn_not_empty: not fn.is_empty
611 local
612 l_comparer: FILE_COMPARER
613 do
614 create l_comparer
615 Result := l_comparer.same_files (name, fn)
616 end
617
618 feature -- Status setting
619
620 open_read
621 -- Open file in read-only mode.
622 require
623 is_closed: is_closed
624 do
625 file_pointer := file_open (internal_name_pointer.item, 0)
626 mode := Read_file
627 ensure
628 exists: exists
629 open_read: is_open_read
630 end
631
632 open_write
633 -- Open file in write-only mode;
634 -- create it if it does not exist.
635 do
636 file_pointer := file_open (internal_name_pointer.item, 1)
637 mode := Write_file
638 ensure
639 exists: exists
640 open_write: is_open_write
641 end
642
643 open_append
644 -- Open file in append-only mode;
645 -- create it if it does not exist.
646 require
647 is_closed: is_closed
648 do
649 file_pointer := file_open (internal_name_pointer.item, 2)
650 mode := Append_file
651 ensure
652 exists: exists
653 open_append: is_open_append
654 end
655
656 open_read_write
657 -- Open file in read and write mode.
658 require
659 is_closed: is_closed
660 do
661 file_pointer := file_open (internal_name_pointer.item, 3)
662 mode := Read_write_file
663 ensure
664 exists: exists
665 open_read: is_open_read
666 open_write: is_open_write
667 end
668
669 create_read_write
670 -- Open file in read and write mode;
671 -- create it if it does not exist.
672 require
673 is_closed: is_closed
674 do
675 file_pointer := file_open (internal_name_pointer.item, 4)
676 mode := Read_write_file
677 ensure
678 exists: exists
679 open_read: is_open_read
680 open_write: is_open_write
681 end
682
683 open_read_append
684 -- Open file in read and write-at-end mode;
685 -- create it if it does not exist.
686 require
687 is_closed: is_closed
688 do
689 file_pointer := file_open (internal_name_pointer.item, 5)
690 mode := Append_read_file
691 ensure
692 exists: exists
693 open_read: is_open_read
694 open_append: is_open_append
695 end
696
697 fd_open_read (fd: INTEGER)
698 -- Open file of descriptor `fd' in read-only mode.
699 do
700 file_pointer := file_dopen (fd, 0)
701 mode := Read_file
702 ensure
703 exists: exists
704 open_read: is_open_read
705 end
706
707 fd_open_write (fd: INTEGER)
708 -- Open file of descriptor `fd' in write mode.
709 do
710 file_pointer := file_dopen (fd, 1)
711 mode := Write_file
712 ensure
713 exists: exists
714 open_write: is_open_write
715 end
716
717 fd_open_append (fd: INTEGER)
718 -- Open file of descriptor `fd' in append mode.
719 do
720 file_pointer := file_dopen (fd, 2)
721 mode := Append_file
722 ensure
723 exists: exists
724 open_append: is_open_append
725 end
726
727 fd_open_read_write (fd: INTEGER)
728 -- Open file of descriptor `fd' in read-write mode.
729 do
730 file_pointer := file_dopen (fd, 3)
731 mode := Read_write_file
732 ensure
733 exists: exists
734 open_read: is_open_read
735 open_write: is_open_write
736 end
737
738 fd_open_read_append (fd: INTEGER)
739 -- Open file of descriptor `fd'
740 -- in read and write-at-end mode.
741 do
742 file_pointer := file_dopen (fd, 5)
743 mode := Append_read_file
744 ensure
745 exists: exists
746 open_read: is_open_read
747 open_append: is_open_append
748 end
749
750 reopen_read (fname: STRING)
751 -- Reopen in read-only mode with file of name `fname';
752 -- create file if it does not exist.
753 require
754 is_open: not is_closed
755 valid_name: fname /= Void
756 do
757 set_name (fname)
758 file_pointer := file_reopen (internal_name_pointer.item, 0, file_pointer)
759 mode := Read_file
760 ensure
761 exists: exists
762 open_read: is_open_read
763 end
764
765 reopen_write (fname: STRING)
766 -- Reopen in write-only mode with file of name `fname';
767 -- create file if it does not exist.
768 require
769 is_open: not is_closed
770 valid_name: fname /= Void
771 do
772 set_name (fname)
773 file_pointer := file_reopen (internal_name_pointer.item, 1, file_pointer)
774 mode := Write_file
775 ensure
776 exists: exists
777 open_write: is_open_write
778 end
779
780 reopen_append (fname: STRING)
781 -- Reopen in append mode with file of name `fname';
782 -- create file if it does not exist.
783 require
784 is_open: not is_closed
785 valid_name: fname /= Void
786 do
787 set_name (fname)
788 file_pointer := file_reopen (internal_name_pointer.item, 2, file_pointer)
789 mode := Append_file
790 ensure
791 exists: exists
792 open_append: is_open_append
793 end
794
795 reopen_read_write (fname: STRING)
796 -- Reopen in read-write mode with file of name `fname'.
797 require
798 is_open: not is_closed
799 valid_name: fname /= Void
800 do
801 set_name (fname)
802 file_pointer := file_reopen (internal_name_pointer.item, 3, file_pointer)
803 mode := Read_write_file
804 ensure
805 exists: exists
806 open_read: is_open_read
807 open_write: is_open_write
808 end
809
810 recreate_read_write (fname: STRING)
811 -- Reopen in read-write mode with file of name `fname';
812 -- create file if it does not exist.
813 require
814 is_open: not is_closed
815 valid_name: fname /= Void
816 do
817 set_name (fname)
818 file_pointer := file_reopen (internal_name_pointer.item, 4, file_pointer)
819 mode := Read_write_file
820 ensure
821 exists: exists
822 open_read: is_open_read
823 open_write: is_open_write
824 end
825
826 reopen_read_append (fname: STRING)
827 -- Reopen in read and write-at-end mode with file
828 -- of name `fname'; create file if it does not exist.
829 require
830 is_open: not is_closed
831 valid_name: fname /= Void
832 do
833 set_name (fname)
834 file_pointer := file_reopen (internal_name_pointer.item, 5, file_pointer)
835 mode := Append_read_file
836 ensure
837 exists: exists
838 open_read: is_open_read
839 open_append: is_open_append
840 end
841
842 close
843 -- Close file.
844 do
845 file_close (file_pointer)
846 mode := Closed_file
847 file_pointer := default_pointer
848 descriptor_available := False
849 ensure then
850 is_closed: is_closed
851 end
852
853 feature -- Cursor movement
854
855 start
856 -- Go to first position.
857 require else
858 file_opened: not is_closed
859 do
860 file_go (file_pointer, 0)
861 end
862
863 finish
864 -- Go to last position.
865 require else
866 file_opened: not is_closed
867 do
868 file_recede (file_pointer, 0)
869 end
870
871 forth
872 -- Go to next position.
873 require else
874 file_opened: not is_closed
875 do
876 file_move (file_pointer, 1)
877 -- Try to trigger EOF.
878 -- Do not use `file_move' it does not trigger EOF.
879 file_gc (file_pointer).do_nothing
880 if not end_of_file then
881 back
882 end
883 end
884
885 back
886 -- Go back one position.
887 do
888 file_move (file_pointer, - 1)
889 end
890
891 move (offset: INTEGER)
892 -- Advance by `offset' from current location.
893 require
894 file_opened: not is_closed
895 do
896 file_move (file_pointer, offset)
897 end
898
899 go (abs_position: INTEGER)
900 -- Go to the absolute `position'.
901 -- (New position may be beyond physical length.)
902 require
903 file_opened: not is_closed
904 non_negative_argument: abs_position >= 0
905 do
906 file_go (file_pointer, abs_position)
907 end
908
909 recede (abs_position: INTEGER)
910 -- Go to the absolute `position' backwards,
911 -- starting from end of file.
912 require
913 file_opened: not is_closed
914 non_negative_argument: abs_position >= 0
915 do
916 file_recede (file_pointer, abs_position)
917 end
918
919 next_line
920 -- Move to next input line.
921 require
922 is_readable: file_readable
923 do
924 file_tnil (file_pointer)
925 end
926
927 feature -- Element change
928
929 extend (v: CHARACTER)
930 -- Include `v' at end.
931 do
932 put_character (v)
933 end
934
935 flush
936 -- Flush buffered data to disk.
937 -- Note that there is no guarantee that the operating
938 -- system will physically write the data to the disk.
939 -- At least it will end up in the buffer cache,
940 -- making the data visible to other processes.
941 require
942 is_open: not is_closed
943 do
944 file_flush (file_pointer)
945 end
946
947 link (fn: STRING)
948 -- Link current file to `fn'.
949 -- `fn' must not already exist.
950 require
951 file_exists: exists
952 -- `fn' does not exist already
953 local
954 l_ptr: MANAGED_POINTER
955 do
956 l_ptr := buffered_file_info.file_name_to_pointer (fn, Void)
957 file_link (internal_name_pointer.item, l_ptr.item)
958 end
959
960 append (f: like Current)
961 -- Append a copy of the contents of `f'.
962 require else
963 target_is_closed: is_closed
964 source_is_closed: f.is_closed
965 do
966 -- Open in append mode.
967 open_append
968 -- Open `f' in read mode.
969 f.open_read
970 -- Append contents of `f'.
971 file_append (file_pointer, f.file_pointer, f.count)
972 -- Close both files.
973 close
974 f.close
975 ensure then
976 new_count: count = old count + f.count
977 files_closed: f.is_closed and is_closed
978 end
979
980 put_integer, putint (i: INTEGER)
981 -- Write `i' at current position.
982 deferred
983 end
984
985 put_boolean, putbool (b: BOOLEAN)
986 -- Write `b' at current position.
987 deferred
988 end
989
990 put_real, putreal (r: REAL)
991 -- Write `r' at current position.
992 deferred
993 end
994
995 put_double, putdouble (d: DOUBLE)
996 -- Write `d' at current position.
997 deferred
998 end
999
1000 put_string, putstring (s: STRING)
1001 -- Write `s' at current position.
1002 local
1003 ext_s: ANY
1004 do
1005 if s.count /= 0 then
1006 ext_s := s.area
1007 file_ps (file_pointer, $ext_s, s.count)
1008 end
1009 end
1010
1011 put_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER)
1012 -- Put data of length `nb_bytes' pointed by `start_pos' index in `p' at
1013 -- current position.
1014 do
1015 file_ps (file_pointer, p.item + start_pos, nb_bytes)
1016 end
1017
1018 put_character, putchar (c: CHARACTER)
1019 -- Write `c' at current position.
1020 do
1021 file_pc (file_pointer, c)
1022 end
1023
1024 put_new_line, new_line
1025 -- Write a new line character at current position.
1026 do
1027 file_tnwl (file_pointer)
1028 end
1029
1030 stamp (time: INTEGER)
1031 -- Stamp with `time' (for both access and modification).
1032 require
1033 file_exists: exists
1034 do
1035 file_utime (internal_name_pointer.item, time, 2)
1036 ensure
1037 date_updated: date = time -- But race condition possible
1038 end
1039
1040 set_access (time: INTEGER)
1041 -- Stamp with `time' (access only).
1042 require
1043 file_exists: exists
1044 do
1045 file_utime (internal_name_pointer.item, time, 0)
1046 ensure
1047 acess_date_updated: access_date = time -- But race condition might occur
1048 date_unchanged: date = old date -- Modulo a race condition
1049 end
1050
1051 set_date (time: INTEGER)
1052 -- Stamp with `time' (modification time only).
1053 require
1054 file_exists: exists
1055 do
1056 file_utime (internal_name_pointer.item, time, 1)
1057 ensure
1058 access_date_unchanged: access_date = old access_date -- But race condition might occur
1059 date_updated: date = time -- Modulo a race condition
1060 end
1061
1062 change_name (new_name: STRING)
1063 -- Change file name to `new_name'.
1064 require
1065 new_name_not_void: new_name /= Void
1066 new_name_not_empty: not new_name.is_empty
1067 file_exists: exists
1068 local
1069 l_ptr: MANAGED_POINTER
1070 do
1071 l_ptr := buffered_file_info.file_name_to_pointer (new_name, Void)
1072 file_rename (internal_name_pointer.item, l_ptr.item)
1073 set_name (new_name)
1074 ensure
1075 name_changed: internal_name = new_name
1076 end
1077
1078
1079 add_permission (who, what: STRING)
1080 -- Add read, write, execute or setuid permission
1081 -- for `who' ('u', 'g' or 'o') to `what'.
1082 require
1083 -- `who @ 1 in {u, g, o}'
1084 -- For every `i' in 1 .. `what'.`count', `what' @ `i' in {w, r, x, s, t}'
1085 who_is_not_void: who /= Void
1086 what_is_not_void: what /= Void
1087 file_descriptor_exists: exists
1088 local
1089 ext_who, ext_what: ANY
1090 do
1091 ext_who := who.to_c
1092 ext_what := what.to_c
1093 file_perm (internal_name_pointer.item, $ext_who, $ext_what, 1)
1094 end
1095
1096 remove_permission (who, what: STRING)
1097 -- Remove read, write, execute or setuid permission
1098 -- for `who' ('u', 'g' or 'o') to `what'.
1099 require
1100 -- `who @ 1 in {u, g, o}'
1101 -- For every `i' in 1 .. `what'.`count', `what' @ `i' in {w, r, x, s, t}'
1102 who_is_not_void: who /= Void
1103 what_is_not_void: what /= Void
1104 file_descriptor_exists: exists
1105 local
1106 ext_who, ext_what: ANY
1107 do
1108 ext_who := who.to_c
1109 ext_what := what.to_c
1110 file_perm (internal_name_pointer.item, $ext_who, $ext_what, 0)
1111 end
1112
1113 change_mode (mask: INTEGER)
1114 -- Replace mode by `mask'.
1115 require
1116 file_exists: exists
1117 do
1118 file_chmod (internal_name_pointer.item, mask)
1119 end
1120
1121 change_owner (new_owner_id: INTEGER)
1122 -- Change owner of file to `new_owner_id' found in
1123 -- system password file. On some systems this
1124 -- requires super-user privileges.
1125 require
1126 file_exists: exists
1127 do
1128 file_chown (internal_name_pointer.item, new_owner_id)
1129 end
1130
1131 change_group (new_group_id: INTEGER)
1132 -- Change group of file to `new_group_id' found in
1133 -- system password file.
1134 require
1135 file_exists: exists
1136 do
1137 file_chgrp (internal_name_pointer.item, new_group_id)
1138 end
1139
1140 change_date: INTEGER
1141 -- Time stamp of last change.
1142 require
1143 file_exists: exists
1144 do
1145 set_buffer
1146 Result := buffered_file_info.change_date
1147 end
1148
1149 touch
1150 -- Update time stamp (for both access and modification).
1151 require
1152 file_exists: exists
1153 do
1154 file_touch (internal_name_pointer.item)
1155 ensure
1156 date_changed: date /= old date -- Race condition nearly impossible
1157 end
1158
1159 basic_store (object: ANY)
1160 -- Produce an external representation of the
1161 -- entire object structure reachable from `object'.
1162 -- Retrievable within current system only.
1163 do
1164 c_basic_store (descriptor, $object)
1165 end
1166
1167 general_store (object: ANY)
1168 -- Produce an external representation of the
1169 -- entire object structure reachable from `object'.
1170 -- Retrievable from other systems for same platform
1171 -- (machine architecture).
1172 --| This feature may use a visible name of a class written
1173 --| in the `visible' clause of the Ace file. This makes it
1174 --| possible to overcome class name clashes.
1175 do
1176 c_general_store (descriptor, $object)
1177 end
1178
1179 independent_store (object: ANY)
1180 -- Produce an external representation of the
1181 -- entire object structure reachable from `object'.
1182 -- Retrievable from other systems for the same or other
1183 -- platform (machine architecture).
1184 do
1185 c_independent_store (descriptor, $object)
1186 end
1187
1188 feature -- Removal
1189
1190 wipe_out
1191 -- Remove all items.
1192 require else
1193 is_closed: is_closed
1194 do
1195 open_write
1196 close
1197 end
1198
1199 delete
1200 -- Remove link with physical file.
1201 -- File does not physically disappear from the disk
1202 -- until no more processes reference it.
1203 -- I/O operations on it are still possible.
1204 -- A directory must be empty to be deleted.
1205 require
1206 exists: path_exists
1207 do
1208 file_unlink (internal_name_pointer.item)
1209 end
1210
1211 reset (fn: STRING)
1212 -- Change file name to `fn' and reset
1213 -- file descriptor and all information.
1214 require
1215 valid_file_name: fn /= Void
1216 do
1217 set_name (fn)
1218 if mode /= Closed_file then
1219 close
1220 end
1221 last_integer := 0
1222 last_real := 0.0
1223 last_double := 0.0
1224 last_character := '%U'
1225 last_string.wipe_out
1226 ensure
1227 file_renamed: internal_name = fn
1228 file_closed: is_closed
1229 end
1230
1231 feature -- Input
1232
1233 read_real, readreal
1234 -- Read a new real.
1235 -- Make result available in `last_real'.
1236 require else
1237 is_readable: file_readable
1238 deferred
1239 end
1240
1241 read_double, readdouble
1242 -- Read a new double.
1243 -- Make result available in `last_double'.
1244 require else
1245 is_readable: file_readable
1246 deferred
1247 end
1248
1249 read_character, readchar
1250 -- Read a new character.
1251 -- Make result available in `last_character'.
1252 require else
1253 is_readable: file_readable
1254 do
1255 last_character := file_gc (file_pointer)
1256 end
1257
1258 read_integer, readint
1259 -- Read a new integer.
1260 -- Make result available in `last_integer'.
1261 require else
1262 is_readable: file_readable
1263 deferred
1264 end
1265
1266 read_line, readline
1267 -- Read a string until new line or end of file.
1268 -- Make result available in `last_string'.
1269 -- New line will be consumed but not part of `last_string'.
1270 require else
1271 is_readable: file_readable
1272 local
1273 str_cap: INTEGER
1274 read: INTEGER -- Amount of bytes already read
1275 str_area: ANY
1276 done: BOOLEAN
1277 l: like last_string
1278 do
1279 l := last_string
1280 from
1281 str_area := l.area
1282 str_cap := l.capacity
1283 until
1284 done
1285 loop
1286 read := read + file_gs (file_pointer, $str_area, str_cap, read)
1287 if read > str_cap then
1288 -- End of line not reached yet
1289 --|The string must be consistently set before
1290 --|resizing.
1291 l.set_count (str_cap)
1292 if str_cap < 2048 then
1293 l.grow (str_cap + 1024)
1294 else
1295 -- Increase capacity by `Growth_percentage' as
1296 -- defined in RESIZABLE.
1297 l.automatic_grow
1298 end
1299 str_cap := l.capacity
1300 read := read - 1 -- True amount of byte read
1301 str_area := l.area
1302 else
1303 l.set_count (read)
1304 done := True
1305 end
1306 end
1307 end
1308
1309 read_line_thread_aware
1310 -- <Precursor>
1311 require else
1312 is_readable: file_readable
1313 local
1314 str_cap: INTEGER
1315 read: INTEGER -- Amount of bytes already read
1316 done: BOOLEAN
1317 l: like last_string
1318 l_old_count, l_new_count: INTEGER
1319 l_buffer: like read_data_buffer
1320 do
1321 l := last_string
1322 l_buffer := read_data_buffer
1323 from
1324 l.clear_all
1325 str_cap := l_buffer.capacity
1326 until
1327 done
1328 loop
1329 read := file_gs_ta (file_pointer, l_buffer.item, str_cap, 0)
1330 l_old_count := l.count
1331 l_new_count := l_old_count + read.min (str_cap)
1332 done := read <= str_cap
1333 l.grow (l_new_count)
1334 l.set_count (l_new_count)
1335 l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
1336 end
1337 end
1338
1339 read_stream, readstream (nb_char: INTEGER)
1340 -- Read a string of at most `nb_char' bound characters
1341 -- or until end of file.
1342 -- Make result available in `last_string'.
1343 require else
1344 is_readable: file_readable
1345 local
1346 new_count: INTEGER
1347 str_area: ANY
1348 l: like last_string
1349 do
1350 l := last_string
1351 l.grow (nb_char)
1352 str_area := l.area
1353 new_count := file_gss (file_pointer, $str_area, nb_char)
1354 l.set_count (new_count)
1355 end
1356
1357 read_stream_thread_aware (nb_char: INTEGER)
1358 -- <Precursor>
1359 require else
1360 is_readable: file_readable
1361 local
1362 new_count: INTEGER
1363 l_buffer: like read_data_buffer
1364 l_str: like last_string
1365 do
1366 l_str := last_string
1367 l_buffer := read_data_buffer
1368 l_buffer.set_count (nb_char)
1369 new_count := file_gss_ta (file_pointer, l_buffer.item, nb_char)
1370 l_buffer.set_count (new_count)
1371 l_str.grow (new_count)
1372 l_str.set_count (new_count)
1373 l_buffer.read_string_into (l_str)
1374 end
1375
1376 read_to_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER)
1377 -- Read at most `nb_bytes' bound bytes and make result
1378 -- available in `p' at position `start_pos'.
1379 require else
1380 p_not_void: p /= Void
1381 p_large_enough: p.count >= nb_bytes + start_pos
1382 is_readable: file_readable
1383 do
1384 bytes_read := file_gss (file_pointer, p.item + start_pos, nb_bytes)
1385 end
1386
1387 read_word, readword
1388 -- Read a string, excluding white space and stripping
1389 -- leading white space.
1390 -- Make result available in `last_string'.
1391 -- White space characters are: blank, new_line, tab,
1392 -- vertical tab, formfeed, end of file.
1393 require
1394 is_readable: file_readable
1395 local
1396 str_area: ANY
1397 str_cap: INTEGER
1398 read: INTEGER -- Amount of bytes already read
1399 l: like last_string
1400 do
1401 l := last_string
1402 from
1403 str_area := l.area
1404 str_cap := l.capacity
1405 until
1406 read > str_cap
1407 loop
1408 read := read +
1409 file_gw (file_pointer, $str_area, str_cap, read)
1410 if read > str_cap then
1411 -- End of word not reached yet.
1412 if str_cap < 2048 then
1413 l.grow (str_cap + 1024)
1414 else
1415 -- Increase capacity by `Growth_percentage' as
1416 -- defined in RESIZABLE.
1417 l.automatic_grow
1418 end
1419 str_area := l.area
1420 str_cap := l.capacity
1421 read := read - 1 -- True amount of byte read
1422 else
1423 l.set_count (read)
1424 read := str_cap + 1 -- End of loop
1425 end
1426 end
1427 separator := file_lh (file_pointer) -- Look ahead
1428 ensure
1429 last_string_not_void: last_string /= Void
1430 end
1431
1432 read_word_thread_aware
1433 -- Read a string, excluding white space and stripping
1434 -- leading white space.
1435 -- Make result available in `last_string'.
1436 -- White space characters are: blank, new_line, tab,
1437 -- vertical tab, formfeed, end of file.
1438 require
1439 is_readable: file_readable
1440 local
1441 str_cap: INTEGER
1442 read: INTEGER -- Amount of bytes already read
1443 done: BOOLEAN
1444 l: like last_string
1445 l_old_count, l_new_count: INTEGER
1446 l_buffer: like read_data_buffer
1447 do
1448 l := last_string
1449 l_buffer := read_data_buffer
1450 from
1451 l.clear_all
1452 str_cap := l_buffer.capacity
1453 until
1454 done
1455 loop
1456 read := file_gw_ta (file_pointer, l_buffer.item, str_cap, 0)
1457 l_old_count := l.count
1458 l_new_count := l_old_count + read.min (str_cap)
1459 done := read <= str_cap
1460 l.grow (l_new_count)
1461 l.set_count (l_new_count)
1462 l_buffer.copy_to_string (l, 1, l_old_count + 1, read.min (str_cap))
1463 end
1464 separator := file_lh (file_pointer) -- Look ahead
1465 ensure
1466 last_string_not_void: last_string /= Void
1467 end
1468
1469 feature -- Convenience
1470
1471 copy_to (file: like Current)
1472 -- Copy content of current from current cursor
1473 -- position to end of file into `file' from
1474 -- current cursor position of `file'.
1475 require
1476 file_not_void: file /= Void
1477 file_is_open_write: file.is_open_write
1478 current_is_open_read: is_open_read
1479 local
1480 l_modulo, l_read, nb: INTEGER
1481 l_pos: INTEGER
1482 l_old_last_string: like last_string
1483 do
1484 from
1485 l_read := 0
1486 nb := count
1487 l_modulo := 51200
1488 l_old_last_string := last_string
1489 create last_string.make (l_modulo)
1490 l_pos := position
1491 if l_pos /= 0 then
1492 go (0)
1493 end
1494 until
1495 l_read >= nb
1496 loop
1497 read_stream (l_modulo)
1498 file.put_string (last_string)
1499 l_read := l_read + l_modulo
1500 end
1501 -- Restore previous status of Current file.
1502 if l_pos /= 0 then
1503 go (l_pos)
1504 end
1505 last_string := l_old_last_string
1506 end
1507
1508 feature {NONE} -- Implementation
1509
1510 internal_name: STRING
1511 -- Store the name of the file as it was given to us by the user
1512 -- to avoid conversion on storing as it is not necessary.
1513
1514 internal_name_pointer: MANAGED_POINTER
1515 -- File system specific encoding of `internal_name'.
1516 -- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
1517 do
1518 if attached internal_detachable_name_pointer as l_ptr then
1519 Result := l_ptr
1520 else
1521 -- This is never True because `internal_detachable_name_pointer' is set during the creation
1522 -- of the FILE object.
1523 check internal_name_pointer_set: False then end
1524 end
1525 end
1526
1527 internal_detachable_name_pointer: detachable MANAGED_POINTER note option: stable, transient attribute end
1528 -- File system specific encoding of `internal_name'.
1529 -- Typically a UTF-16 sequence on Windows, a UTF-8 sequence on Unix.
1530
1531 set_name (a_name: STRING)
1532 -- Set `name' with `a_name'.
1533 require
1534 a_name_not_void: a_name /= Void
1535 do
1536 internal_name := a_name
1537 internal_detachable_name_pointer := buffered_file_info.file_name_to_pointer (a_name, internal_detachable_name_pointer)
1538 ensure
1539 name_set: internal_name = a_name
1540 end
1541
1542 create_last_string (a_min_size: INTEGER)
1543 -- Create new instance of `last_string' with a least `a_min_size'
1544 -- as capacity.
1545 obsolete
1546 "Implementors should create `last_string' directly."
1547 require
1548 last_string_void: last_string = Void
1549 a_min_size_non_negative: a_min_size >= 0
1550 do
1551 create last_string.make (default_last_string_size.max (a_min_size))
1552 ensure
1553 last_string_attached: last_string /= Void
1554 capacity_set: attached last_string as l and then l.capacity >= a_min_size
1555 end
1556
1557 default_last_string_size: INTEGER = 256
1558 -- Default size for creating `last_string'
1559
1560 read_to_string (a_string: STRING; pos, nb: INTEGER): INTEGER
1561 -- Fill `a_string', starting at position `pos' with at
1562 -- most `nb' characters read from current file.
1563 -- Return the number of characters actually read.
1564 require
1565 is_readable: file_readable
1566 not_end_of_file: not end_of_file
1567 a_string_not_void: a_string /= Void
1568 valid_position: a_string.valid_index (pos)
1569 nb_large_enough: nb > 0
1570 nb_small_enough: nb <= a_string.count - pos + 1
1571 deferred
1572 ensure
1573 nb_char_read_large_enough: Result >= 0
1574 nb_char_read_small_enough: Result <= nb
1575 character_read: not end_of_file implies Result > 0
1576 end
1577
1578 true_string: STRING
1579 -- Character string "true"
1580 once
1581 Result := "True"
1582 end
1583
1584 false_string: STRING
1585 -- Character string "false"
1586 once
1587 Result := "False"
1588 end
1589
1590 buffered_file_info: FILE_INFO
1591 -- Information about the file.
1592 once
1593 create Result.make
1594 end
1595
1596 read_data_buffer: C_STRING
1597 -- Buffer to read data in a thread aware context.
1598 once
1599 create Result.make_empty (default_last_string_size)
1600 ensure
1601 read_data_buffer_not_void: Result /= Void
1602 end
1603
1604 set_buffer
1605 -- Resynchronizes information on file
1606 require
1607 file_exists: exists
1608 do
1609 buffered_file_info.fast_update (internal_name, internal_name_pointer)
1610 end
1611
1612 file_link (from_name, to_name: POINTER)
1613 -- Link `to_name' to `from_name'
1614 external
1615 "C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
1616 alias
1617 "eif_file_link"
1618 end
1619
1620 file_unlink (fname: POINTER)
1621 -- Delete file `fname'.
1622 external
1623 "C signature (EIF_FILENAME) use %"eif_file.h%""
1624 alias
1625 "eif_file_unlink"
1626 end
1627
1628 file_open (fname: POINTER; how: INTEGER): POINTER
1629 -- File pointer for file `fname', in mode `how'.
1630 external
1631 "C signature (EIF_FILENAME, int): EIF_POINTER use %"eif_file.h%""
1632 alias
1633 "eif_file_open"
1634 end
1635
1636 file_dopen (fd, how: INTEGER): POINTER
1637 -- File pointer for file of descriptor `fd' in mode `how'
1638 -- (which must fit the way `fd' was obtained).
1639 external
1640 "C signature (int, int): EIF_POINTER use %"eif_file.h%""
1641 alias
1642 "eif_file_dopen"
1643 end
1644
1645 file_reopen (fname: POINTER; how: INTEGER; file: POINTER): POINTER
1646 -- File pointer to `file', reopened to have new name `fname'
1647 -- in a mode specified by `how'.
1648 external
1649 "C signature (EIF_FILENAME, int, FILE *): EIF_POINTER use %"eif_file.h%""
1650 alias
1651 "eif_file_reopen"
1652 end
1653
1654 file_close (file: POINTER)
1655 -- Close `file'.
1656 external
1657 "C signature (FILE *) use %"eif_file.h%""
1658 alias
1659 "eif_file_close"
1660 end
1661
1662 file_flush (file: POINTER)
1663 -- Flush `file'.
1664 external
1665 "C signature (FILE *) use %"eif_file.h%""
1666 alias
1667 "eif_file_flush"
1668 end
1669
1670 file_fd (file: POINTER): INTEGER
1671 -- Operating system's file descriptor
1672 external
1673 "C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
1674 alias
1675 "eif_file_fd"
1676 end
1677
1678 file_gc (file: POINTER): CHARACTER
1679 -- Access the next character
1680 external
1681 "C blocking signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
1682 alias
1683 "eif_file_gc"
1684 end
1685
1686 file_gs (file: POINTER; a_string: POINTER; length, begin: INTEGER): INTEGER
1687 -- `a_string' updated with characters read from `file'
1688 -- until new line, with `begin' characters already read.
1689 -- If it does not fit, result is `length' - `begin' + 1.
1690 -- If it fits, result is number of characters read.
1691 external
1692 "C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1693 alias
1694 "eif_file_gs"
1695 end
1696
1697 file_gss (file: POINTER; a_string: POINTER; length: INTEGER): INTEGER
1698 -- Read min (`length', remaining bytes in file) characters
1699 -- into `a_string'. If it does not fit, result is `length' + 1.
1700 -- Otherwise, result is the number of characters read.
1701 external
1702 "C signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1703 alias
1704 "eif_file_gss"
1705 end
1706
1707 file_gw (file: POINTER; a_string: POINTER; length, begin: INTEGER): INTEGER
1708 -- Read a string excluding white space and stripping
1709 -- leading white space from `file' into `a_string'.
1710 -- White space characters are: blank, new_line,
1711 -- tab, vertical tab, formfeed or end of file.
1712 -- If it does not fit, result is `length' - `begin' + 1,
1713 -- otherwise result is number of characters read.
1714 external
1715 "C signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1716 alias
1717 "eif_file_gw"
1718 end
1719
1720 file_gs_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER): INTEGER
1721 -- Same as `file_gs' but it won't prevent garbage collection from occurring
1722 -- while blocked waiting for data.
1723 external
1724 "C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1725 alias
1726 "eif_file_gs"
1727 end
1728
1729 file_gss_ta (file: POINTER; a_string: POINTER; length: INTEGER): INTEGER
1730 -- Same as `file_gss' but it won't prevent garbage collection from occurring
1731 -- while blocked waiting for data.
1732
1733 external
1734 "C blocking signature (FILE *, char *, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1735 alias
1736 "eif_file_gss"
1737 end
1738
1739 file_gw_ta (file: POINTER; a_string: POINTER; length, begin: INTEGER): INTEGER
1740 -- Same as `file_gw' but it won't prevent garbage collection from occurring
1741 -- while blocked waiting for data.
1742 external
1743 "C blocking signature (FILE *, char *, EIF_INTEGER, EIF_INTEGER): EIF_INTEGER use %"eif_file.h%""
1744 alias
1745 "eif_file_gw"
1746 end
1747
1748 file_lh (file: POINTER): CHARACTER
1749 -- Look ahead in `file' and find out the value of the next
1750 -- character. Do not read over character.
1751 external
1752 "C signature (FILE *): EIF_CHARACTER use %"eif_file.h%""
1753 alias
1754 "eif_file_lh"
1755 end
1756
1757 file_size (file: POINTER): INTEGER
1758 -- Size of `file'
1759 external
1760 "C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
1761 alias
1762 "eif_file_size"
1763 end
1764
1765 file_tnil (file: POINTER)
1766 -- Read upto next input line.
1767 external
1768 "C signature (FILE *) use %"eif_file.h%""
1769 alias
1770 "eif_file_tnil"
1771 end
1772
1773 file_tell (file: POINTER): INTEGER
1774 -- Current cursor position in file.
1775 external
1776 "C signature (FILE *): EIF_INTEGER use %"eif_file.h%""
1777 alias
1778 "eif_file_tell"
1779 end
1780
1781 file_touch (fname: POINTER)
1782 -- Touch file `fname'.
1783 external
1784 "C signature (EIF_FILENAME) use %"eif_file.h%""
1785 alias
1786 "eif_file_touch"
1787 end
1788
1789 file_rename (old_name, new_name: POINTER)
1790 -- Change file name from `old_name' to `new_name'.
1791 external
1792 "C signature (EIF_FILENAME, EIF_FILENAME) use %"eif_file.h%""
1793 alias
1794 "eif_file_rename"
1795 end
1796
1797 file_perm (fname, who, what: POINTER; flag: INTEGER)
1798 -- Change permissions for `fname' to `who' and `what'.
1799 -- `flag' = 1 -> add permissions,
1800 -- `flag' = 0 -> remove permissions.
1801 external
1802 "C signature (EIF_FILENAME, char *, char *, int) use %"eif_file.h%""
1803 alias
1804 "eif_file_perm"
1805 end
1806
1807 file_chmod (fname: POINTER; mask: INTEGER)
1808 -- Change mode of `fname' to `mask'.
1809 external
1810 "C signature (EIF_FILENAME, int) use %"eif_file.h%""
1811 alias
1812 "eif_file_chmod"
1813 end
1814
1815 file_chown (fname: POINTER; new_owner: INTEGER)
1816 -- Change owner of `fname' to `new_owner'
1817 external
1818 "C signature (EIF_FILENAME, int) use %"eif_file.h%""
1819 alias
1820 "eif_file_chown"
1821 end
1822
1823 file_chgrp (fname: POINTER; new_group: INTEGER)
1824 -- Change group of `fname' to `new_group'
1825 external
1826 "C signature (EIF_FILENAME, int) use %"eif_file.h%""
1827 alias
1828 "eif_file_chgrp"
1829 end
1830
1831 file_utime (fname: POINTER; time, how: INTEGER)
1832 -- Set access, modification time or both (`how' = 0,1,2) on
1833 -- `fname', using `time' as time stamp.
1834 external
1835 "C signature (EIF_FILENAME, int, int) use %"eif_file.h%""
1836 alias
1837 "eif_file_utime"
1838 end
1839
1840 file_tnwl (file: POINTER)
1841 -- Print a new-line to `file'.
1842 external
1843 "C signature (FILE *) use %"eif_file.h%""
1844 alias
1845 "eif_file_tnwl"
1846 end
1847
1848 file_append (file, from_file: POINTER; length: INTEGER)
1849 -- Append a copy of `from_file' to `file'
1850 external
1851 "C signature (FILE *, FILE *, EIF_INTEGER) use %"eif_file.h%""
1852 alias
1853 "eif_file_append"
1854 end
1855
1856 file_ps (file: POINTER; a_string: POINTER; length: INTEGER)
1857 -- Print `a_string' to `file'.
1858 external
1859 "C signature (FILE *, char *, EIF_INTEGER) use %"eif_file.h%""
1860 alias
1861 "eif_file_ps"
1862 end
1863
1864 file_pc (file: POINTER; c: CHARACTER)
1865 -- Put `c' to end of `file'.
1866 external
1867 "C signature (FILE *, EIF_CHARACTER) use %"eif_file.h%""
1868 alias
1869 "eif_file_pc"
1870 end
1871
1872 file_go (file: POINTER; abs_position: INTEGER)
1873 -- Go to absolute `position', originated from start.
1874 external
1875 "C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
1876 alias
1877 "eif_file_go"
1878 end
1879
1880 file_recede (file: POINTER; abs_position: INTEGER)
1881 -- Go to absolute `position', originated from end.
1882 external
1883 "C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
1884 alias
1885 "eif_file_recede"
1886 end
1887
1888 file_move (file: POINTER; offset: INTEGER)
1889 -- Move file pointer by `offset'.
1890 external
1891 "C signature (FILE *, EIF_INTEGER) use %"eif_file.h%""
1892 alias
1893 "eif_file_move"
1894 end
1895
1896 file_feof (file: POINTER): BOOLEAN
1897 -- End of file?
1898 external
1899 "C signature (FILE *): EIF_BOOLEAN use %"eif_file.h%""
1900 alias
1901 "eif_file_feof"
1902 end
1903
1904 file_exists (fname: POINTER): BOOLEAN
1905 -- Does `fname' exist.
1906 external
1907 "C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
1908 alias
1909 "eif_file_exists"
1910 end
1911
1912 file_path_exists (fname: POINTER): BOOLEAN
1913 -- Does `fname' exist.
1914 external
1915 "C signature (EIF_FILENAME): EIF_BOOLEAN use %"eif_file.h%""
1916 alias
1917 "eif_file_path_exists"
1918 end
1919
1920 file_access (fname: POINTER; which: INTEGER): BOOLEAN
1921 -- Perform access test `which' on `fname' using real UID.
1922 external
1923 "C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
1924 alias
1925 "eif_file_access"
1926 end
1927
1928 file_creatable (fname: POINTER; n: INTEGER): BOOLEAN
1929 -- Is `fname' with `n' bytes creatable.
1930 external
1931 "C signature (EIF_FILENAME, EIF_INTEGER): EIF_BOOLEAN use %"eif_file.h%""
1932 alias
1933 "eif_file_creatable"
1934 end
1935
1936 c_retrieved (file_handle: INTEGER): detachable ANY
1937 -- Object structured retrieved from file of pointer
1938 -- `file_ptr'
1939 external
1940 "C use %"eif_retrieve.h%""
1941 alias
1942 "eretrieve"
1943 end
1944
1945 c_basic_store (file_handle: INTEGER; object: POINTER)
1946 -- Store object structure reachable form current object
1947 -- in file pointer `file_ptr'.
1948 external
1949 "C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
1950 alias
1951 "estore"
1952 end
1953
1954 c_general_store (file_handle: INTEGER; object: POINTER)
1955 -- Store object structure reachable form current object
1956 -- in file pointer `file_ptr'.
1957 external
1958 "C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
1959 alias
1960 "eestore"
1961 end
1962
1963 c_independent_store (file_handle: INTEGER; object: POINTER)
1964 -- Store object structure reachable form current object
1965 -- in file pointer `file_ptr'.
1966 external
1967 "C signature (EIF_INTEGER, EIF_REFERENCE) use %"eif_store.h%""
1968 alias
1969 "sstore"
1970 end
1971
1972 eif_file_date (a_path: POINTER): INTEGER
1973 -- Modification date of file named `a_path'.
1974 external
1975 "C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
1976 alias
1977 "eif_file_date"
1978 end
1979
1980 eif_file_access_date (a_path: POINTER): INTEGER
1981 -- Access date of a file named `a_path'.
1982 external
1983 "C signature (EIF_FILENAME): EIF_INTEGER use %"eif_file.h%""
1984 alias
1985 "eif_file_access_date"
1986 end
1987
1988 feature {NONE} -- Inapplicable
1989
1990 go_to (r: CURSOR)
1991 -- Move to position marked `r'.
1992 do
1993 end
1994
1995 replace (v: like item)
1996 -- Replace current item by `v'.
1997 do
1998 end
1999
2000 remove
2001 -- Remove current item.
2002 do
2003 end
2004
2005 prune (v: like item)
2006 -- Remove an occurrence of `v' if any.
2007 do
2008 ensure then
2009 count <= old count
2010 end
2011
2012 feature {FILE} -- Implementation
2013
2014 mode: INTEGER
2015 -- Input-output mode
2016
2017 Closed_file: INTEGER = 0
2018 Read_file: INTEGER = 1
2019 Write_file: INTEGER = 2
2020 Append_file: INTEGER = 3
2021 Read_Write_file: INTEGER = 4
2022 Append_Read_file: INTEGER = 5
2023
2024 set_read_mode
2025 -- Define file mode as read.
2026 do
2027 mode := Read_file
2028 end
2029
2030 set_write_mode
2031 -- Define file mode as write.
2032 do
2033 mode := Write_file
2034 end
2035
2036 platform_indicator: PLATFORM
2037 -- Platform indicator
2038 once
2039 create Result
2040 end
2041
2042 invariant
2043
2044 valid_mode: Closed_file <= mode and mode <= Append_read_file
2045 name_exists: internal_name /= Void
2046 name_not_empty: not internal_name.is_empty
2047
2048 note
2049 copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
2050 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
2051 source: "[
2052 Eiffel Software
2053 5949 Hollister Ave., Goleta, CA 93117 USA
2054 Telephone 805-685-1006, Fax 805-685-6869
2055 Website http://www.eiffel.com
2056 Customer support http://support.eiffel.com
2057 ]"
2058
2059 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23