TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / src / filesystem.c
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "internal/filesystem.h"
16
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21
22 #if defined(_MSC_VER)
23 #include <io.h>
24 int CpuFeatures_OpenFile(const char* filename) {
25   return _open(filename, _O_RDONLY);
26 }
27
28 void CpuFeatures_CloseFile(int file_descriptor) { _close(file_descriptor); }
29
30 int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
31                          size_t buffer_size) {
32   return _read(file_descriptor, buffer, buffer_size);
33 }
34
35 #else
36 #include <unistd.h>
37
38 int CpuFeatures_OpenFile(const char* filename) {
39   int result;
40   do {
41     result = open(filename, O_RDONLY);
42   } while (result == -1L && errno == EINTR);
43   return result;
44 }
45
46 void CpuFeatures_CloseFile(int file_descriptor) { close(file_descriptor); }
47
48 int CpuFeatures_ReadFile(int file_descriptor, void* buffer,
49                          size_t buffer_size) {
50   int result;
51   do {
52     result = read(file_descriptor, buffer, buffer_size);
53   } while (result == -1L && errno == EINTR);
54   return result;
55 }
56
57 #endif