Blame posix/spawn_faction_addclose.c

Packit Service 82fcde
/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <errno.h>
Packit Service 82fcde
#include <spawn.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
Packit Service 82fcde
#include "spawn_int.h"
Packit Service 82fcde
Packit Service 82fcde
/* Add an action to FILE-ACTIONS which tells the implementation to call
Packit Service 82fcde
   `close' for the given file descriptor during the `spawn' call.  */
Packit Service 82fcde
int
Packit Service 82fcde
posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions,
Packit Service 82fcde
				   int fd)
Packit Service 82fcde
{
Packit Service 82fcde
  struct __spawn_action *rec;
Packit Service 82fcde
Packit Service 82fcde
  if (!__spawn_valid_fd (fd))
Packit Service 82fcde
    return EBADF;
Packit Service 82fcde
Packit Service 82fcde
  /* Allocate more memory if needed.  */
Packit Service 82fcde
  if (file_actions->__used == file_actions->__allocated
Packit Service 82fcde
      && __posix_spawn_file_actions_realloc (file_actions) != 0)
Packit Service 82fcde
    /* This can only mean we ran out of memory.  */
Packit Service 82fcde
    return ENOMEM;
Packit Service 82fcde
Packit Service 82fcde
  /* Add the new value.  */
Packit Service 82fcde
  rec = &file_actions->__actions[file_actions->__used];
Packit Service 82fcde
  rec->tag = spawn_do_close;
Packit Service 82fcde
  rec->action.open_action.fd = fd;
Packit Service 82fcde
Packit Service 82fcde
  /* Account for the new entry.  */
Packit Service 82fcde
  ++file_actions->__used;
Packit Service 82fcde
Packit Service 82fcde
  return 0;
Packit Service 82fcde
}