D-Bus 1.4.10
dbus-pipe-unix.c
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-pipe-unix.c unix related pipe implementation
00003  * 
00004  * Copyright (C) 2002, 2003, 2006  Red Hat, Inc.
00005  * Copyright (C) 2003 CodeFactory AB
00006  *
00007  * Licensed under the Academic Free License version 2.1
00008  * 
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  */
00024 
00025 #include <config.h>
00026 #include "dbus-protocol.h"
00027 #include "dbus-string.h"
00028 #include "dbus-internals.h"
00029 #include "dbus-pipe.h"
00030 #include "dbus-sysdeps-unix.h"
00031 
00032 #include <errno.h>
00033 
00044 int
00045 _dbus_pipe_write (DBusPipe         *pipe,
00046                   const DBusString *buffer,
00047                   int               start,
00048                   int               len,
00049                   DBusError        *error)
00050 {
00051   int written;
00052   
00053   written = _dbus_write (pipe->fd_or_handle, buffer, start, len);
00054   if (written < 0)
00055     {
00056       dbus_set_error (error, DBUS_ERROR_FAILED,
00057                       "Writing to pipe: %s\n",
00058                       _dbus_strerror (errno));
00059     }
00060   return written;
00061 }
00062 
00070 int
00071 _dbus_pipe_close  (DBusPipe         *pipe,
00072                    DBusError        *error)
00073 {
00074   if (!_dbus_close (pipe->fd_or_handle, error))
00075     {
00076       return -1;
00077     }
00078   else
00079     {
00080       _dbus_pipe_invalidate (pipe);
00081       return 0;
00082     }
00083 }