spawn_faction_init.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (C) 2000, 2009-2023 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. /* Specification. */
  15. #include <spawn.h>
  16. #include <errno.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "spawn_int.h"
  20. /* Function used to increase the size of the allocated array. This
  21. function is called from the 'add'-functions. */
  22. int
  23. __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
  24. {
  25. int newalloc = file_actions->_allocated + 8;
  26. void *newmem = realloc (file_actions->_actions,
  27. newalloc * sizeof (struct __spawn_action));
  28. if (newmem == NULL)
  29. /* Not enough memory. */
  30. return ENOMEM;
  31. file_actions->_actions = (struct __spawn_action *) newmem;
  32. file_actions->_allocated = newalloc;
  33. return 0;
  34. }
  35. /* Initialize data structure for file attribute for 'spawn' call. */
  36. int
  37. posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions)
  38. {
  39. /* Simply clear all the elements. */
  40. memset (file_actions, '\0', sizeof (*file_actions));
  41. return 0;
  42. }