// Copyright (c) 2011 The LevelDB Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. // // An Env is an interface used by the leveldb implementation to access // operating system functionality like the filesystem etc. Callers // may wish to provide a custom Env object when opening a database to // get fine gain control; e.g., to rate limit file system operations. // // All Env implementations are safe for concurrent access from // multiple threads without any external synchronization. #ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_ #define STORAGE_LEVELDB_INCLUDE_ENV_H_ #include <cstdarg> #include <cstdint> #include <string> #include <vector> #include "leveldb/export.h" #include "leveldb/status.h" // This workaround can be removed when leveldb::Env::DeleteFile is removed. #if defined(_WIN32) // On Windows, the method name DeleteFile (below) introduces the risk of // triggering undefined behavior by exposing the compiler to different // declarations of the Env class in different translation units. // // This is because <windows.h>, a fairly popular header file for Windows // applications, defines a DeleteFile macro. So, files that include the Windows // header before this header will contain an altered Env declaration. // // This workaround ensures that the compiler sees the same Env declaration, // independently of whether <windows.h> was included. #if defined(DeleteFile) #undef DeleteFile #define LEVELDB_DELETEFILE_UNDEFINED #endif // defined(DeleteFile) #endif // defined(_WIN32) namespace leveldb { class FileLock; class Logger; class RandomAccessFile; class SequentialFile; class Slice; class WritableFile; class LEVELDB_EXPORT Env { … }; // A file abstraction for reading sequentially through a file class LEVELDB_EXPORT SequentialFile { … }; // A file abstraction for randomly reading the contents of a file. class LEVELDB_EXPORT RandomAccessFile { … }; // A file abstraction for sequential writing. The implementation // must provide buffering since callers may append small fragments // at a time to the file. class LEVELDB_EXPORT WritableFile { … }; // An interface for writing log messages. class LEVELDB_EXPORT Logger { … }; // Identifies a locked file. class LEVELDB_EXPORT FileLock { … }; // Log the specified data to *info_log if info_log is non-null. void Log(Logger* info_log, const char* format, ...) #if defined(__GNUC__) || defined(__clang__) __attribute__((__format__(__printf__, 2, 3))) #endif ; // A utility routine: write "data" to the named file. LEVELDB_EXPORT Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname); // A utility routine: read contents of named file into *data LEVELDB_EXPORT Status ReadFileToString(Env* env, const std::string& fname, std::string* data); // An implementation of Env that forwards all calls to another Env. // May be useful to clients who wish to override just part of the // functionality of another Env. class LEVELDB_EXPORT EnvWrapper : public Env { … }; } // namespace leveldb // This workaround can be removed when leveldb::Env::DeleteFile is removed. // Redefine DeleteFile if it was undefined earlier. #if defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED) #if defined(UNICODE) #define DeleteFile … #else #define DeleteFile … #endif // defined(UNICODE) #endif // defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED) #endif // STORAGE_LEVELDB_INCLUDE_ENV_H_