1 //===-- Implementation of posix_spawn_file_actions_destroy ----------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "posix_spawn_file_actions_destroy.h"
11 #include "file_actions.h"
13 #include "src/__support/CPP/new.h"
14 #include "src/__support/common.h"
15 #include "src/__support/macros/config.h"
16 #include "src/errno/libc_errno.h"
20 namespace LIBC_NAMESPACE_DECL
{
22 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_destroy
,
23 (posix_spawn_file_actions_t
* actions
)) {
24 if (actions
== nullptr)
26 if (actions
->__front
== nullptr)
29 auto *act
= reinterpret_cast<BaseSpawnFileAction
*>(actions
->__front
);
30 actions
->__front
= nullptr;
31 actions
->__back
= nullptr;
35 while (act
!= nullptr) {
39 case BaseSpawnFileAction::OPEN
:
40 delete reinterpret_cast<SpawnFileOpenAction
*>(temp
);
42 case BaseSpawnFileAction::CLOSE
:
43 delete reinterpret_cast<SpawnFileCloseAction
*>(temp
);
45 case BaseSpawnFileAction::DUP2
:
46 delete reinterpret_cast<SpawnFileDup2Action
*>(temp
);
54 } // namespace LIBC_NAMESPACE_DECL