set-host.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Set a host configuration item kept as the whole contents of a file.
  2. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <fcntl.h>
  16. #include <hurd.h>
  17. #include "hurdhost.h"
  18. ssize_t
  19. _hurd_set_host_config (const char *item, const char *value, size_t valuelen)
  20. {
  21. error_t err;
  22. vm_size_t nwrote;
  23. file_t new, dir;
  24. char *name;
  25. dir = __file_name_split (item, &name);
  26. if (dir == MACH_PORT_NULL)
  27. return -1;
  28. /* Create a new node. */
  29. err = __dir_mkfile (dir, O_WRONLY, 0644, &new);
  30. if (! err)
  31. {
  32. /* Write the contents. */
  33. err = __io_write (new, value, valuelen, 0, &nwrote);
  34. if (! err)
  35. /* Atomically link the new node onto the name. */
  36. err = __dir_link (dir, new, name, 0);
  37. __mach_port_deallocate (__mach_task_self (), new);
  38. }
  39. __mach_port_deallocate (__mach_task_self (), dir);
  40. return err ? __hurd_fail (err) : nwrote;
  41. }