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 //===----------------------------------------------------------------------===// 8 9 #include "posix_spawn_file_actions_destroy.h" 10 11 #include "file_actions.h" 12 #include "src/__support/CPP/new.h" 13 #include "src/__support/common.h" 14 15 #include <errno.h> 16 #include <spawn.h> 17 18 namespace LIBC_NAMESPACE { 19 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; 26 27 auto *act = reinterpret_cast<BaseSpawnFileAction *>(actions->__front); 28 actions->__front = nullptr; 29 actions->__back = nullptr; 30 if (act == nullptr) 31 return 0; 32 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; 46 } 47 } 48 49 return 0; 50 } 51 52 } // namespace LIBC_NAMESPACE 53