File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 11-- ----------------------------------------------------------------------------
22-- G N A T C O L L --
33-- --
4- -- Copyright (C) 2020-2021 , AdaCore --
4+ -- Copyright (C) 2020-2022 , AdaCore --
55-- --
66-- This library is free software; you can redistribute it and/or modify it --
77-- under terms of the GNU General Public License as published by the Free --
4848 O_Mode := O_RDONLY or O_CLOEXEC;
4949 Perm := 0 ;
5050 when Write_Mode =>
51- O_Mode := O_WRONLY or O_CREAT or O_CLOEXEC;
51+ O_Mode := O_WRONLY or O_CREAT or O_CLOEXEC or O_TRUNC ;
5252 Perm := S_IRUSR or S_IWUSR or S_IRGRP or
5353 S_IWGRP or S_IROTH or S_IWOTH;
5454 when Append_Mode =>
Original file line number Diff line number Diff line change 11-- ----------------------------------------------------------------------------
22-- G N A T C O L L --
33-- --
4- -- Copyright (C) 2020-2021 , AdaCore --
4+ -- Copyright (C) 2020-2022 , AdaCore --
55-- --
66-- This library is free software; you can redistribute it and/or modify it --
77-- under terms of the GNU General Public License as published by the Free --
5454 O_Mode := Win32.Files.O_WRONLY
5555 or Win32.Files.O_CREAT
5656 or Win32.Files.O_NOINHERIT
57- or Win32.Files.O_BINARY;
57+ or Win32.Files.O_BINARY
58+ or Win32.Files.O_TRUNC;
5859 O_Perm := Win32.Files.S_IWRITE;
5960 when Append_Mode =>
6061 O_Mode := Win32.Files.O_WRONLY
Original file line number Diff line number Diff line change 5757 end ;
5858 Close (FD);
5959
60+ -- Check that opening a file in write mode truncates the file to size 0
61+
62+ declare
63+ Name : constant String := " non_empty_file" ;
64+ begin
65+ -- First create a file that contains several KB of data (just in case
66+ -- it makes a difference).
67+
68+ FD := Open (Name, Mode => Write_Mode);
69+ for C in Character range ' A' .. ' Z' loop
70+ for Dummy in 1 .. 10 loop
71+ Write (FD, (1 .. 80 => C));
72+ Write (FD, (1 => ASCII.LF));
73+ end loop ;
74+ end loop ;
75+
76+ Close (FD);
77+
78+ -- Then try to overwrite it
79+
80+ FD := Open (Name, Mode => Write_Mode);
81+ Write (FD, " not much here" );
82+ Close (FD);
83+
84+ -- Now, check that it contains data from the last write session only
85+
86+ FD := Open (Name, Mode => Read_Mode);
87+ declare
88+ File_Content : constant String := Read (FD);
89+ begin
90+ A.Assert (File_Content, " not much here" );
91+ end ;
92+ Close (FD);
93+ end ;
94+
6095 end ;
6196 return A.Report;
6297end Test ;
You can’t perform that action at this time.
0 commit comments