xref: /aosp_15_r20/art/libartbase/base/os.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2009 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBARTBASE_BASE_OS_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_LIBARTBASE_BASE_OS_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include <stdint.h>
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker namespace unix_file {
23*795d594fSAndroid Build Coastguard Worker class FdFile;
24*795d594fSAndroid Build Coastguard Worker }  // namespace unix_file
25*795d594fSAndroid Build Coastguard Worker 
26*795d594fSAndroid Build Coastguard Worker namespace art {
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker using File = ::unix_file::FdFile;
29*795d594fSAndroid Build Coastguard Worker 
30*795d594fSAndroid Build Coastguard Worker // Interface to the underlying OS platform.
31*795d594fSAndroid Build Coastguard Worker 
32*795d594fSAndroid Build Coastguard Worker class OS {
33*795d594fSAndroid Build Coastguard Worker  public:
34*795d594fSAndroid Build Coastguard Worker   // Open an existing file with read only access.
35*795d594fSAndroid Build Coastguard Worker   static File* OpenFileForReading(const char* name);
36*795d594fSAndroid Build Coastguard Worker 
37*795d594fSAndroid Build Coastguard Worker   // Open an existing file with read/write access.
38*795d594fSAndroid Build Coastguard Worker   static File* OpenFileReadWrite(const char* name);
39*795d594fSAndroid Build Coastguard Worker 
40*795d594fSAndroid Build Coastguard Worker   // Create an empty file with read/write access. This is a *new* file, that is, if the file
41*795d594fSAndroid Build Coastguard Worker   // already exists, it is *not* overwritten, but unlinked, and a new inode will be used.
42*795d594fSAndroid Build Coastguard Worker   static File* CreateEmptyFile(const char* name);
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker   // Create an empty file with write access. This is a *new* file, that is, if the file
45*795d594fSAndroid Build Coastguard Worker   // already exists, it is *not* overwritten, but unlinked, and a new inode will be used.
46*795d594fSAndroid Build Coastguard Worker   static File* CreateEmptyFileWriteOnly(const char* name);
47*795d594fSAndroid Build Coastguard Worker 
48*795d594fSAndroid Build Coastguard Worker   // Open a file with the specified open(2) flags.
49*795d594fSAndroid Build Coastguard Worker   static File* OpenFileWithFlags(const char* name, int flags, bool auto_flush = true);
50*795d594fSAndroid Build Coastguard Worker 
51*795d594fSAndroid Build Coastguard Worker   // Check if a file exists.
52*795d594fSAndroid Build Coastguard Worker   static bool FileExists(const char* name, bool check_file_type = true);
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   // Check if a directory exists.
55*795d594fSAndroid Build Coastguard Worker   static bool DirectoryExists(const char* name);
56*795d594fSAndroid Build Coastguard Worker 
57*795d594fSAndroid Build Coastguard Worker   // Get the size of a file (or -1 if it does not exist).
58*795d594fSAndroid Build Coastguard Worker   static int64_t GetFileSizeBytes(const char* name);
59*795d594fSAndroid Build Coastguard Worker };
60*795d594fSAndroid Build Coastguard Worker 
61*795d594fSAndroid Build Coastguard Worker }  // namespace art
62*795d594fSAndroid Build Coastguard Worker 
63*795d594fSAndroid Build Coastguard Worker #endif  // ART_LIBARTBASE_BASE_OS_H_
64