blob: 5aeb5fd1ed003a332efead15c50766c7e6f437c3 [file] [log] [blame]
Andrew Top193dc3d2019-01-23 09:57:23 -08001// Copyright 2017 The Cobalt Authors. All Rights Reserved.
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 "starboard/file.h"
16
17#include <android/asset_manager.h>
18
19#include "starboard/directory.h"
20
21#include "starboard/android/shared/file_internal.h"
22#include "starboard/shared/posix/impl/file_can_open.h"
23
24using starboard::android::shared::IsAndroidAssetPath;
25using starboard::android::shared::OpenAndroidAsset;
26
27bool SbFileCanOpen(const char* path, int flags) {
28 if (!IsAndroidAssetPath(path)) {
29 return ::starboard::shared::posix::impl::FileCanOpen(path, flags);
30 }
31
32 SbFile file = SbFileOpen(path, flags | kSbFileOpenOnly, NULL, NULL);
33 bool result = SbFileIsValid(file);
34 SbFileClose(file);
35
36 if (!result) {
37 SbDirectory directory = SbDirectoryOpen(path, NULL);
38 result = SbDirectoryIsValid(directory);
39 SbDirectoryClose(directory);
40 }
41
42 return result;
43}