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"
12 #include "src/__support/CPP/new.h"
13 #include "src/__support/common.h"
18 namespace LIBC_NAMESPACE
{
20 LLVM_LIBC_FUNCTION(int, posix_spawn_file_actions_destroy
,
21 (posix_spawn_file_actions_t
* actions
)) {
22 if (actions
== nullptr)
24 if (actions
->__front
== nullptr)
27 auto *act
= reinterpret_cast<BaseSpawnFileAction
*>(actions
->__front
);
28 actions
->__front
= nullptr;
29 actions
->__back
= nullptr;
33 while (act
!= nullptr) {
37 case BaseSpawnFileAction::OPEN
:
38 delete reinterpret_cast<SpawnFileOpenAction
*>(temp
);
40 case BaseSpawnFileAction::CLOSE
:
41 delete reinterpret_cast<SpawnFileCloseAction
*>(temp
);
43 case BaseSpawnFileAction::DUP2
:
44 delete reinterpret_cast<SpawnFileDup2Action
*>(temp
);
52 } // namespace LIBC_NAMESPACE