Back to index

glibc  2.9
set-host.c
Go to the documentation of this file.
00001 /* Set a host configuration item kept as the whole contents of a file.
00002    Copyright (C) 1996,97,99,2001 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <fcntl.h>
00021 #include <hurd.h>
00022 #include "hurdhost.h"
00023 
00024 ssize_t
00025 _hurd_set_host_config (const char *item, const char *value, size_t valuelen)
00026 {
00027   error_t err;
00028   mach_msg_type_number_t nwrote;
00029   file_t new, dir;
00030   char *name;
00031 
00032   dir = __file_name_split (item, &name);
00033   if (dir == MACH_PORT_NULL)
00034     return -1;
00035 
00036   /* Create a new node.  */
00037   err = __dir_mkfile (dir, O_WRONLY, 0644, &new);
00038   if (! err)
00039     {
00040       /* Write the contents.  */
00041       err = __io_write (new, value, valuelen, 0, &nwrote);
00042       if (! err)
00043        /* Atomically link the new node onto the name.  */
00044        err = __dir_link (dir, new, name, 0);
00045       __mach_port_deallocate (__mach_task_self (), new);
00046     }
00047   __mach_port_deallocate (__mach_task_self (), dir);
00048 
00049   return err ? __hurd_fail (err) : nwrote;
00050 }