| Nico Huber | f03ef4f | 2017-03-04 13:57:09 +0100 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2017 Nico Huber <nico.h@gmx.de> |
| 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | package HW.File is |
| 16 | |
| Nico Huber | a43b1ee | 2017-07-09 15:40:25 +0200 | [diff] [blame] | 17 | -- |
| Nico Huber | f03ef4f | 2017-03-04 13:57:09 +0100 | [diff] [blame] | 18 | -- Map a file's content into our address space |
| 19 | -- |
| Nico Huber | 967dd0d | 2017-07-09 15:51:08 +0200 | [diff] [blame] | 20 | -- If `Map_Copy` is `False`, `Len` bytes at `Offset` from the start |
| 21 | -- of the file given by `Path` should be mapped into the application's |
| 22 | -- address space using mmap(). |
| Nico Huber | a43b1ee | 2017-07-09 15:40:25 +0200 | [diff] [blame] | 23 | -- |
| 24 | -- If `Map_Copy` is `True`, anonymous memory should be mapped instead |
| 25 | -- and be filled with a copy of the file's content using read(). |
| 26 | -- |
| Nico Huber | 967dd0d | 2017-07-09 15:51:08 +0200 | [diff] [blame] | 27 | -- If `Len` is zero, the whole file should be mapped. |
| 28 | -- |
| Nico Huber | f03ef4f | 2017-03-04 13:57:09 +0100 | [diff] [blame] | 29 | procedure Map |
| Nico Huber | a43b1ee | 2017-07-09 15:40:25 +0200 | [diff] [blame] | 30 | (Addr : out Word64; |
| 31 | Path : in String; |
| Nico Huber | 967dd0d | 2017-07-09 15:51:08 +0200 | [diff] [blame] | 32 | Len : in Natural := 0; |
| 33 | Offset : in Natural := 0; |
| Nico Huber | f03ef4f | 2017-03-04 13:57:09 +0100 | [diff] [blame] | 34 | Readable : in Boolean := False; |
| 35 | Writable : in Boolean := False; |
| 36 | Map_Copy : in Boolean := False; |
| 37 | Success : out Boolean) |
| 38 | with |
| 39 | Pre => (Readable or Writable) and |
| 40 | (if Map_Copy then Readable and not Writable); |
| 41 | |
| Nico Huber | def89eb | 2017-08-18 17:38:55 +0200 | [diff] [blame] | 42 | -- Sets `Length` to the size of the file given by `Path` or 0 if an |
| 43 | -- error occurs. |
| 44 | procedure Size (Length : out Natural; Path : String); |
| 45 | |
| Nico Huber | f03ef4f | 2017-03-04 13:57:09 +0100 | [diff] [blame] | 46 | end HW.File; |