LLDB mainline
WindowsFileAction.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <fcntl.h>
10
11#include "lldb/Host/PosixApi.h"
14
15using namespace lldb_private;
16
18 Clear();
19 if (fh != INVALID_HANDLE_VALUE && dup_fh != INVALID_HANDLE_VALUE) {
21 m_handle = fh;
22 m_arg_handle = dup_fh;
23 return true;
24 }
25 return false;
26}
27
28bool WindowsFileAction::Open(HANDLE fh, const FileSpec &file_spec, bool read,
29 bool write) {
30 if ((read || write) && fh != INVALID_HANDLE_VALUE && file_spec) {
32 m_handle = fh;
33 if (read && write)
34 m_arg = O_NOCTTY | O_CREAT | O_RDWR;
35 else if (read)
36 m_arg = O_NOCTTY | O_RDONLY;
37 else
38 m_arg = O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC;
39 m_file_spec = file_spec;
40 return true;
41 } else {
42 Clear();
43 }
44 return false;
45}
46
48 if (m_handle != INVALID_HANDLE_VALUE)
49 return m_handle;
50 switch (m_fd) {
51 case STDIN_FILENO:
52 return GetStdHandle(STD_INPUT_HANDLE);
53 case STDOUT_FILENO:
54 return GetStdHandle(STD_OUTPUT_HANDLE);
55 case STDERR_FILENO:
56 return GetStdHandle(STD_ERROR_HANDLE);
57 default:
58 return INVALID_HANDLE_VALUE;
59 }
60}
61
void * HANDLE
Action m_action
The action for this file.
Definition FileAction.h:77
int m_fd
The file descriptor this action applies to.
Definition FileAction.h:79
int m_arg
oflag for eFileActionOpen, dup_fd for eFileActionDuplicate.
Definition FileAction.h:81
FileSpec m_file_spec
File spec to use for opening after fork or posix_spawn.
Definition FileAction.h:83
A file utility class.
Definition FileSpec.h:57
HANDLE GetHandle() const
Get the Windows HANDLE for this action's file.
HANDLE GetActionArgumentHandle() const
Get the Windows HANDLE argument for eFileActionDuplicate actions.
bool Open(HANDLE fh, const FileSpec &file_spec, bool read, bool write)
Configure this action to associate a Windows file handle with a file.
void Clear()
Reset this WindowsFileAction to its default state.
bool Duplicate(HANDLE fh, HANDLE dup_fh)
Configure this action to duplicate a Windows file handle.
A class that represents a running process on the host machine.
#define O_NOCTTY