Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / spawn / posix_spawn_file_actions_destroy.cpp
blob73e0ac828cd6997a0d9a4892a0b27871fce39244
1 //===-- Implementation of posix_spawn_file_actions_destroy ----------------===//
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 //===----------------------------------------------------------------------===//
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"
15 #include <errno.h>
16 #include <spawn.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)
23 return EINVAL;
24 if (actions->__front == nullptr)
25 return 0;
27 auto *act = reinterpret_cast<BaseSpawnFileAction *>(actions->__front);
28 actions->__front = nullptr;
29 actions->__back = nullptr;
30 if (act == nullptr)
31 return 0;
33 while (act != nullptr) {
34 auto *temp = act;
35 act = act->next;
36 switch (temp->type) {
37 case BaseSpawnFileAction::OPEN:
38 delete reinterpret_cast<SpawnFileOpenAction *>(temp);
39 break;
40 case BaseSpawnFileAction::CLOSE:
41 delete reinterpret_cast<SpawnFileCloseAction *>(temp);
42 break;
43 case BaseSpawnFileAction::DUP2:
44 delete reinterpret_cast<SpawnFileDup2Action *>(temp);
45 break;
49 return 0;
52 } // namespace LIBC_NAMESPACE