aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar/platform_utils.h
blob: 65ba902dbf46af8a33472dc6dabddd7300d522b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_IJAR_PLATFORM_UTILS_H_
#define THIRD_PARTY_IJAR_PLATFORM_UTILS_H_

#include <stdlib.h>

#include <string>

#include "third_party/ijar/common.h"

namespace devtools_ijar {

// Platform-independent stat data.
struct Stat {
  // Total size of the file in bytes.
  int total_size;
  // The Unix file mode from the stat.st_mode field.
  mode_t file_mode;
  // True if this is a directory.
  bool is_directory;
};

// Writes stat data into `result` about the file under `path`.
// Returns true upon success: file is found and can be stat'ed.
// Returns false upon failure and reports the error to stderr.
bool stat_file(const char* path, Stat* result);

// Writes `size` bytes from `data` into file under `path`.
// The file is created or overwritten and is set to have `perm` permissions.
// Returns true upon success: file is created and all data is written.
// Returns false upon failure and reports the error to stderr.
bool write_file(const char* path, mode_t perm, const void* data, size_t size);

// Reads at most `size` bytes into `buffer` from the file under `path`.
// Returns true upon success: file is opened and all data is read.
// Returns false upon failure and reports the error to stderr.
bool read_file(const char* path, void* buffer, size_t size);

}  // namespace devtools_ijar

#endif  // THIRD_PARTY_IJAR_PLATFORM_UTILS_H_