platform_file.h (1446B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #ifndef BASE_PLATFORM_FILE_H_ 8 #define BASE_PLATFORM_FILE_H_ 9 10 #if defined(XP_WIN) 11 # include <windows.h> 12 #endif 13 14 #include <string> 15 16 namespace base { 17 18 #if defined(XP_WIN) 19 typedef HANDLE PlatformFile; 20 const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE; 21 #else 22 typedef int PlatformFile; 23 const PlatformFile kInvalidPlatformFileValue = -1; 24 #endif 25 26 enum PlatformFileFlags { 27 PLATFORM_FILE_OPEN = 1, 28 PLATFORM_FILE_CREATE = 2, 29 PLATFORM_FILE_OPEN_ALWAYS = 4, // May create a new file. 30 PLATFORM_FILE_CREATE_ALWAYS = 8, // May overwrite an old file. 31 PLATFORM_FILE_READ = 16, 32 PLATFORM_FILE_WRITE = 32, 33 PLATFORM_FILE_EXCLUSIVE_READ = 64, // EXCLUSIVE is opposite of Windows SHARE 34 PLATFORM_FILE_EXCLUSIVE_WRITE = 128, 35 PLATFORM_FILE_ASYNC = 256 36 }; 37 38 // Creates or open the given file. If PLATFORM_FILE_OPEN_ALWAYS is used, and 39 // |created| is provided, |created| will be set to true if the file was created 40 // or to false in case the file was just opened. 41 PlatformFile CreatePlatformFile(const std::wstring& name, int flags, 42 bool* created); 43 44 } // namespace base 45 46 #endif // BASE_PLATFORM_FILE_H_