tree checksum vpatch file split hunks
all signers: bvt phf
antecedents: vtools_vpatch_newline vtools_ksum
press order:
patch:
(7 . 3)(7 . 4)
5 517100 phf vtools_fixes_static_tohex Fixes for xalloc's use of static inline courtesy of spyked, fix broken ToHex implementation
6 517100 phf vtools_vpatch_newline Vpatch tool support for "No newline at end of file" directive.
7 543200 phf vtools_ksum Ksum standalone keccak hasher
8 547300 bvt vtools_tempfile_standalone_notmp Standalone temporary file generation code; creates temporary files in the vpatch work directory.
-(0 . 0)(1 . 71)
13 with Bits; use Bits;
14 with System; use System;
15 with SMG_Keccak; use SMG_Keccak;
16
17 package body Temporary_File is
18 -- Create a new file or exit when the file with specified name exists.
19 -- Use fopen(3) with "x" mode to create the file or error out if it
20 -- already exists.
21 subtype File_Ptr is System.Address;
22 subtype C_String is System.Address;
23
24 function fopen (Path: C_String;
25 Mode: C_String) return File_Ptr;
26 pragma Import (C, fopen);
27
28 procedure fclose (Stream: File_Ptr);
29 pragma Import (C, fclose);
30
31 function Create_File_Exclusive(Path: String) return Boolean is
32 Fptr: File_Ptr;
33 begin
34 declare
35 XP : aliased String := Path & ASCII.NUL;
36 XM : aliased String := "wx" & ASCII.NUL;
37 begin
38 Fptr := fopen(XP'Address, XM'Address);
39 end;
40 if Fptr = System.Null_Address then
41 return False;
42 end if;
43 fclose(Fptr);
44 return True;
45 end Create_File_Exclusive;
46
47 -- Create a temporary file with a randomly generated name;
48 -- if the file with random component F exists, retry with
49 -- H(F) as a new random component.
50 Function Temporary_File(Path_Prefix: String;
51 Seed: Bitstream) return String is
52 Hash: Bitstream(1..64*8);
53 Name_Ctx: Keccak_Context;
54
55 procedure Hash_Bitstream(Input: Bitstream) is
56 begin
57 KeccakBegin(Name_Ctx);
58 KeccakHash(Name_Ctx, Input);
59 KeccakEnd(Name_Ctx, Hash);
60 end Hash_Bitstream;
61 begin
62 Hash_Bitstream(Seed);
63 loop
64 declare
65 File_Name: String := Path_Prefix & ToHex(Hash);
66 begin
67 if Create_File_Exclusive(File_Name) then
68 return File_Name;
69 end if;
70 end;
71 Hash_Bitstream(Hash);
72 end loop;
73 end Temporary_File;
74
75 function Temporary_File(Path_Prefix: String;
76 Seed: String) return String is
77 B: Bitstream(1..Seed'Length*8);
78 begin
79 ToBitstream(Seed, B);
80 return Temporary_File(Path_Prefix, B);
81 end Temporary_File;
82
83 end Temporary_File;
-(0 . 0)(1 . 3)
88 package Temporary_File is
89 function Temporary_File(Path_Prefix: String; Seed: String) return String;
90 end Temporary_File;
- 23DCF3C0EFF5D5CA20CE1C5091E4DC9B739D2D98630208AA16DEC1298A13C28962089C0311E8E50AF9801C026E79F003FE8B9CE9341C351CB4E4556347D14734(1 . 6)(1 . 4)
95 with Bits; use Bits;
96 with Interfaces.C;
97 with Interfaces.C.Strings;
98 with Ada.Text_IO; use Ada.Text_IO;
99 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
100 with Character_IO; use Character_IO;
(11 . 6)(9 . 7)
102 with Ada.Characters.Latin_1;
103 with Ada.Sequential_IO;
104 with SMG_Keccak; use SMG_Keccak;
105 with Temporary_File; use Temporary_File;
106
107 procedure VPatch is
108 package Latin_1 renames Ada.Characters.Latin_1;
(59 . 36)(58 . 22)
110
111 -- Temporary File
112
113 procedure MkTemp(Template: Interfaces.C.Strings.Chars_Ptr);
114 pragma Import(C, mktemp);
115
116 function Temp_File_Name(Template: String) return String is
117 X: Interfaces.C.Strings.Chars_Ptr
118 := Interfaces.C.Strings.New_String(Template);
119 begin
120 MkTemp(X);
121 declare
122 Result: String := Interfaces.C.Strings.Value(X);
123 begin
124 Interfaces.C.Strings.Free(X);
125 return Result;
126 end;
127 end;
128
129 procedure Create_Temp(File : in out File_Type;
130 Mode : in File_Mode := Out_File;
131 Template : in String := "vpatch.XXX";
132 Prefix : in String;
133 Seed : in String := "";
134 Form : in String := "") is
135 Name: String := Temp_File_Name(Template);
136 Name: String := Temporary_File.Temporary_File(Prefix, Seed);
137 begin
138 Create(File, Mode, Name, Form);
139 end;
140
141 procedure Create_Temp(File : in out CIO.File_Type;
142 Mode : in CIO.File_Mode := CIO.Out_File;
143 Template : in String := "vpatch.XXX";
144 Prefix : in String;
145 Seed : in String := "";
146 Form : in String := "") is
147 Name: String := Temp_File_Name(Template);
148 Name: String := Temporary_File.Temporary_File(Prefix, Seed);
149 begin
150 Create(File, Mode, Name, Form);
151 end;
(466 . 7)(451 . 7)
153
154 -- prepare keccak and open files
155 KeccakBegin(To_Ctx);
156 Create_Temp(To_F, Template => "tmp.XXX");
157 Create_Temp(To_F, Prefix => "vpatch-", Seed => To_F_Name);
158 case Op is
159 when Op_Create =>
160 Has_Input_File := False;