145
|
1
|
|
2 /* Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
|
|
3 * http://www.digitalmars.com
|
|
4 * Distributed under the Boost Software License, Version 1.0.
|
|
5 * http://www.boost.org/LICENSE_1_0.txt
|
|
6 * https://github.com/dlang/dmd/blob/master/src/dmd/root/file.h
|
|
7 */
|
|
8
|
|
9 #pragma once
|
|
10
|
|
11 #include "dsystem.h"
|
|
12 #include "array.h"
|
|
13
|
|
14 typedef Array<struct File *> Files;
|
|
15
|
|
16 struct FileName;
|
|
17
|
|
18 struct File
|
|
19 {
|
|
20 int ref; // != 0 if this is a reference to someone else's buffer
|
|
21 unsigned char *buffer; // data for our file
|
|
22 size_t len; // amount of data in buffer[]
|
|
23
|
|
24 FileName *name; // name of our file
|
|
25
|
|
26 File(const char *);
|
|
27 static File *create(const char *);
|
|
28 File(const FileName *);
|
|
29 ~File();
|
|
30
|
|
31 const char *toChars();
|
|
32
|
|
33 /* Read file, return true if error
|
|
34 */
|
|
35
|
|
36 bool read();
|
|
37
|
|
38 /* Write file, return true if error
|
|
39 */
|
|
40
|
|
41 bool write();
|
|
42
|
|
43 /* Set buffer
|
|
44 */
|
|
45
|
|
46 void setbuffer(void *buffer, size_t len)
|
|
47 {
|
|
48 this->buffer = (unsigned char *)buffer;
|
|
49 this->len = len;
|
|
50 }
|
|
51
|
|
52 void remove(); // delete file
|
|
53 };
|