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 1
1
-- ----------------------------------------------------------------------------
2
2
-- G N A T C O L L --
3
3
-- --
4
- -- Copyright (C) 2020-2021 , AdaCore --
4
+ -- Copyright (C) 2020-2022 , AdaCore --
5
5
-- --
6
6
-- This library is free software; you can redistribute it and/or modify it --
7
7
-- under terms of the GNU General Public License as published by the Free --
48
48
O_Mode := O_RDONLY or O_CLOEXEC;
49
49
Perm := 0 ;
50
50
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 ;
52
52
Perm := S_IRUSR or S_IWUSR or S_IRGRP or
53
53
S_IWGRP or S_IROTH or S_IWOTH;
54
54
when Append_Mode =>
Original file line number Diff line number Diff line change 1
1
-- ----------------------------------------------------------------------------
2
2
-- G N A T C O L L --
3
3
-- --
4
- -- Copyright (C) 2020-2021 , AdaCore --
4
+ -- Copyright (C) 2020-2022 , AdaCore --
5
5
-- --
6
6
-- This library is free software; you can redistribute it and/or modify it --
7
7
-- under terms of the GNU General Public License as published by the Free --
54
54
O_Mode := Win32.Files.O_WRONLY
55
55
or Win32.Files.O_CREAT
56
56
or Win32.Files.O_NOINHERIT
57
- or Win32.Files.O_BINARY;
57
+ or Win32.Files.O_BINARY
58
+ or Win32.Files.O_TRUNC;
58
59
O_Perm := Win32.Files.S_IWRITE;
59
60
when Append_Mode =>
60
61
O_Mode := Win32.Files.O_WRONLY
Original file line number Diff line number Diff line change 57
57
end ;
58
58
Close (FD);
59
59
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
+
60
95
end ;
61
96
return A.Report;
62
97
end Test ;
You can’t perform that action at this time.
0 commit comments