Skip to content

Commit

Permalink
Deprecate SbFile types. (#4055)
Browse files Browse the repository at this point in the history
b/302715109
  • Loading branch information
yjzhang111 committed Aug 30, 2024
1 parent ea15d82 commit 2e6b9b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
4 changes: 2 additions & 2 deletions starboard/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
extern "C" {
#endif

#if SB_API_VERSION < 17

// Private structure representing an open file.
typedef struct SbFilePrivate SbFilePrivate;

Expand Down Expand Up @@ -127,8 +129,6 @@ static inline bool SbFileIsValid(SbFile file) {
return file != kSbFileInvalid;
}

#if SB_API_VERSION < 17

// DEPRECATED with SB_API_VERSION 16
//
// Opens the file at |path|, which must be absolute, creating it if specified by
Expand Down
7 changes: 5 additions & 2 deletions starboard/shared/win32/file_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "starboard/shared/win32/error_utils.h"
#include "starboard/shared/win32/wchar_utils.h"

#define O_ACCMODE O_RDWR | O_WRONLY | O_RDONLY
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)

namespace sbwin32 = starboard::shared::win32;

Expand Down Expand Up @@ -110,6 +110,10 @@ HANDLE OpenFileOrDirectory(const char* path, int flags) {
}

DWORD creation_disposition = 0;
if (!flags) {
creation_disposition = OPEN_EXISTING;
}

if (flags & O_CREAT && flags & O_EXCL) {
SB_DCHECK(!creation_disposition);
creation_disposition = CREATE_NEW;
Expand Down Expand Up @@ -144,7 +148,6 @@ HANDLE OpenFileOrDirectory(const char* path, int flags) {
SB_DCHECK(desired_access != 0) << "Invalid permission flag.";

std::wstring path_wstring = NormalizeWin32Path(path);

CREATEFILE2_EXTENDED_PARAMETERS create_ex_params = {0};
// Enabling |FILE_FLAG_BACKUP_SEMANTICS| allows us to figure out if the path
// is a directory.
Expand Down
23 changes: 0 additions & 23 deletions starboard/shared/win32/file_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,12 @@ inline bool IsValidHandle(HANDLE handle) {
// to generate a warning.
#pragma warning(disable : 4099)

class SbFilePrivate {
public:
explicit SbFilePrivate(HANDLE handle) : file_handle(handle) {}

bool HasValidHandle() const {
return starboard::shared::win32::IsValidHandle(file_handle);
}

HANDLE file_handle;

// SbFilePrivate is neither copyable nor movable.
SbFilePrivate(const SbFilePrivate&) = delete;
SbFilePrivate& operator=(const SbFilePrivate&) = delete;
};

#pragma warning(pop)

namespace starboard {
namespace shared {
namespace win32 {

inline bool HasValidHandle(SbFile file) {
if (!SbFileIsValid(file)) {
return false;
}

return file->HasValidHandle();
}

inline bool PathEndsWith(const std::wstring& path, const wchar_t* filename) {
size_t filename_length = std::wcslen(filename);
if (filename_length > path.size()) {
Expand Down

0 comments on commit 2e6b9b9

Please sign in to comment.