D-Bus  1.12.20
dbus-file-win.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-file-win.c windows related file implementation (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
5  * Copyright (C) 2003 CodeFactory AB
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include <config.h>
26 #include "dbus-protocol.h"
27 #include "dbus-string.h"
28 #include "dbus-internals.h"
29 #include "dbus-sysdeps-win.h"
30 #include "dbus-pipe.h"
31 
32 #include <windows.h>
33 
34 
46 static int
47 _dbus_file_read (HANDLE hnd,
48  DBusString *buffer,
49  int count,
50  DBusError *error)
51 {
52  BOOL result;
53  DWORD bytes_read;
54  int start;
55  char *data;
56 
57  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
58 
59  _dbus_assert (count >= 0);
60 
61  start = _dbus_string_get_length (buffer);
62 
63  if (!_dbus_string_lengthen (buffer, count))
64  {
66  return -1;
67  }
68 
69  data = _dbus_string_get_data_len (buffer, start, count);
70 
71  result = ReadFile (hnd, data, count, &bytes_read, NULL);
72  if (result == 0)
73  {
74  char *emsg = _dbus_win_error_string (GetLastError ());
75  dbus_set_error (error, _dbus_win_error_from_last_error (),
76  "Failed to read from %p: %s", hnd, emsg);
77  _dbus_win_free_error_string (emsg);
78  return -1;
79  }
80 
81  <