blob: 4de8863e4d208b498604119d095a972d86cae647 [file] [log] [blame]
Zonr Changd670be72012-04-05 15:09:28 +08001/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Stephen Hines2f6a4932012-05-03 12:27:13 -070017#ifndef BCC_EXECUTION_ENGINE_OUTPUT_FILE_H
18#define BCC_EXECUTION_ENGINE_OUTPUT_FILE_H
Zonr Changd670be72012-04-05 15:09:28 +080019
Stephen Hines2f6a4932012-05-03 12:27:13 -070020#include "File.h"
21#include "FileBase.h"
Zonr Changd670be72012-04-05 15:09:28 +080022
23namespace llvm {
24 class raw_fd_ostream;
25}
26
27namespace bcc {
28
29class OutputFile : public File<FileBase::kWriteMode> {
30 typedef File<FileBase::kWriteMode> super;
31public:
32 // Generate a unique temporary filename from pFileTemplate and open it in
33 // an OutputFile returned. The filename will be pFileTemplate with
34 // a dot ('.') plus six random characters appended. Return NULL on error.
35 static OutputFile *CreateTemporary(const std::string &pFileTemplate,
36 unsigned pFlags);
37
38 OutputFile(const std::string &pFilename, unsigned pFlags = 0);
39
40 ssize_t write(const void *pBuf, size_t count);
41
42 void truncate();
43
44 // This is similar to the system call dup(). It creates a copy of the file
45 // descriptor it contains and wrap it in llvm::raw_fd_ostream object. It
46 // returns a non-NULL object if everything goes well and user should later
47 // use delete operator to destroy it by itself.
48 llvm::raw_fd_ostream *dup();
49};
50
51} // end namespace bcc
52
Stephen Hines2f6a4932012-05-03 12:27:13 -070053#endif // BCC_EXECUTION_ENGINE_OUTPUT_FILE_H