D-Bus 1.6.12

dbus-pipe-win.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-pipe-win.c windows 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 
00031 #include <windows.h>
00032 #include <io.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   const char *buffer_c = _dbus_string_get_const_data (buffer);
00052   int written;
00053 
00054   written = _write (pipe->fd, buffer_c + start, len);
00055 
00056   if (written >= 0)
00057     return written;
00058 
00059   dbus_set_error (error, _dbus_error_from_system_errno (),
00060                   "Writing to pipe: %s",
00061                   _dbus_strerror_from_errno ());
00062   return -1;
00063 }
00064 
00072 int
00073 _dbus_pipe_close  (DBusPipe         *pipe,
00074                    DBusError        *error)
00075 {
00076   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
00077 
00078   if (_close (pipe->fd) != 0)
00079     {
00080       dbus_set_error (error, _dbus_error_from_system_errno (),
00081                       "Could not close pipe fd %d: %s", pipe->fd,
00082                       _dbus_strerror_from_errno ());
00083       return -1;
00084     }
00085   else
00086     {
00087       _dbus_pipe_invalidate (pipe);
00088       return 0;
00089     }
00090 }