Current File : //usr/share/doc/dbus/api/dbus-sysdeps-win_8c_source.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>D-Bus: dbus-sysdeps-win.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">D-Bus
   &#160;<span id="projectnumber">1.8.20</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">dbus-sysdeps-win.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: &quot;gnu&quot;; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-sysdeps.c Wrappers around system/libc features (internal to D-BUS implementation)</span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003  Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2003 CodeFactory AB</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright (C) 2005 Novell, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> * Copyright (C) 2006 Peter Kümmel  &lt;syntheticpp@gmx.net&gt;</span>
<a name="l00008"></a>00008 <span class="comment"> * Copyright (C) 2006 Christian Ehrlicher &lt;ch.ehrlicher@gmx.de&gt;</span>
<a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2006-2013 Ralf Habacker &lt;ralf.habacker@freenet.de&gt;</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00012"></a>00012 <span class="comment"> * </span>
<a name="l00013"></a>00013 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00014"></a>00014 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00015"></a>00015 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00016"></a>00016 <span class="comment"> * (at your option) any later version.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00019"></a>00019 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00020"></a>00020 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00021"></a>00021 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00022"></a>00022 <span class="comment"> * </span>
<a name="l00023"></a>00023 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00024"></a>00024 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00025"></a>00025 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> */</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#define STRSAFE_NO_DEPRECATE</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="preprocessor">#ifndef DBUS_WINCE</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#ifndef _WIN32_WINNT</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor">#define _WIN32_WINNT 0x0501</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;dbus-internals.h&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;dbus-sha.h&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;dbus-sysdeps.h&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;dbus-threads.h&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;dbus-protocol.h&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;dbus-string.h&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;dbus-sysdeps.h&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;dbus-sysdeps-win.h&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &quot;dbus-protocol.h&quot;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include &quot;dbus-hash.h&quot;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &quot;dbus-sockets-win.h&quot;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &quot;dbus-list.h&quot;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &quot;dbus-nonce.h&quot;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &quot;dbus-credentials.h&quot;</span>
<a name="l00053"></a>00053 
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;windows.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;ws2tcpip.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;wincrypt.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;iphlpapi.h&gt;</span>
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <span class="comment">/* Declarations missing in mingw&#39;s and windows sdk 7.0 headers */</span>
<a name="l00060"></a>00060 <span class="keyword">extern</span> BOOL WINAPI ConvertStringSidToSidA (LPCSTR  StringSid, PSID *Sid);
<a name="l00061"></a>00061 <span class="keyword">extern</span> BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid);
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00064"></a>00064 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00065"></a>00065 
<a name="l00066"></a>00066 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00067"></a>00067 <span class="preprocessor">#if HAVE_ERRNO_H</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00069"></a>00069 <span class="preprocessor">#endif</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#ifndef DBUS_WINCE</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#include &lt;mbstring.h&gt;</span>
<a name="l00072"></a>00072 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00073"></a>00073 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00074"></a>00074 <span class="preprocessor">#endif</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span>
<a name="l00076"></a>00076 <span class="preprocessor">#ifdef HAVE_WS2TCPIP_H</span>
<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="comment">/* getaddrinfo for Windows CE (and Windows).  */</span>
<a name="l00078"></a>00078 <span class="preprocessor">#include &lt;ws2tcpip.h&gt;</span>
<a name="l00079"></a>00079 <span class="preprocessor">#endif</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span>
<a name="l00081"></a>00081 <span class="preprocessor">#ifndef O_BINARY</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define O_BINARY 0</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00084"></a>00084 <span class="preprocessor"></span>
<a name="l00085"></a>00085 <span class="preprocessor">#ifndef PROCESS_QUERY_LIMITED_INFORMATION</span>
<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="comment">/* MinGW32 &lt; 4 does not define this value in its headers */</span>
<a name="l00087"></a>00087 <span class="preprocessor">#define PROCESS_QUERY_LIMITED_INFORMATION (0x1000)</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>
<a name="l00090"></a>00090 <span class="keyword">typedef</span> <span class="keywordtype">int</span> socklen_t;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092 
<a name="l00093"></a>00093 <span class="keywordtype">void</span>
<a name="l00094"></a>00094 _dbus_win_set_errno (<span class="keywordtype">int</span> err)
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096 <span class="preprocessor">#ifdef DBUS_WINCE</span>
<a name="l00097"></a>00097 <span class="preprocessor"></span>  SetLastError (err);
<a name="l00098"></a>00098 <span class="preprocessor">#else</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span>  errno = err;
<a name="l00100"></a>00100 <span class="preprocessor">#endif</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span>}
<a name="l00102"></a>00102 
<a name="l00103"></a>00103 <span class="keyword">static</span> BOOL is_winxp_sp3_or_lower();
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 <span class="comment">/*</span>
<a name="l00106"></a>00106 <span class="comment"> * _MIB_TCPROW_EX and friends are not available in system headers</span>
<a name="l00107"></a>00107 <span class="comment"> *  and are mapped to attribute identical ...OWNER_PID typedefs.</span>
<a name="l00108"></a>00108 <span class="comment"> */</span>
<a name="l00109"></a>00109 <span class="keyword">typedef</span> MIB_TCPROW_OWNER_PID _MIB_TCPROW_EX;
<a name="l00110"></a>00110 <span class="keyword">typedef</span> MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_EX;
<a name="l00111"></a>00111 <span class="keyword">typedef</span> PMIB_TCPTABLE_OWNER_PID PMIB_TCPTABLE_EX;
<a name="l00112"></a>00112 <span class="keyword">typedef</span> DWORD (WINAPI *ProcAllocateAndGetTcpExtTableFromStack)(PMIB_TCPTABLE_EX*,BOOL,HANDLE,DWORD,DWORD);
<a name="l00113"></a>00113 <span class="keyword">static</span> ProcAllocateAndGetTcpExtTableFromStack lpfnAllocateAndGetTcpExTableFromStack = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00114"></a>00114 
<a name="l00120"></a>00120 <span class="keyword">static</span> BOOL
<a name="l00121"></a>00121 load_ex_ip_helper_procedures(<span class="keywordtype">void</span>)
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123   HMODULE hModule = LoadLibrary (<span class="stringliteral">&quot;iphlpapi.dll&quot;</span>);
<a name="l00124"></a>00124   <span class="keywordflow">if</span> (hModule == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00125"></a>00125     {
<a name="l00126"></a>00126       _dbus_verbose (<span class="stringliteral">&quot;could not load iphlpapi.dll\n&quot;</span>);
<a name="l00127"></a>00127       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00128"></a>00128     }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130   lpfnAllocateAndGetTcpExTableFromStack = (ProcAllocateAndGetTcpExtTableFromStack)GetProcAddress (hModule, <span class="stringliteral">&quot;AllocateAndGetTcpExTableFromStack&quot;</span>);
<a name="l00131"></a>00131   <span class="keywordflow">if</span> (lpfnAllocateAndGetTcpExTableFromStack == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00132"></a>00132     {
<a name="l00133"></a>00133       _dbus_verbose (<span class="stringliteral">&quot;could not find function AllocateAndGetTcpExTableFromStack in iphlpapi.dll\n&quot;</span>);
<a name="l00134"></a>00134       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00135"></a>00135     }
<a name="l00136"></a>00136   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 
<a name="l00145"></a>00145 <span class="keyword">static</span> <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>
<a name="l00146"></a>00146 get_pid_from_extended_tcp_table(<span class="keywordtype">int</span> peer_port)
<a name="l00147"></a>00147 {
<a name="l00148"></a>00148   <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> result;
<a name="l00149"></a>00149   DWORD errorCode, size = 0, i;
<a name="l00150"></a>00150   MIB_TCPTABLE_OWNER_PID *tcp_table;
<a name="l00151"></a>00151 
<a name="l00152"></a>00152   <span class="keywordflow">if</span> ((errorCode =
<a name="l00153"></a>00153        GetExtendedTcpTable (<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, &amp;size, <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) == ERROR_INSUFFICIENT_BUFFER)
<a name="l00154"></a>00154     {
<a name="l00155"></a>00155       tcp_table = (MIB_TCPTABLE_OWNER_PID *) <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (size);
<a name="l00156"></a>00156       <span class="keywordflow">if</span> (tcp_table == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00157"></a>00157         {
<a name="l00158"></a>00158           _dbus_verbose (<span class="stringliteral">&quot;Error allocating memory\n&quot;</span>);
<a name="l00159"></a>00159           <span class="keywordflow">return</span> 0;
<a name="l00160"></a>00160         }
<a name="l00161"></a>00161     }
<a name="l00162"></a>00162   <span class="keywordflow">else</span>
<a name="l00163"></a>00163     {
<a name="l00164"></a>00164       _dbus_win_warn_win_error (<span class="stringliteral">&quot;unexpected error returned from GetExtendedTcpTable&quot;</span>, errorCode);
<a name="l00165"></a>00165       <span class="keywordflow">return</span> 0;
<a name="l00166"></a>00166     }
<a name="l00167"></a>00167 
<a name="l00168"></a>00168   <span class="keywordflow">if</span> ((errorCode = GetExtendedTcpTable (tcp_table, &amp;size, <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) != NO_ERROR)
<a name="l00169"></a>00169     {
<a name="l00170"></a>00170       _dbus_verbose (<span class="stringliteral">&quot;Error fetching tcp table %d\n&quot;</span>, (<span class="keywordtype">int</span>)errorCode);
<a name="l00171"></a>00171       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (tcp_table);
<a name="l00172"></a>00172       <span class="keywordflow">return</span> 0;
<a name="l00173"></a>00173     }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175   result = 0;
<a name="l00176"></a>00176   <span class="keywordflow">for</span> (i = 0; i &lt; tcp_table-&gt;dwNumEntries; i++)
<a name="l00177"></a>00177     {
<a name="l00178"></a>00178       MIB_TCPROW_OWNER_PID *p = &amp;tcp_table-&gt;table[i];
<a name="l00179"></a>00179       <span class="keywordtype">int</span> local_address = ntohl (p-&gt;dwLocalAddr);
<a name="l00180"></a>00180       <span class="keywordtype">int</span> local_port = ntohs (p-&gt;dwLocalPort);
<a name="l00181"></a>00181       <span class="keywordflow">if</span> (p-&gt;dwState == MIB_TCP_STATE_ESTAB
<a name="l00182"></a>00182           &amp;&amp; local_address == INADDR_LOOPBACK &amp;&amp; local_port == peer_port)
<a name="l00183"></a>00183          result = p-&gt;dwOwningPid;
<a name="l00184"></a>00184     }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (tcp_table);
<a name="l00187"></a>00187   _dbus_verbose (<span class="stringliteral">&quot;got pid %lu\n&quot;</span>, result);
<a name="l00188"></a>00188   <span class="keywordflow">return</span> result;
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190 
<a name="l00198"></a>00198 <span class="keyword">static</span> <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>
<a name="l00199"></a>00199 get_pid_from_tcp_ex_table(<span class="keywordtype">int</span> peer_port)
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201   <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> result;
<a name="l00202"></a>00202   DWORD errorCode, i;
<a name="l00203"></a>00203   PMIB_TCPTABLE_EX tcp_table = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00204"></a>00204 
<a name="l00205"></a>00205   <span class="keywordflow">if</span> (!load_ex_ip_helper_procedures ())
<a name="l00206"></a>00206     {
<a name="l00207"></a>00207       _dbus_verbose
<a name="l00208"></a>00208         (<span class="stringliteral">&quot;Error not been able to load iphelper procedures\n&quot;</span>);
<a name="l00209"></a>00209       <span class="keywordflow">return</span> 0;
<a name="l00210"></a>00210     }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212   errorCode = lpfnAllocateAndGetTcpExTableFromStack (&amp;tcp_table, <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>, GetProcessHeap(), 0, 2);
<a name="l00213"></a>00213 
<a name="l00214"></a>00214   <span class="keywordflow">if</span> (errorCode != NO_ERROR)
<a name="l00215"></a>00215     {
<a name="l00216"></a>00216       _dbus_verbose
<a name="l00217"></a>00217         (<span class="stringliteral">&quot;Error not been able to call AllocateAndGetTcpExTableFromStack()\n&quot;</span>);
<a name="l00218"></a>00218       <span class="keywordflow">return</span> 0;
<a name="l00219"></a>00219     }
<a name="l00220"></a>00220 
<a name="l00221"></a>00221   result = 0;
<a name="l00222"></a>00222   <span class="keywordflow">for</span> (i = 0; i &lt; tcp_table-&gt;dwNumEntries; i++)
<a name="l00223"></a>00223     {
<a name="l00224"></a>00224       _MIB_TCPROW_EX *p = &amp;tcp_table-&gt;table[i];
<a name="l00225"></a>00225       <span class="keywordtype">int</span> local_port = ntohs (p-&gt;dwLocalPort);
<a name="l00226"></a>00226       <span class="keywordtype">int</span> local_address = ntohl (p-&gt;dwLocalAddr);
<a name="l00227"></a>00227       <span class="keywordflow">if</span> (local_address == INADDR_LOOPBACK &amp;&amp; local_port == peer_port)
<a name="l00228"></a>00228         {
<a name="l00229"></a>00229           result = p-&gt;dwOwningPid;
<a name="l00230"></a>00230           <span class="keywordflow">break</span>;
<a name="l00231"></a>00231         }
<a name="l00232"></a>00232     }
<a name="l00233"></a>00233 
<a name="l00234"></a>00234   HeapFree (GetProcessHeap(), 0, tcp_table);
<a name="l00235"></a>00235   _dbus_verbose (<span class="stringliteral">&quot;got pid %lu\n&quot;</span>, result);
<a name="l00236"></a>00236   <span class="keywordflow">return</span> result;
<a name="l00237"></a>00237 }
<a name="l00238"></a>00238 
<a name="l00244"></a>00244 <span class="keyword">static</span> <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>
<a name="l00245"></a>00245 _dbus_get_peer_pid_from_tcp_handle (<span class="keywordtype">int</span> handle)
<a name="l00246"></a>00246 {
<a name="l00247"></a>00247   <span class="keyword">struct </span>sockaddr_storage addr;
<a name="l00248"></a>00248   socklen_t len = <span class="keyword">sizeof</span> (addr);
<a name="l00249"></a>00249   <span class="keywordtype">int</span> peer_port;
<a name="l00250"></a>00250 
<a name="l00251"></a>00251   <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> result;
<a name="l00252"></a>00252   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> is_localhost = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00253"></a>00253 
<a name="l00254"></a>00254   getpeername (handle, (<span class="keyword">struct</span> sockaddr *) &amp;addr, &amp;len);
<a name="l00255"></a>00255 
<a name="l00256"></a>00256   <span class="keywordflow">if</span> (addr.ss_family == AF_INET)
<a name="l00257"></a>00257     {
<a name="l00258"></a>00258       <span class="keyword">struct </span>sockaddr_in *s = (<span class="keyword">struct </span>sockaddr_in *) &amp;addr;
<a name="l00259"></a>00259       peer_port = ntohs (s-&gt;sin_port);
<a name="l00260"></a>00260       is_localhost = (ntohl (s-&gt;sin_addr.s_addr) == INADDR_LOOPBACK);
<a name="l00261"></a>00261     }
<a name="l00262"></a>00262   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (addr.ss_family == AF_INET6)
<a name="l00263"></a>00263     {
<a name="l00264"></a>00264       _dbus_verbose (<span class="stringliteral">&quot;FIXME [61922]: IPV6 support not working on windows\n&quot;</span>);
<a name="l00265"></a>00265       <span class="keywordflow">return</span> 0;
<a name="l00266"></a>00266       <span class="comment">/*</span>
<a name="l00267"></a>00267 <span class="comment">         struct sockaddr_in6 *s = (struct sockaddr_in6 * )&amp;addr;</span>
<a name="l00268"></a>00268 <span class="comment">         peer_port = ntohs (s-&gt;sin6_port);</span>
<a name="l00269"></a>00269 <span class="comment">         is_localhost = (memcmp(s-&gt;sin6_addr.s6_addr, in6addr_loopback.s6_addr, 16) == 0);</span>
<a name="l00270"></a>00270 <span class="comment">         _dbus_verbose (&quot;IPV6 %08x %08x\n&quot;, s-&gt;sin6_addr.s6_addr, in6addr_loopback.s6_addr);</span>
<a name="l00271"></a>00271 <span class="comment">       */</span>
<a name="l00272"></a>00272     }
<a name="l00273"></a>00273   <span class="keywordflow">else</span>
<a name="l00274"></a>00274     {
<a name="l00275"></a>00275       _dbus_verbose (<span class="stringliteral">&quot;no idea what address family %d is\n&quot;</span>, addr.ss_family);
<a name="l00276"></a>00276       <span class="keywordflow">return</span> 0;
<a name="l00277"></a>00277     }
<a name="l00278"></a>00278 
<a name="l00279"></a>00279   <span class="keywordflow">if</span> (!is_localhost)
<a name="l00280"></a>00280     {
<a name="l00281"></a>00281       _dbus_verbose (<span class="stringliteral">&quot;could not fetch process id from remote process\n&quot;</span>);
<a name="l00282"></a>00282       <span class="keywordflow">return</span> 0;
<a name="l00283"></a>00283     }
<a name="l00284"></a>00284 
<a name="l00285"></a>00285   <span class="keywordflow">if</span> (peer_port == 0)
<a name="l00286"></a>00286     {
<a name="l00287"></a>00287       _dbus_verbose
<a name="l00288"></a>00288         (<span class="stringliteral">&quot;Error not been able to fetch tcp peer port from connection\n&quot;</span>);
<a name="l00289"></a>00289       <span class="keywordflow">return</span> 0;
<a name="l00290"></a>00290     }
<a name="l00291"></a>00291 
<a name="l00292"></a>00292   _dbus_verbose (<span class="stringliteral">&quot;trying to get peers pid&quot;</span>);
<a name="l00293"></a>00293 
<a name="l00294"></a>00294   result = get_pid_from_extended_tcp_table (peer_port);
<a name="l00295"></a>00295   <span class="keywordflow">if</span> (result &gt; 0)
<a name="l00296"></a>00296       <span class="keywordflow">return</span> result;
<a name="l00297"></a>00297   result = get_pid_from_tcp_ex_table (peer_port);
<a name="l00298"></a>00298   <span class="keywordflow">return</span> result;
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300 
<a name="l00301"></a>00301 <span class="comment">/* Convert GetLastError() to a dbus error.  */</span>
<a name="l00302"></a>00302 <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l00303"></a>00303 _dbus_win_error_from_last_error (<span class="keywordtype">void</span>)
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305   <span class="keywordflow">switch</span> (GetLastError())
<a name="l00306"></a>00306     {
<a name="l00307"></a>00307     <span class="keywordflow">case</span> 0:
<a name="l00308"></a>00308       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>;
<a name="l00309"></a>00309     
<a name="l00310"></a>00310     <span class="keywordflow">case</span> ERROR_NO_MORE_FILES:
<a name="l00311"></a>00311     <span class="keywordflow">case</span> ERROR_TOO_MANY_OPEN_FILES:
<a name="l00312"></a>00312       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#ga7c96d165c4ebee51e939969934d18027" title="Some limited resource is exhausted.">DBUS_ERROR_LIMITS_EXCEEDED</a>; <span class="comment">/* kernel out of memory */</span>
<a name="l00313"></a>00313 
<a name="l00314"></a>00314     <span class="keywordflow">case</span> ERROR_ACCESS_DENIED:
<a name="l00315"></a>00315     <span class="keywordflow">case</span> ERROR_CANNOT_MAKE:
<a name="l00316"></a>00316       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#ga6d3940075c1fbd1bfe06626b59723a16" title="Security restrictions don&#39;t allow doing what you&#39;re trying to do.">DBUS_ERROR_ACCESS_DENIED</a>;
<a name="l00317"></a>00317 
<a name="l00318"></a>00318     <span class="keywordflow">case</span> ERROR_NOT_ENOUGH_MEMORY:
<a name="l00319"></a>00319       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>;
<a name="l00320"></a>00320 
<a name="l00321"></a>00321     <span class="keywordflow">case</span> ERROR_FILE_EXISTS:
<a name="l00322"></a>00322       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#ga7c65e9730331eb19b7d6b128a79361ef" title="Existing file and the operation you&#39;re using does not silently overwrite.">DBUS_ERROR_FILE_EXISTS</a>;
<a name="l00323"></a>00323 
<a name="l00324"></a>00324     <span class="keywordflow">case</span> ERROR_FILE_NOT_FOUND:
<a name="l00325"></a>00325     <span class="keywordflow">case</span> ERROR_PATH_NOT_FOUND:
<a name="l00326"></a>00326       <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#gaf5ad9572cc5935d4655635003073c21a" title="Missing file.">DBUS_ERROR_FILE_NOT_FOUND</a>;
<a name="l00327"></a>00327     }
<a name="l00328"></a>00328   
<a name="l00329"></a>00329   <span class="keywordflow">return</span> <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>;
<a name="l00330"></a>00330 }
<a name="l00331"></a>00331 
<a name="l00332"></a>00332 
<a name="l00333"></a>00333 <span class="keywordtype">char</span>*
<a name="l00334"></a>00334 _dbus_win_error_string (<span class="keywordtype">int</span> error_number)
<a name="l00335"></a>00335 {
<a name="l00336"></a>00336   <span class="keywordtype">char</span> *msg;
<a name="l00337"></a>00337 
<a name="l00338"></a>00338   FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
<a name="l00339"></a>00339                   FORMAT_MESSAGE_IGNORE_INSERTS |
<a name="l00340"></a>00340                   FORMAT_MESSAGE_FROM_SYSTEM,
<a name="l00341"></a>00341                   <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error_number, 0,
<a name="l00342"></a>00342                   (LPSTR) &amp;msg, 0, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00343"></a>00343 
<a name="l00344"></a>00344   <span class="keywordflow">if</span> (msg[strlen (msg) - 1] == <span class="charliteral">&#39;\n&#39;</span>)
<a name="l00345"></a>00345     msg[strlen (msg) - 1] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00346"></a>00346   <span class="keywordflow">if</span> (msg[strlen (msg) - 1] == <span class="charliteral">&#39;\r&#39;</span>)
<a name="l00347"></a>00347     msg[strlen (msg) - 1] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00348"></a>00348 
<a name="l00349"></a>00349   <span class="keywordflow">return</span> msg;
<a name="l00350"></a>00350 }
<a name="l00351"></a>00351 
<a name="l00352"></a>00352 <span class="keywordtype">void</span>
<a name="l00353"></a>00353 _dbus_win_free_error_string (<span class="keywordtype">char</span> *<span class="keywordtype">string</span>)
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355   LocalFree (<span class="keywordtype">string</span>);
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 
<a name="l00378"></a>00378 <span class="keywordtype">int</span>
<a name="l00379"></a><a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530">00379</a> <a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530" title="Like _dbus_read(), but only works on sockets so is available on Windows.">_dbus_read_socket</a> (<span class="keywordtype">int</span>               fd,
<a name="l00380"></a>00380                    <a class="code" href="structDBusString.html">DBusString</a>       *buffer,
<a name="l00381"></a>00381                    <span class="keywordtype">int</span>               count)
<a name="l00382"></a>00382 {
<a name="l00383"></a>00383   <span class="keywordtype">int</span> bytes_read;
<a name="l00384"></a>00384   <span class="keywordtype">int</span> start;
<a name="l00385"></a>00385   <span class="keywordtype">char</span> *data;
<a name="l00386"></a>00386 
<a name="l00387"></a>00387   _dbus_assert (count &gt;= 0);
<a name="l00388"></a>00388 
<a name="l00389"></a>00389   start = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (buffer);
<a name="l00390"></a>00390 
<a name="l00391"></a>00391   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga8f13997d90ceed2f437706e6b7804d9b" title="Makes a string longer by the given number of bytes.">_dbus_string_lengthen</a> (buffer, count))
<a name="l00392"></a>00392     {
<a name="l00393"></a>00393       _dbus_win_set_errno (ENOMEM);
<a name="l00394"></a>00394       <span class="keywordflow">return</span> -1;
<a name="l00395"></a>00395     }
<a name="l00396"></a>00396 
<a name="l00397"></a>00397   data = <a class="code" href="group__DBusString.html#ga7a73fb373398606e6e1d0a86c4587a3c" title="Gets a sub-portion of the raw character buffer from the string.">_dbus_string_get_data_len</a> (buffer, start, count);
<a name="l00398"></a>00398 
<a name="l00399"></a>00399  again:
<a name="l00400"></a>00400  
<a name="l00401"></a>00401   _dbus_verbose (<span class="stringliteral">&quot;recv: count=%d fd=%d\n&quot;</span>, count, fd);
<a name="l00402"></a>00402   bytes_read = recv (fd, data, count, 0);
<a name="l00403"></a>00403   
<a name="l00404"></a>00404   <span class="keywordflow">if</span> (bytes_read == SOCKET_ERROR)
<a name="l00405"></a>00405         {
<a name="l00406"></a>00406           DBUS_SOCKET_SET_ERRNO();
<a name="l00407"></a>00407           _dbus_verbose (<span class="stringliteral">&quot;recv: failed: %s (%d)\n&quot;</span>, _dbus_strerror (errno), errno);
<a name="l00408"></a>00408           bytes_read = -1;
<a name="l00409"></a>00409         }
<a name="l00410"></a>00410         <span class="keywordflow">else</span>
<a name="l00411"></a>00411           _dbus_verbose (<span class="stringliteral">&quot;recv: = %d\n&quot;</span>, bytes_read);
<a name="l00412"></a>00412 
<a name="l00413"></a>00413   <span class="keywordflow">if</span> (bytes_read &lt; 0)
<a name="l00414"></a>00414     {
<a name="l00415"></a>00415       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l00416"></a>00416         <span class="keywordflow">goto</span> again;
<a name="l00417"></a>00417       <span class="keywordflow">else</span>      
<a name="l00418"></a>00418         {
<a name="l00419"></a>00419           <span class="comment">/* put length back (note that this doesn&#39;t actually realloc anything) */</span>
<a name="l00420"></a>00420           <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start);
<a name="l00421"></a>00421           <span class="keywordflow">return</span> -1;
<a name="l00422"></a>00422         }
<a name="l00423"></a>00423     }
<a name="l00424"></a>00424   <span class="keywordflow">else</span>
<a name="l00425"></a>00425     {
<a name="l00426"></a>00426       <span class="comment">/* put length back (doesn&#39;t actually realloc) */</span>
<a name="l00427"></a>00427       <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start + bytes_read);
<a name="l00428"></a>00428 
<a name="l00429"></a>00429 <span class="preprocessor">#if 0</span>
<a name="l00430"></a>00430 <span class="preprocessor"></span>      <span class="keywordflow">if</span> (bytes_read &gt; 0)
<a name="l00431"></a>00431         <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_read);
<a name="l00432"></a>00432 <span class="preprocessor">#endif</span>
<a name="l00433"></a>00433 <span class="preprocessor"></span>
<a name="l00434"></a>00434       <span class="keywordflow">return</span> bytes_read;
<a name="l00435"></a>00435     }
<a name="l00436"></a>00436 }
<a name="l00437"></a>00437 
<a name="l00448"></a>00448 <span class="keywordtype">int</span>
<a name="l00449"></a><a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de">00449</a> <a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de" title="Like _dbus_write(), but only supports sockets and is thus available on Windows.">_dbus_write_socket</a> (<span class="keywordtype">int</span>               fd,
<a name="l00450"></a>00450                     <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer,
<a name="l00451"></a>00451                     <span class="keywordtype">int</span>               start,
<a name="l00452"></a>00452                     <span class="keywordtype">int</span>               len)
<a name="l00453"></a>00453 {
<a name="l00454"></a>00454   <span class="keyword">const</span> <span class="keywordtype">char</span> *data;
<a name="l00455"></a>00455   <span class="keywordtype">int</span> bytes_written;
<a name="l00456"></a>00456 
<a name="l00457"></a>00457   data = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer, start, len);
<a name="l00458"></a>00458 
<a name="l00459"></a>00459  again:
<a name="l00460"></a>00460 
<a name="l00461"></a>00461   _dbus_verbose (<span class="stringliteral">&quot;send: len=%d fd=%d\n&quot;</span>, len, fd);
<a name="l00462"></a>00462   bytes_written = send (fd, data, len, 0);
<a name="l00463"></a>00463 
<a name="l00464"></a>00464   <span class="keywordflow">if</span> (bytes_written == SOCKET_ERROR)
<a name="l00465"></a>00465     {
<a name="l00466"></a>00466       DBUS_SOCKET_SET_ERRNO();
<a name="l00467"></a>00467       _dbus_verbose (<span class="stringliteral">&quot;send: failed: %s\n&quot;</span>, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l00468"></a>00468       bytes_written = -1;
<a name="l00469"></a>00469     }
<a name="l00470"></a>00470     <span class="keywordflow">else</span>
<a name="l00471"></a>00471       _dbus_verbose (<span class="stringliteral">&quot;send: = %d\n&quot;</span>, bytes_written);
<a name="l00472"></a>00472 
<a name="l00473"></a>00473   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00474"></a>00474     <span class="keywordflow">goto</span> again;
<a name="l00475"></a>00475     
<a name="l00476"></a>00476 <span class="preprocessor">#if 0</span>
<a name="l00477"></a>00477 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (bytes_written &gt; 0)
<a name="l00478"></a>00478     <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_written);
<a name="l00479"></a>00479 <span class="preprocessor">#endif</span>
<a name="l00480"></a>00480 <span class="preprocessor"></span>
<a name="l00481"></a>00481   <span class="keywordflow">return</span> bytes_written;
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483 
<a name="l00484"></a>00484 
<a name="l00492"></a>00492 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00493"></a><a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8">00493</a> <a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8" title="Closes a socket.">_dbus_close_socket</a> (<span class="keywordtype">int</span>        fd,
<a name="l00494"></a>00494                     <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l00495"></a>00495 {
<a name="l00496"></a>00496   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00497"></a>00497 
<a name="l00498"></a>00498  again:
<a name="l00499"></a>00499   <span class="keywordflow">if</span> (closesocket (fd) == SOCKET_ERROR)
<a name="l00500"></a>00500     {
<a name="l00501"></a>00501       DBUS_SOCKET_SET_ERRNO ();
<a name="l00502"></a>00502       
<a name="l00503"></a>00503       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l00504"></a>00504         <span class="keywordflow">goto</span> again;
<a name="l00505"></a>00505         
<a name="l00506"></a>00506       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00507"></a>00507                       <span class="stringliteral">&quot;Could not close socket: socket=%d, , %s&quot;</span>,
<a name="l00508"></a>00508                       fd, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l00509"></a>00509       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00510"></a>00510     }
<a name="l00511"></a>00511   _dbus_verbose (<span class="stringliteral">&quot;_dbus_close_socket: socket=%d, \n&quot;</span>, fd);
<a name="l00512"></a>00512 
<a name="l00513"></a>00513   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00514"></a>00514 }
<a name="l00515"></a>00515 
<a name="l00523"></a>00523 <span class="keywordtype">void</span>
<a name="l00524"></a><a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6">00524</a> <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (intptr_t handle)
<a name="l00525"></a>00525 {
<a name="l00526"></a>00526   <span class="keywordflow">if</span> ( !SetHandleInformation( (HANDLE) handle,
<a name="l00527"></a>00527                         HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE,
<a name="l00528"></a>00528                         0 <span class="comment">/*disable both flags*/</span> ) )
<a name="l00529"></a>00529     {
<a name="l00530"></a>00530       _dbus_win_warn_win_error (<span class="stringliteral">&quot;Disabling socket handle inheritance failed:&quot;</span>, GetLastError());
<a name="l00531"></a>00531     }
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 
<a name="l00541"></a>00541 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00542"></a>00542 _dbus_set_fd_nonblocking (<span class="keywordtype">int</span>             handle,
<a name="l00543"></a>00543                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l00544"></a>00544 {
<a name="l00545"></a>00545   u_long one = 1;
<a name="l00546"></a>00546 
<a name="l00547"></a>00547   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00548"></a>00548 
<a name="l00549"></a>00549   <span class="keywordflow">if</span> (ioctlsocket (handle, FIONBIO, &amp;one) == SOCKET_ERROR)
<a name="l00550"></a>00550     {
<a name="l00551"></a>00551       DBUS_SOCKET_SET_ERRNO ();
<a name="l00552"></a>00552       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00553"></a>00553                       <span class="stringliteral">&quot;Failed to set socket %d:%d to nonblocking: %s&quot;</span>, handle,
<a name="l00554"></a>00554                       <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l00555"></a>00555       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00556"></a>00556     }
<a name="l00557"></a>00557 
<a name="l00558"></a>00558   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00559"></a>00559 }
<a name="l00560"></a>00560 
<a name="l00561"></a>00561 
<a name="l00582"></a>00582 <span class="keywordtype">int</span>
<a name="l00583"></a><a class="code" href="group__DBusSysdeps.html#ga02da720105c2a2397b7c687c5ca81174">00583</a> <a class="code" href="group__DBusSysdeps.html#ga02da720105c2a2397b7c687c5ca81174" title="Like _dbus_write_two() but only works on sockets and is thus available on Windows.">_dbus_write_socket_two</a> (<span class="keywordtype">int</span>               fd,
<a name="l00584"></a>00584                         <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer1,
<a name="l00585"></a>00585                         <span class="keywordtype">int</span>               start1,
<a name="l00586"></a>00586                         <span class="keywordtype">int</span>               len1,
<a name="l00587"></a>00587                         <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer2,
<a name="l00588"></a>00588                         <span class="keywordtype">int</span>               start2,
<a name="l00589"></a>00589                         <span class="keywordtype">int</span>               len2)
<a name="l00590"></a>00590 {
<a name="l00591"></a>00591   WSABUF vectors[2];
<a name="l00592"></a>00592   <span class="keyword">const</span> <span class="keywordtype">char</span> *data1;
<a name="l00593"></a>00593   <span class="keyword">const</span> <span class="keywordtype">char</span> *data2;
<a name="l00594"></a>00594   <span class="keywordtype">int</span> rc;
<a name="l00595"></a>00595   DWORD bytes_written;
<a name="l00596"></a>00596 
<a name="l00597"></a>00597   _dbus_assert (buffer1 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00598"></a>00598   _dbus_assert (start1 &gt;= 0);
<a name="l00599"></a>00599   _dbus_assert (start2 &gt;= 0);
<a name="l00600"></a>00600   _dbus_assert (len1 &gt;= 0);
<a name="l00601"></a>00601   _dbus_assert (len2 &gt;= 0);
<a name="l00602"></a>00602 
<a name="l00603"></a>00603 
<a name="l00604"></a>00604   data1 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer1, start1, len1);
<a name="l00605"></a>00605 
<a name="l00606"></a>00606   <span class="keywordflow">if</span> (buffer2 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00607"></a>00607     data2 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer2, start2, len2);
<a name="l00608"></a>00608   <span class="keywordflow">else</span>
<a name="l00609"></a>00609     {
<a name="l00610"></a>00610       data2 = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00611"></a>00611       start2 = 0;
<a name="l00612"></a>00612       len2 = 0;
<a name="l00613"></a>00613     }
<a name="l00614"></a>00614 
<a name="l00615"></a>00615   vectors[0].buf = (<span class="keywordtype">char</span>*) data1;
<a name="l00616"></a>00616   vectors[0].len = len1;
<a name="l00617"></a>00617   vectors[1].buf = (<span class="keywordtype">char</span>*) data2;
<a name="l00618"></a>00618   vectors[1].len = len2;
<a name="l00619"></a>00619 
<a name="l00620"></a>00620  again:
<a name="l00621"></a>00621  
<a name="l00622"></a>00622   _dbus_verbose (<span class="stringliteral">&quot;WSASend: len1+2=%d+%d fd=%d\n&quot;</span>, len1, len2, fd);
<a name="l00623"></a>00623   rc = WSASend (fd, 
<a name="l00624"></a>00624                 vectors,
<a name="l00625"></a>00625                 data2 ? 2 : 1, 
<a name="l00626"></a>00626                 &amp;bytes_written,
<a name="l00627"></a>00627                 0, 
<a name="l00628"></a>00628                 <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 
<a name="l00629"></a>00629                 <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00630"></a>00630                 
<a name="l00631"></a>00631   <span class="keywordflow">if</span> (rc == SOCKET_ERROR)
<a name="l00632"></a>00632     {
<a name="l00633"></a>00633       DBUS_SOCKET_SET_ERRNO ();
<a name="l00634"></a>00634       _dbus_verbose (<span class="stringliteral">&quot;WSASend: failed: %s\n&quot;</span>, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l00635"></a>00635       bytes_written = -1;
<a name="l00636"></a>00636     }
<a name="l00637"></a>00637   <span class="keywordflow">else</span>
<a name="l00638"></a>00638     _dbus_verbose (<span class="stringliteral">&quot;WSASend: = %ld\n&quot;</span>, bytes_written);
<a name="l00639"></a>00639     
<a name="l00640"></a>00640   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00641"></a>00641     <span class="keywordflow">goto</span> again;
<a name="l00642"></a>00642       
<a name="l00643"></a>00643   <span class="keywordflow">return</span> bytes_written;
<a name="l00644"></a>00644 }
<a name="l00645"></a>00645 
<a name="l00646"></a>00646 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00647"></a>00647 _dbus_socket_is_invalid (<span class="keywordtype">int</span> fd)
<a name="l00648"></a>00648 {
<a name="l00649"></a>00649     <span class="keywordflow">return</span> fd == INVALID_SOCKET ? <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a> : <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00650"></a>00650 }
<a name="l00651"></a>00651 
<a name="l00652"></a>00652 <span class="preprocessor">#if 0</span>
<a name="l00653"></a>00653 <span class="preprocessor"></span>
<a name="l00662"></a>00662 <span class="keywordtype">int</span>
<a name="l00663"></a>00663 _dbus_connect_named_pipe (<span class="keyword">const</span> <span class="keywordtype">char</span>     *path,
<a name="l00664"></a>00664                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l00665"></a>00665 {
<a name="l00666"></a>00666   _dbus_assert_not_reached (<span class="stringliteral">&quot;not implemented&quot;</span>);
<a name="l00667"></a>00667 }
<a name="l00668"></a>00668 
<a name="l00669"></a>00669 <span class="preprocessor">#endif</span>
<a name="l00670"></a>00670 <span class="preprocessor"></span>
<a name="l00674"></a>00674 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00675"></a>00675 _dbus_win_startup_winsock (<span class="keywordtype">void</span>)
<a name="l00676"></a>00676 {
<a name="l00677"></a>00677   <span class="comment">/* Straight from MSDN, deuglified */</span>
<a name="l00678"></a>00678 
<a name="l00679"></a>00679   <span class="comment">/* Protected by _DBUS_LOCK_sysdeps */</span>
<a name="l00680"></a>00680   <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> beenhere = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00681"></a>00681 
<a name="l00682"></a>00682   WORD wVersionRequested;
<a name="l00683"></a>00683   WSADATA wsaData;
<a name="l00684"></a>00684   <span class="keywordtype">int</span> err;
<a name="l00685"></a>00685 
<a name="l00686"></a>00686   <span class="keywordflow">if</span> (!_DBUS_LOCK (sysdeps))
<a name="l00687"></a>00687     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00688"></a>00688 
<a name="l00689"></a>00689   <span class="keywordflow">if</span> (beenhere)
<a name="l00690"></a>00690     <span class="keywordflow">goto</span> out;
<a name="l00691"></a>00691 
<a name="l00692"></a>00692   wVersionRequested = MAKEWORD (2, 0);
<a name="l00693"></a>00693 
<a name="l00694"></a>00694   err = WSAStartup (wVersionRequested, &amp;wsaData);
<a name="l00695"></a>00695   <span class="keywordflow">if</span> (err != 0)
<a name="l00696"></a>00696     {
<a name="l00697"></a>00697       _dbus_assert_not_reached (<span class="stringliteral">&quot;Could not initialize WinSock&quot;</span>);
<a name="l00698"></a>00698       <a class="code" href="group__DBusSysdeps.html#ga83c51771d3c4e612522bd5ad72e6ad7a" title="Aborts the program with SIGABRT (dumping core).">_dbus_abort</a> ();
<a name="l00699"></a>00699     }
<a name="l00700"></a>00700 
<a name="l00701"></a>00701   <span class="comment">/* Confirm that the WinSock DLL supports 2.0.  Note that if the DLL</span>
<a name="l00702"></a>00702 <span class="comment">   * supports versions greater than 2.0 in addition to 2.0, it will</span>
<a name="l00703"></a>00703 <span class="comment">   * still return 2.0 in wVersion since that is the version we</span>
<a name="l00704"></a>00704 <span class="comment">   * requested.</span>
<a name="l00705"></a>00705 <span class="comment">   */</span>
<a name="l00706"></a>00706   <span class="keywordflow">if</span> (LOBYTE (wsaData.wVersion) != 2 ||
<a name="l00707"></a>00707       HIBYTE (wsaData.wVersion) != 0)
<a name="l00708"></a>00708     {
<a name="l00709"></a>00709       _dbus_assert_not_reached (<span class="stringliteral">&quot;No usable WinSock found&quot;</span>);
<a name="l00710"></a>00710       <a class="code" href="group__DBusSysdeps.html#ga83c51771d3c4e612522bd5ad72e6ad7a" title="Aborts the program with SIGABRT (dumping core).">_dbus_abort</a> ();
<a name="l00711"></a>00711     }
<a name="l00712"></a>00712 
<a name="l00713"></a>00713   beenhere = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00714"></a>00714 
<a name="l00715"></a>00715 out:
<a name="l00716"></a>00716   _DBUS_UNLOCK (sysdeps);
<a name="l00717"></a>00717   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00718"></a>00718 }
<a name="l00719"></a>00719 
<a name="l00720"></a>00720 
<a name="l00721"></a>00721 
<a name="l00722"></a>00722 
<a name="l00723"></a>00723 
<a name="l00724"></a>00724 
<a name="l00725"></a>00725 
<a name="l00726"></a>00726 
<a name="l00727"></a>00727 
<a name="l00728"></a>00728 <span class="comment">/************************************************************************</span>
<a name="l00729"></a>00729 <span class="comment"> </span>
<a name="l00730"></a>00730 <span class="comment"> UTF / string code</span>
<a name="l00731"></a>00731 <span class="comment"> </span>
<a name="l00732"></a>00732 <span class="comment"> ************************************************************************/</span>
<a name="l00733"></a>00733 
<a name="l00737"></a><a class="code" href="group__DBusSysdeps.html#gaffaf8b5bb832c20a8ccb10f012920776">00737</a> <span class="keywordtype">int</span> <a class="code" href="group__DBusSysdeps.html#gaffaf8b5bb832c20a8ccb10f012920776" title="Measure the length of the given format string and arguments, not including the terminating nul...">_dbus_printf_string_upper_bound</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *format,
<a name="l00738"></a>00738                                      va_list args)
<a name="l00739"></a>00739 {
<a name="l00740"></a>00740   <span class="comment">/* MSVCRT&#39;s vsnprintf semantics are a bit different */</span>
<a name="l00741"></a>00741   <span class="keywordtype">char</span> buf[1024];
<a name="l00742"></a>00742   <span class="keywordtype">int</span> bufsize;
<a name="l00743"></a>00743   <span class="keywordtype">int</span> len;
<a name="l00744"></a>00744   va_list args_copy;
<a name="l00745"></a>00745 
<a name="l00746"></a>00746   bufsize = <span class="keyword">sizeof</span> (buf);
<a name="l00747"></a>00747   DBUS_VA_COPY (args_copy, args);
<a name="l00748"></a>00748   len = _vsnprintf (buf, bufsize - 1, format, args_copy);
<a name="l00749"></a>00749   va_end (args_copy);
<a name="l00750"></a>00750 
<a name="l00751"></a>00751   <span class="keywordflow">while</span> (len == -1) <span class="comment">/* try again */</span>
<a name="l00752"></a>00752     {
<a name="l00753"></a>00753       <span class="keywordtype">char</span> *p;
<a name="l00754"></a>00754 
<a name="l00755"></a>00755       bufsize *= 2;
<a name="l00756"></a>00756 
<a name="l00757"></a>00757       p = malloc (bufsize);
<a name="l00758"></a>00758 
<a name="l00759"></a>00759       <span class="keywordflow">if</span> (p == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00760"></a>00760         <span class="keywordflow">return</span> -1;
<a name="l00761"></a>00761 
<a name="l00762"></a>00762       DBUS_VA_COPY (args_copy, args);
<a name="l00763"></a>00763       len = _vsnprintf (p, bufsize - 1, format, args_copy);
<a name="l00764"></a>00764       va_end (args_copy);
<a name="l00765"></a>00765       free (p);
<a name="l00766"></a>00766     }
<a name="l00767"></a>00767 
<a name="l00768"></a>00768   <span class="keywordflow">return</span> len;
<a name="l00769"></a>00769 }
<a name="l00770"></a>00770 
<a name="l00771"></a>00771 
<a name="l00779"></a>00779 <span class="keywordtype">wchar_t</span> *
<a name="l00780"></a>00780 _dbus_win_utf8_to_utf16 (<span class="keyword">const</span> <span class="keywordtype">char</span> *str,
<a name="l00781"></a>00781                          <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l00782"></a>00782 {
<a name="l00783"></a>00783   <a class="code" href="structDBusString.html">DBusString</a> s;
<a name="l00784"></a>00784   <span class="keywordtype">int</span> n;
<a name="l00785"></a>00785   <span class="keywordtype">wchar_t</span> *retval;
<a name="l00786"></a>00786 
<a name="l00787"></a>00787   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;s, str);
<a name="l00788"></a>00788 
<a name="l00789"></a>00789   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga65f0f04b7c9371406fc87343f691e8da" title="Checks that the given range of the string is valid UTF-8.">_dbus_string_validate_utf8</a> (&amp;s, 0, <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (&amp;s)))
<a name="l00790"></a>00790     {
<a name="l00791"></a>00791       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;Invalid UTF-8&quot;</span>);
<a name="l00792"></a>00792       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00793"></a>00793     }
<a name="l00794"></a>00794 
<a name="l00795"></a>00795   n = MultiByteToWideChar (CP_UTF8, 0, str, -1, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0);
<a name="l00796"></a>00796 
<a name="l00797"></a>00797   <span class="keywordflow">if</span> (n == 0)
<a name="l00798"></a>00798     {
<a name="l00799"></a>00799       _dbus_win_set_error_from_win_error (error, GetLastError ());
<a name="l00800"></a>00800       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00801"></a>00801     }
<a name="l00802"></a>00802 
<a name="l00803"></a>00803   retval = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<span class="keywordtype">wchar_t</span>, n);
<a name="l00804"></a>00804 
<a name="l00805"></a>00805   <span class="keywordflow">if</span> (!retval)
<a name="l00806"></a>00806     {
<a name="l00807"></a>00807       _DBUS_SET_OOM (error);
<a name="l00808"></a>00808       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00809"></a>00809     }
<a name="l00810"></a>00810 
<a name="l00811"></a>00811   <span class="keywordflow">if</span> (MultiByteToWideChar (CP_UTF8, 0, str, -1, retval, n) != n)
<a name="l00812"></a>00812     {
<a name="l00813"></a>00813       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (retval);
<a name="l00814"></a>00814       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;MultiByteToWideChar inconsistency&quot;</span>);
<a name="l00815"></a>00815       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00816"></a>00816     }
<a name="l00817"></a>00817 
<a name="l00818"></a>00818   <span class="keywordflow">return</span> retval;
<a name="l00819"></a>00819 }
<a name="l00820"></a>00820 
<a name="l00828"></a>00828 <span class="keywordtype">char</span> *
<a name="l00829"></a>00829 _dbus_win_utf16_to_utf8 (<span class="keyword">const</span> <span class="keywordtype">wchar_t</span> *str,
<a name="l00830"></a>00830                          <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>     *error)
<a name="l00831"></a>00831 {
<a name="l00832"></a>00832   <span class="keywordtype">int</span> n;
<a name="l00833"></a>00833   <span class="keywordtype">char</span> *retval;
<a name="l00834"></a>00834 
<a name="l00835"></a>00835   n = WideCharToMultiByte (CP_UTF8, 0, str, -1, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00836"></a>00836 
<a name="l00837"></a>00837   <span class="keywordflow">if</span> (n == 0)
<a name="l00838"></a>00838     {
<a name="l00839"></a>00839       _dbus_win_set_error_from_win_error (error, GetLastError ());
<a name="l00840"></a>00840       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00841"></a>00841     }
<a name="l00842"></a>00842 
<a name="l00843"></a>00843   retval = <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (n);
<a name="l00844"></a>00844 
<a name="l00845"></a>00845   <span class="keywordflow">if</span> (!retval)
<a name="l00846"></a>00846     {
<a name="l00847"></a>00847       _DBUS_SET_OOM (error);
<a name="l00848"></a>00848       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00849"></a>00849     }
<a name="l00850"></a>00850 
<a name="l00851"></a>00851   <span class="keywordflow">if</span> (WideCharToMultiByte (CP_UTF8, 0, str, -1, retval, n, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>) != n)
<a name="l00852"></a>00852     {
<a name="l00853"></a>00853       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (retval);
<a name="l00854"></a>00854       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;WideCharToMultiByte inconsistency&quot;</span>);
<a name="l00855"></a>00855       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00856"></a>00856     }
<a name="l00857"></a>00857 
<a name="l00858"></a>00858   <span class="keywordflow">return</span> retval;
<a name="l00859"></a>00859 }
<a name="l00860"></a>00860 
<a name="l00861"></a>00861 
<a name="l00862"></a>00862 
<a name="l00863"></a>00863 
<a name="l00864"></a>00864 
<a name="l00865"></a>00865 
<a name="l00866"></a>00866 <span class="comment">/************************************************************************</span>
<a name="l00867"></a>00867 <span class="comment"> </span>
<a name="l00868"></a>00868 <span class="comment"> </span>
<a name="l00869"></a>00869 <span class="comment"> ************************************************************************/</span>
<a name="l00870"></a>00870 
<a name="l00871"></a>00871 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00872"></a>00872 _dbus_win_account_to_sid (<span class="keyword">const</span> <span class="keywordtype">wchar_t</span> *waccount,
<a name="l00873"></a>00873                           <span class="keywordtype">void</span>           **ppsid,
<a name="l00874"></a>00874                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>       *error)
<a name="l00875"></a>00875 {
<a name="l00876"></a>00876   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00877"></a>00877   DWORD sid_length, wdomain_length;
<a name="l00878"></a>00878   SID_NAME_USE use;
<a name="l00879"></a>00879   <span class="keywordtype">wchar_t</span> *wdomain;
<a name="l00880"></a>00880 
<a name="l00881"></a>00881   *ppsid = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00882"></a>00882 
<a name="l00883"></a>00883   sid_length = 0;
<a name="l00884"></a>00884   wdomain_length = 0;
<a name="l00885"></a>00885   <span class="keywordflow">if</span> (!LookupAccountNameW (<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, waccount, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, &amp;sid_length,
<a name="l00886"></a>00886                            <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, &amp;wdomain_length, &amp;use) &amp;&amp;
<a name="l00887"></a>00887       GetLastError () != ERROR_INSUFFICIENT_BUFFER)
<a name="l00888"></a>00888     {
<a name="l00889"></a>00889       _dbus_win_set_error_from_win_error (error, GetLastError ());
<a name="l00890"></a>00890       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00891"></a>00891     }
<a name="l00892"></a>00892 
<a name="l00893"></a>00893   *ppsid = <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (sid_length);
<a name="l00894"></a>00894   <span class="keywordflow">if</span> (!*ppsid)
<a name="l00895"></a>00895     {
<a name="l00896"></a>00896       _DBUS_SET_OOM (error);
<a name="l00897"></a>00897       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00898"></a>00898     }
<a name="l00899"></a>00899 
<a name="l00900"></a>00900   wdomain = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<span class="keywordtype">wchar_t</span>, wdomain_length);
<a name="l00901"></a>00901   <span class="keywordflow">if</span> (!wdomain)
<a name="l00902"></a>00902     {
<a name="l00903"></a>00903       _DBUS_SET_OOM (error);
<a name="l00904"></a>00904       <span class="keywordflow">goto</span> out1;
<a name="l00905"></a>00905     }
<a name="l00906"></a>00906 
<a name="l00907"></a>00907   <span class="keywordflow">if</span> (!LookupAccountNameW (<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, waccount, (PSID) *ppsid, &amp;sid_length,
<a name="l00908"></a>00908                            wdomain, &amp;wdomain_length, &amp;use))
<a name="l00909"></a>00909     {
<a name="l00910"></a>00910       _dbus_win_set_error_from_win_error (error, GetLastError ());
<a name="l00911"></a>00911       <span class="keywordflow">goto</span> out2;
<a name="l00912"></a>00912     }
<a name="l00913"></a>00913 
<a name="l00914"></a>00914   <span class="keywordflow">if</span> (!IsValidSid ((PSID) *ppsid))
<a name="l00915"></a>00915     {
<a name="l00916"></a>00916       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;Invalid SID&quot;</span>);
<a name="l00917"></a>00917       <span class="keywordflow">goto</span> out2;
<a name="l00918"></a>00918     }
<a name="l00919"></a>00919 
<a name="l00920"></a>00920   retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00921"></a>00921 
<a name="l00922"></a>00922 out2:
<a name="l00923"></a>00923   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (wdomain);
<a name="l00924"></a>00924 out1:
<a name="l00925"></a>00925   <span class="keywordflow">if</span> (!retval)
<a name="l00926"></a>00926     {
<a name="l00927"></a>00927       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (*ppsid);
<a name="l00928"></a>00928       *ppsid = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00929"></a>00929     }
<a name="l00930"></a>00930 
<a name="l00931"></a>00931   <span class="keywordflow">return</span> retval;
<a name="l00932"></a>00932 }
<a name="l00933"></a>00933 
<a name="l00943"></a>00943 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
<a name="l00944"></a><a class="code" href="group__DBusSysdeps.html#ga1b30aa55e8758ed6e1b62e0f86866543">00944</a> <a class="code" href="group__DBusSysdeps.html#ga1b30aa55e8758ed6e1b62e0f86866543" title="The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...">_dbus_pid_for_log</a> (<span class="keywordtype">void</span>)
<a name="l00945"></a>00945 {
<a name="l00946"></a>00946   <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a> ();
<a name="l00947"></a>00947 }
<a name="l00948"></a>00948 
<a name="l00949"></a>00949 <span class="preprocessor">#ifndef DBUS_WINCE</span>
<a name="l00950"></a>00950 <span class="preprocessor"></span>
<a name="l00951"></a>00951 <span class="keyword">static</span> BOOL is_winxp_sp3_or_lower()
<a name="l00952"></a>00952 {
<a name="l00953"></a>00953    OSVERSIONINFOEX osvi;
<a name="l00954"></a>00954    DWORDLONG dwlConditionMask = 0;
<a name="l00955"></a>00955    <span class="keywordtype">int</span> op=VER_LESS_EQUAL;
<a name="l00956"></a>00956 
<a name="l00957"></a>00957    <span class="comment">// Initialize the OSVERSIONINFOEX structure.</span>
<a name="l00958"></a>00958 
<a name="l00959"></a>00959    ZeroMemory(&amp;osvi, <span class="keyword">sizeof</span>(OSVERSIONINFOEX));
<a name="l00960"></a>00960    osvi.dwOSVersionInfoSize = <span class="keyword">sizeof</span>(OSVERSIONINFOEX);
<a name="l00961"></a>00961    osvi.dwMajorVersion = 5;
<a name="l00962"></a>00962    osvi.dwMinorVersion = 1;
<a name="l00963"></a>00963    osvi.wServicePackMajor = 3;
<a name="l00964"></a>00964    osvi.wServicePackMinor = 0;
<a name="l00965"></a>00965 
<a name="l00966"></a>00966    <span class="comment">// Initialize the condition mask.</span>
<a name="l00967"></a>00967 
<a name="l00968"></a>00968    VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );
<a name="l00969"></a>00969    VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );
<a name="l00970"></a>00970    VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op );
<a name="l00971"></a>00971    VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op );
<a name="l00972"></a>00972 
<a name="l00973"></a>00973    <span class="comment">// Perform the test.</span>
<a name="l00974"></a>00974 
<a name="l00975"></a>00975    <span class="keywordflow">return</span> VerifyVersionInfo(
<a name="l00976"></a>00976       &amp;osvi,
<a name="l00977"></a>00977       VER_MAJORVERSION | VER_MINORVERSION |
<a name="l00978"></a>00978       VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
<a name="l00979"></a>00979       dwlConditionMask);
<a name="l00980"></a>00980 }
<a name="l00981"></a>00981 
<a name="l00987"></a>00987 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00988"></a>00988 _dbus_getsid(<span class="keywordtype">char</span> **sid, <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> process_id)
<a name="l00989"></a>00989 {
<a name="l00990"></a>00990   HANDLE process_token = INVALID_HANDLE_VALUE;
<a name="l00991"></a>00991   TOKEN_USER *token_user = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00992"></a>00992   DWORD n;
<a name="l00993"></a>00993   PSID psid;
<a name="l00994"></a>00994   <span class="keywordtype">int</span> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00995"></a>00995 
<a name="l00996"></a>00996   HANDLE process_handle = OpenProcess(is_winxp_sp3_or_lower() ? PROCESS_QUERY_INFORMATION : PROCESS_QUERY_LIMITED_INFORMATION, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, process_id);
<a name="l00997"></a>00997 
<a name="l00998"></a>00998   <span class="keywordflow">if</span> (!OpenProcessToken (process_handle, TOKEN_QUERY, &amp;process_token))
<a name="l00999"></a>00999     {
<a name="l01000"></a>01000       _dbus_win_warn_win_error (<span class="stringliteral">&quot;OpenProcessToken failed&quot;</span>, GetLastError ());
<a name="l01001"></a>01001       <span class="keywordflow">goto</span> failed;
<a name="l01002"></a>01002     }
<a name="l01003"></a>01003   <span class="keywordflow">if</span> ((!GetTokenInformation (process_token, TokenUser, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0, &amp;n)
<a name="l01004"></a>01004             &amp;&amp; GetLastError () != ERROR_INSUFFICIENT_BUFFER)
<a name="l01005"></a>01005            || (token_user = alloca (n)) == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>
<a name="l01006"></a>01006            || !GetTokenInformation (process_token, TokenUser, token_user, n, &amp;n))
<a name="l01007"></a>01007     {
<a name="l01008"></a>01008       _dbus_win_warn_win_error (<span class="stringliteral">&quot;GetTokenInformation failed&quot;</span>, GetLastError ());
<a name="l01009"></a>01009       <span class="keywordflow">goto</span> failed;
<a name="l01010"></a>01010     }
<a name="l01011"></a>01011   psid = token_user-&gt;User.Sid;
<a name="l01012"></a>01012   <span class="keywordflow">if</span> (!IsValidSid (psid))
<a name="l01013"></a>01013     {
<a name="l01014"></a>01014       _dbus_verbose(<span class="stringliteral">&quot;%s invalid sid\n&quot;</span>,__FUNCTION__);
<a name="l01015"></a>01015       <span class="keywordflow">goto</span> failed;
<a name="l01016"></a>01016     }
<a name="l01017"></a>01017   <span class="keywordflow">if</span> (!ConvertSidToStringSidA (psid, sid))
<a name="l01018"></a>01018     {
<a name="l01019"></a>01019       _dbus_verbose(<span class="stringliteral">&quot;%s invalid sid\n&quot;</span>,__FUNCTION__);
<a name="l01020"></a>01020       <span class="keywordflow">goto</span> failed;
<a name="l01021"></a>01021     }
<a name="l01022"></a>01022 <span class="comment">//okay:</span>
<a name="l01023"></a>01023   retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01024"></a>01024 
<a name="l01025"></a>01025 failed:
<a name="l01026"></a>01026   CloseHandle (process_handle);
<a name="l01027"></a>01027   <span class="keywordflow">if</span> (process_token != INVALID_HANDLE_VALUE)
<a name="l01028"></a>01028     CloseHandle (process_token);
<a name="l01029"></a>01029 
<a name="l01030"></a>01030   _dbus_verbose(<span class="stringliteral">&quot;_dbus_getsid() got &#39;%s&#39; and returns %d\n&quot;</span>, *sid, retval);
<a name="l01031"></a>01031   <span class="keywordflow">return</span> retval;
<a name="l01032"></a>01032 }
<a name="l01033"></a>01033 <span class="preprocessor">#endif</span>
<a name="l01034"></a>01034 <span class="preprocessor"></span>
<a name="l01035"></a>01035 <span class="comment">/************************************************************************</span>
<a name="l01036"></a>01036 <span class="comment"> </span>
<a name="l01037"></a>01037 <span class="comment"> pipes</span>
<a name="l01038"></a>01038 <span class="comment"> </span>
<a name="l01039"></a>01039 <span class="comment"> ************************************************************************/</span>
<a name="l01040"></a>01040 
<a name="l01051"></a>01051 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01052"></a><a class="code" href="group__DBusSysdeps.html#gae96a3f400324b065f78a865a86454d09">01052</a> <a class="code" href="group__DBusSysdeps.html#gae96a3f400324b065f78a865a86454d09" title="Creates a full-duplex pipe (as in socketpair()).">_dbus_full_duplex_pipe</a> (<span class="keywordtype">int</span>        *fd1,
<a name="l01053"></a>01053                         <span class="keywordtype">int</span>        *fd2,
<a name="l01054"></a>01054                         <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> blocking,
<a name="l01055"></a>01055                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l01056"></a>01056 {
<a name="l01057"></a>01057   SOCKET temp, socket1 = -1, socket2 = -1;
<a name="l01058"></a>01058   <span class="keyword">struct </span>sockaddr_in saddr;
<a name="l01059"></a>01059   <span class="keywordtype">int</span> len;
<a name="l01060"></a>01060   u_long arg;
<a name="l01061"></a>01061 
<a name="l01062"></a>01062   <span class="keywordflow">if</span> (!_dbus_win_startup_winsock ())
<a name="l01063"></a>01063     {
<a name="l01064"></a>01064       _DBUS_SET_OOM (error);
<a name="l01065"></a>01065       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01066"></a>01066     }
<a name="l01067"></a>01067 
<a name="l01068"></a>01068   temp = socket (AF_INET, SOCK_STREAM, 0);
<a name="l01069"></a>01069   <span class="keywordflow">if</span> (temp == INVALID_SOCKET)
<a name="l01070"></a>01070     {
<a name="l01071"></a>01071       DBUS_SOCKET_SET_ERRNO ();
<a name="l01072"></a>01072       <span class="keywordflow">goto</span> out0;
<a name="l01073"></a>01073     }
<a name="l01074"></a>01074 
<a name="l01075"></a>01075   _DBUS_ZERO (saddr);
<a name="l01076"></a>01076   saddr.sin_family = AF_INET;
<a name="l01077"></a>01077   saddr.sin_port = 0;
<a name="l01078"></a>01078   saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
<a name="l01079"></a>01079 
<a name="l01080"></a>01080   <span class="keywordflow">if</span> (bind (temp, (<span class="keyword">struct</span> sockaddr *)&amp;saddr, <span class="keyword">sizeof</span> (saddr)) == SOCKET_ERROR)
<a name="l01081"></a>01081     {
<a name="l01082"></a>01082       DBUS_SOCKET_SET_ERRNO ();
<a name="l01083"></a>01083       <span class="keywordflow">goto</span> out0;
<a name="l01084"></a>01084     }
<a name="l01085"></a>01085 
<a name="l01086"></a>01086   <span class="keywordflow">if</span> (listen (temp, 1) == SOCKET_ERROR)
<a name="l01087"></a>01087     {
<a name="l01088"></a>01088       DBUS_SOCKET_SET_ERRNO ();
<a name="l01089"></a>01089       <span class="keywordflow">goto</span> out0;
<a name="l01090"></a>01090     }
<a name="l01091"></a>01091 
<a name="l01092"></a>01092   len = <span class="keyword">sizeof</span> (saddr);
<a name="l01093"></a>01093   <span class="keywordflow">if</span> (getsockname (temp, (<span class="keyword">struct</span> sockaddr *)&amp;saddr, &amp;len) == SOCKET_ERROR)
<a name="l01094"></a>01094     {
<a name="l01095"></a>01095       DBUS_SOCKET_SET_ERRNO ();
<a name="l01096"></a>01096       <span class="keywordflow">goto</span> out0;
<a name="l01097"></a>01097     }
<a name="l01098"></a>01098 
<a name="l01099"></a>01099   socket1 = socket (AF_INET, SOCK_STREAM, 0);
<a name="l01100"></a>01100   <span class="keywordflow">if</span> (socket1 == INVALID_SOCKET)
<a name="l01101"></a>01101     {
<a name="l01102"></a>01102       DBUS_SOCKET_SET_ERRNO ();
<a name="l01103"></a>01103       <span class="keywordflow">goto</span> out0;
<a name="l01104"></a>01104     }
<a name="l01105"></a>01105 
<a name="l01106"></a>01106   <span class="keywordflow">if</span> (connect (socket1, (<span class="keyword">struct</span> sockaddr  *)&amp;saddr, len) == SOCKET_ERROR)
<a name="l01107"></a>01107     {
<a name="l01108"></a>01108       DBUS_SOCKET_SET_ERRNO ();
<a name="l01109"></a>01109       <span class="keywordflow">goto</span> out1;
<a name="l01110"></a>01110     }
<a name="l01111"></a>01111 
<a name="l01112"></a>01112   socket2 = accept (temp, (<span class="keyword">struct</span> sockaddr *) &amp;saddr, &amp;len);
<a name="l01113"></a>01113   <span class="keywordflow">if</span> (socket2 == INVALID_SOCKET)
<a name="l01114"></a>01114     {
<a name="l01115"></a>01115       DBUS_SOCKET_SET_ERRNO ();
<a name="l01116"></a>01116       <span class="keywordflow">goto</span> out1;
<a name="l01117"></a>01117     }
<a name="l01118"></a>01118 
<a name="l01119"></a>01119   <span class="keywordflow">if</span> (!blocking)
<a name="l01120"></a>01120     {
<a name="l01121"></a>01121       arg = 1;
<a name="l01122"></a>01122       <span class="keywordflow">if</span> (ioctlsocket (socket1, FIONBIO, &amp;arg) == SOCKET_ERROR)
<a name="l01123"></a>01123         {
<a name="l01124"></a>01124           DBUS_SOCKET_SET_ERRNO ();
<a name="l01125"></a>01125           <span class="keywordflow">goto</span> out2;
<a name="l01126"></a>01126         }
<a name="l01127"></a>01127 
<a name="l01128"></a>01128       arg = 1;
<a name="l01129"></a>01129       <span class="keywordflow">if</span> (ioctlsocket (socket2, FIONBIO, &amp;arg) == SOCKET_ERROR)
<a name="l01130"></a>01130         {
<a name="l01131"></a>01131           DBUS_SOCKET_SET_ERRNO ();
<a name="l01132"></a>01132           <span class="keywordflow">goto</span> out2;
<a name="l01133"></a>01133         }
<a name="l01134"></a>01134     }
<a name="l01135"></a>01135 
<a name="l01136"></a>01136   *fd1 = socket1;
<a name="l01137"></a>01137   *fd2 = socket2;
<a name="l01138"></a>01138 
<a name="l01139"></a>01139   _dbus_verbose (<span class="stringliteral">&quot;full-duplex pipe %d:%d &lt;-&gt; %d:%d\n&quot;</span>,
<a name="l01140"></a>01140                  *fd1, socket1, *fd2, socket2);
<a name="l01141"></a>01141 
<a name="l01142"></a>01142   closesocket (temp);
<a name="l01143"></a>01143 
<a name="l01144"></a>01144   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01145"></a>01145 
<a name="l01146"></a>01146 out2:
<a name="l01147"></a>01147   closesocket (socket2);
<a name="l01148"></a>01148 out1:
<a name="l01149"></a>01149   closesocket (socket1);
<a name="l01150"></a>01150 out0:
<a name="l01151"></a>01151   closesocket (temp);
<a name="l01152"></a>01152 
<a name="l01153"></a>01153   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01154"></a>01154                   <span class="stringliteral">&quot;Could not setup socket pair: %s&quot;</span>,
<a name="l01155"></a>01155                   <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01156"></a>01156 
<a name="l01157"></a>01157   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01158"></a>01158 }
<a name="l01159"></a>01159 
<a name="l01168"></a>01168 <span class="keywordtype">int</span>
<a name="l01169"></a><a class="code" href="group__DBusSysdeps.html#gac1cdb5995dcef6dd54399ab610ae689a">01169</a> <a class="code" href="group__DBusSysdeps.html#gac1cdb5995dcef6dd54399ab610ae689a" title="Wrapper for poll().">_dbus_poll</a> (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fds,
<a name="l01170"></a>01170             <span class="keywordtype">int</span>         n_fds,
<a name="l01171"></a>01171             <span class="keywordtype">int</span>         timeout_milliseconds)
<a name="l01172"></a>01172 {
<a name="l01173"></a>01173 <span class="preprocessor">#define USE_CHRIS_IMPL 0</span>
<a name="l01174"></a>01174 <span class="preprocessor"></span>
<a name="l01175"></a>01175 <span class="preprocessor">#if USE_CHRIS_IMPL</span>
<a name="l01176"></a>01176 <span class="preprocessor"></span>
<a name="l01177"></a>01177 <span class="preprocessor">#define DBUS_POLL_CHAR_BUFFER_SIZE 2000</span>
<a name="l01178"></a>01178 <span class="preprocessor"></span>  <span class="keywordtype">char</span> msg[DBUS_POLL_CHAR_BUFFER_SIZE];
<a name="l01179"></a>01179   <span class="keywordtype">char</span> *msgp;
<a name="l01180"></a>01180 
<a name="l01181"></a>01181   <span class="keywordtype">int</span> ret = 0;
<a name="l01182"></a>01182   <span class="keywordtype">int</span> i;
<a name="l01183"></a>01183   <span class="keyword">struct </span>timeval tv;
<a name="l01184"></a>01184   <span class="keywordtype">int</span> ready;
<a name="l01185"></a>01185 
<a name="l01186"></a>01186 <span class="preprocessor">#define DBUS_STACK_WSAEVENTS 256</span>
<a name="l01187"></a>01187 <span class="preprocessor"></span>  WSAEVENT eventsOnStack[DBUS_STACK_WSAEVENTS];
<a name="l01188"></a>01188   WSAEVENT *pEvents = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01189"></a>01189   <span class="keywordflow">if</span> (n_fds &gt; DBUS_STACK_WSAEVENTS)
<a name="l01190"></a>01190     pEvents = calloc(<span class="keyword">sizeof</span>(WSAEVENT), n_fds);
<a name="l01191"></a>01191   <span class="keywordflow">else</span>
<a name="l01192"></a>01192     pEvents = eventsOnStack;
<a name="l01193"></a>01193 
<a name="l01194"></a>01194 
<a name="l01195"></a>01195 <span class="preprocessor">#ifdef DBUS_ENABLE_VERBOSE_MODE</span>
<a name="l01196"></a>01196 <span class="preprocessor"></span>  msgp = msg;
<a name="l01197"></a>01197   msgp += sprintf (msgp, <span class="stringliteral">&quot;WSAEventSelect: to=%d\n\t&quot;</span>, timeout_milliseconds);
<a name="l01198"></a>01198   <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01199"></a>01199     {
<a name="l01200"></a>01200       <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01201"></a>01201 
<a name="l01202"></a>01202 
<a name="l01203"></a>01203       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>)
<a name="l01204"></a>01204         msgp += sprintf (msgp, <span class="stringliteral">&quot;R:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01205"></a>01205 
<a name="l01206"></a>01206       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>)
<a name="l01207"></a>01207         msgp += sprintf (msgp, <span class="stringliteral">&quot;W:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01208"></a>01208 
<a name="l01209"></a>01209       msgp += sprintf (msgp, <span class="stringliteral">&quot;E:%d\n\t&quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01210"></a>01210 
<a name="l01211"></a>01211       <span class="comment">// FIXME: more robust code for long  msg</span>
<a name="l01212"></a>01212       <span class="comment">//        create on heap when msg[] becomes too small</span>
<a name="l01213"></a>01213       <span class="keywordflow">if</span> (msgp &gt;= msg + DBUS_POLL_CHAR_BUFFER_SIZE)
<a name="l01214"></a>01214         {
<a name="l01215"></a>01215           _dbus_assert_not_reached (<span class="stringliteral">&quot;buffer overflow in _dbus_poll&quot;</span>);
<a name="l01216"></a>01216         }
<a name="l01217"></a>01217     }
<a name="l01218"></a>01218 
<a name="l01219"></a>01219   msgp += sprintf (msgp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l01220"></a>01220   _dbus_verbose (<span class="stringliteral">&quot;%s&quot;</span>,msg);
<a name="l01221"></a>01221 <span class="preprocessor">#endif</span>
<a name="l01222"></a>01222 <span class="preprocessor"></span>  <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01223"></a>01223     {
<a name="l01224"></a>01224       <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01225"></a>01225       WSAEVENT ev;
<a name="l01226"></a>01226       <span class="keywordtype">long</span> lNetworkEvents = FD_OOB;
<a name="l01227"></a>01227 
<a name="l01228"></a>01228       ev = WSACreateEvent();
<a name="l01229"></a>01229 
<a name="l01230"></a>01230       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>)
<a name="l01231"></a>01231         lNetworkEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
<a name="l01232"></a>01232 
<a name="l01233"></a>01233       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>)
<a name="l01234"></a>01234         lNetworkEvents |= FD_WRITE | FD_CONNECT;
<a name="l01235"></a>01235 
<a name="l01236"></a>01236       WSAEventSelect(fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, ev, lNetworkEvents);
<a name="l01237"></a>01237 
<a name="l01238"></a>01238       pEvents[i] = ev;
<a name="l01239"></a>01239     }
<a name="l01240"></a>01240 
<a name="l01241"></a>01241 
<a name="l01242"></a>01242   ready = WSAWaitForMultipleEvents (n_fds, pEvents, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, timeout_milliseconds, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>);
<a name="l01243"></a>01243 
<a name="l01244"></a>01244   <span class="keywordflow">if</span> (DBUS_SOCKET_API_RETURNS_ERROR (ready))
<a name="l01245"></a>01245     {
<a name="l01246"></a>01246       DBUS_SOCKET_SET_ERRNO ();
<a name="l01247"></a>01247       <span class="keywordflow">if</span> (errno != WSAEWOULDBLOCK)
<a name="l01248"></a>01248         _dbus_verbose (<span class="stringliteral">&quot;WSAWaitForMultipleEvents: failed: %s\n&quot;</span>, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01249"></a>01249       ret = -1;
<a name="l01250"></a>01250     }
<a name="l01251"></a>01251   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ready == WSA_WAIT_TIMEOUT)
<a name="l01252"></a>01252     {
<a name="l01253"></a>01253       _dbus_verbose (<span class="stringliteral">&quot;WSAWaitForMultipleEvents: WSA_WAIT_TIMEOUT\n&quot;</span>);
<a name="l01254"></a>01254       ret = 0;
<a name="l01255"></a>01255     }
<a name="l01256"></a>01256   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ready &gt;= WSA_WAIT_EVENT_0 &amp;&amp; ready &lt; (<span class="keywordtype">int</span>)(WSA_WAIT_EVENT_0 + n_fds))
<a name="l01257"></a>01257     {
<a name="l01258"></a>01258       msgp = msg;
<a name="l01259"></a>01259       msgp += sprintf (msgp, <span class="stringliteral">&quot;WSAWaitForMultipleEvents: =%d\n\t&quot;</span>, ready);
<a name="l01260"></a>01260 
<a name="l01261"></a>01261       <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01262"></a>01262         {
<a name="l01263"></a>01263           <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01264"></a>01264           WSANETWORKEVENTS ne;
<a name="l01265"></a>01265 
<a name="l01266"></a>01266           fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> = 0;
<a name="l01267"></a>01267 
<a name="l01268"></a>01268           WSAEnumNetworkEvents(fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, pEvents[i], &amp;ne);
<a name="l01269"></a>01269 
<a name="l01270"></a>01270           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_READ | FD_ACCEPT | FD_CLOSE))
<a name="l01271"></a>01271             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>;
<a name="l01272"></a>01272 
<a name="l01273"></a>01273           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_WRITE | FD_CONNECT))
<a name="l01274"></a>01274             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>;
<a name="l01275"></a>01275 
<a name="l01276"></a>01276           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_OOB))
<a name="l01277"></a>01277             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga231164196ff407eccb732452a2d36468" title="Error condition.">_DBUS_POLLERR</a>;
<a name="l01278"></a>01278 
<a name="l01279"></a>01279           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_READ | FD_ACCEPT | FD_CLOSE))
<a name="l01280"></a>01280               msgp += sprintf (msgp, <span class="stringliteral">&quot;R:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01281"></a>01281 
<a name="l01282"></a>01282           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_WRITE | FD_CONNECT))
<a name="l01283"></a>01283               msgp += sprintf (msgp, <span class="stringliteral">&quot;W:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01284"></a>01284 
<a name="l01285"></a>01285           <span class="keywordflow">if</span> (ne.lNetworkEvents &amp; (FD_OOB))
<a name="l01286"></a>01286               msgp += sprintf (msgp, <span class="stringliteral">&quot;E:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01287"></a>01287 
<a name="l01288"></a>01288           msgp += sprintf (msgp, <span class="stringliteral">&quot;lNetworkEvents:%d &quot;</span>, ne.lNetworkEvents);
<a name="l01289"></a>01289 
<a name="l01290"></a>01290           <span class="keywordflow">if</span>(ne.lNetworkEvents)
<a name="l01291"></a>01291             ret++;
<a name="l01292"></a>01292 
<a name="l01293"></a>01293           WSAEventSelect(fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, pEvents[i], 0);
<a name="l01294"></a>01294         }
<a name="l01295"></a>01295 
<a name="l01296"></a>01296       msgp += sprintf (msgp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l01297"></a>01297       _dbus_verbose (<span class="stringliteral">&quot;%s&quot;</span>,msg);
<a name="l01298"></a>01298     }
<a name="l01299"></a>01299   <span class="keywordflow">else</span>
<a name="l01300"></a>01300     {
<a name="l01301"></a>01301       _dbus_verbose (<span class="stringliteral">&quot;WSAWaitForMultipleEvents: failed for unknown reason!&quot;</span>);
<a name="l01302"></a>01302       ret = -1;
<a name="l01303"></a>01303     }
<a name="l01304"></a>01304 
<a name="l01305"></a>01305   <span class="keywordflow">for</span>(i = 0; i &lt; n_fds; i++)
<a name="l01306"></a>01306     {
<a name="l01307"></a>01307       WSACloseEvent(pEvents[i]);
<a name="l01308"></a>01308     }
<a name="l01309"></a>01309 
<a name="l01310"></a>01310   <span class="keywordflow">if</span> (n_fds &gt; DBUS_STACK_WSAEVENTS)
<a name="l01311"></a>01311     free(pEvents);
<a name="l01312"></a>01312 
<a name="l01313"></a>01313   <span class="keywordflow">return</span> ret;
<a name="l01314"></a>01314 
<a name="l01315"></a>01315 <span class="preprocessor">#else   </span><span class="comment">/* USE_CHRIS_IMPL */</span>
<a name="l01316"></a>01316 
<a name="l01317"></a>01317 <span class="preprocessor">#define DBUS_POLL_CHAR_BUFFER_SIZE 2000</span>
<a name="l01318"></a>01318 <span class="preprocessor"></span>  <span class="keywordtype">char</span> msg[DBUS_POLL_CHAR_BUFFER_SIZE];
<a name="l01319"></a>01319   <span class="keywordtype">char</span> *msgp;
<a name="l01320"></a>01320 
<a name="l01321"></a>01321   fd_set read_set, write_set, err_set;
<a name="l01322"></a>01322   <span class="keywordtype">int</span> max_fd = 0;
<a name="l01323"></a>01323   <span class="keywordtype">int</span> i;
<a name="l01324"></a>01324   <span class="keyword">struct </span>timeval tv;
<a name="l01325"></a>01325   <span class="keywordtype">int</span> ready;
<a name="l01326"></a>01326 
<a name="l01327"></a>01327   FD_ZERO (&amp;read_set);
<a name="l01328"></a>01328   FD_ZERO (&amp;write_set);
<a name="l01329"></a>01329   FD_ZERO (&amp;err_set);
<a name="l01330"></a>01330 
<a name="l01331"></a>01331 
<a name="l01332"></a>01332 <span class="preprocessor">#ifdef DBUS_ENABLE_VERBOSE_MODE</span>
<a name="l01333"></a>01333 <span class="preprocessor"></span>  msgp = msg;
<a name="l01334"></a>01334   msgp += sprintf (msgp, <span class="stringliteral">&quot;select: to=%d\n\t&quot;</span>, timeout_milliseconds);
<a name="l01335"></a>01335   <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01336"></a>01336     {
<a name="l01337"></a>01337       <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01338"></a>01338 
<a name="l01339"></a>01339 
<a name="l01340"></a>01340       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>)
<a name="l01341"></a>01341         msgp += sprintf (msgp, <span class="stringliteral">&quot;R:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01342"></a>01342 
<a name="l01343"></a>01343       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>)
<a name="l01344"></a>01344         msgp += sprintf (msgp, <span class="stringliteral">&quot;W:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01345"></a>01345 
<a name="l01346"></a>01346       msgp += sprintf (msgp, <span class="stringliteral">&quot;E:%d\n\t&quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01347"></a>01347 
<a name="l01348"></a>01348       <span class="comment">// FIXME: more robust code for long  msg</span>
<a name="l01349"></a>01349       <span class="comment">//        create on heap when msg[] becomes too small</span>
<a name="l01350"></a>01350       <span class="keywordflow">if</span> (msgp &gt;= msg + DBUS_POLL_CHAR_BUFFER_SIZE)
<a name="l01351"></a>01351         {
<a name="l01352"></a>01352           _dbus_assert_not_reached (<span class="stringliteral">&quot;buffer overflow in _dbus_poll&quot;</span>);
<a name="l01353"></a>01353         }
<a name="l01354"></a>01354     }
<a name="l01355"></a>01355 
<a name="l01356"></a>01356   msgp += sprintf (msgp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l01357"></a>01357   _dbus_verbose (<span class="stringliteral">&quot;%s&quot;</span>,msg);
<a name="l01358"></a>01358 <span class="preprocessor">#endif</span>
<a name="l01359"></a>01359 <span class="preprocessor"></span>  <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01360"></a>01360     {
<a name="l01361"></a>01361       <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i]; 
<a name="l01362"></a>01362 
<a name="l01363"></a>01363       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>)
<a name="l01364"></a>01364         FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;read_set);
<a name="l01365"></a>01365 
<a name="l01366"></a>01366       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>)
<a name="l01367"></a>01367         FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;write_set);
<a name="l01368"></a>01368 
<a name="l01369"></a>01369       FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;err_set);
<a name="l01370"></a>01370 
<a name="l01371"></a>01371       max_fd = MAX (max_fd, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01372"></a>01372     }
<a name="l01373"></a>01373 
<a name="l01374"></a>01374   <span class="comment">// Avoid random lockups with send(), for lack of a better solution so far</span>
<a name="l01375"></a>01375   tv.tv_sec = timeout_milliseconds &lt; 0 ? 1 : timeout_milliseconds / 1000;
<a name="l01376"></a>01376   tv.tv_usec = timeout_milliseconds &lt; 0 ? 0 : (timeout_milliseconds % 1000) * 1000;
<a name="l01377"></a>01377 
<a name="l01378"></a>01378   ready = select (max_fd + 1, &amp;read_set, &amp;write_set, &amp;err_set, &amp;tv);
<a name="l01379"></a>01379 
<a name="l01380"></a>01380   <span class="keywordflow">if</span> (DBUS_SOCKET_API_RETURNS_ERROR (ready))
<a name="l01381"></a>01381     {
<a name="l01382"></a>01382       DBUS_SOCKET_SET_ERRNO ();
<a name="l01383"></a>01383       <span class="keywordflow">if</span> (errno != WSAEWOULDBLOCK)
<a name="l01384"></a>01384         _dbus_verbose (<span class="stringliteral">&quot;select: failed: %s\n&quot;</span>, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01385"></a>01385     }
<a name="l01386"></a>01386   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ready == 0)
<a name="l01387"></a>01387     _dbus_verbose (<span class="stringliteral">&quot;select: = 0\n&quot;</span>);
<a name="l01388"></a>01388   <span class="keywordflow">else</span>
<a name="l01389"></a>01389     <span class="keywordflow">if</span> (ready &gt; 0)
<a name="l01390"></a>01390       {
<a name="l01391"></a>01391 <span class="preprocessor">#ifdef DBUS_ENABLE_VERBOSE_MODE</span>
<a name="l01392"></a>01392 <span class="preprocessor"></span>        msgp = msg;
<a name="l01393"></a>01393         msgp += sprintf (msgp, <span class="stringliteral">&quot;select: = %d:\n\t&quot;</span>, ready);
<a name="l01394"></a>01394 
<a name="l01395"></a>01395         <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01396"></a>01396           {
<a name="l01397"></a>01397             <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01398"></a>01398 
<a name="l01399"></a>01399             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;read_set))
<a name="l01400"></a>01400               msgp += sprintf (msgp, <span class="stringliteral">&quot;R:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01401"></a>01401 
<a name="l01402"></a>01402             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;write_set))
<a name="l01403"></a>01403               msgp += sprintf (msgp, <span class="stringliteral">&quot;W:%d &quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01404"></a>01404 
<a name="l01405"></a>01405             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;err_set))
<a name="l01406"></a>01406               msgp += sprintf (msgp, <span class="stringliteral">&quot;E:%d\n\t&quot;</span>, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l01407"></a>01407           }
<a name="l01408"></a>01408         msgp += sprintf (msgp, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l01409"></a>01409         _dbus_verbose (<span class="stringliteral">&quot;%s&quot;</span>,msg);
<a name="l01410"></a>01410 <span class="preprocessor">#endif</span>
<a name="l01411"></a>01411 <span class="preprocessor"></span>
<a name="l01412"></a>01412         <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l01413"></a>01413           {
<a name="l01414"></a>01414             <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l01415"></a>01415 
<a name="l01416"></a>01416             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> = 0;
<a name="l01417"></a>01417 
<a name="l01418"></a>01418             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;read_set))
<a name="l01419"></a>01419               fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>;
<a name="l01420"></a>01420 
<a name="l01421"></a>01421             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;write_set))
<a name="l01422"></a>01422               fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>;
<a name="l01423"></a>01423 
<a name="l01424"></a>01424             <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;err_set))
<a name="l01425"></a>01425               fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga231164196ff407eccb732452a2d36468" title="Error condition.">_DBUS_POLLERR</a>;
<a name="l01426"></a>01426           }
<a name="l01427"></a>01427       }
<a name="l01428"></a>01428   <span class="keywordflow">return</span> ready;
<a name="l01429"></a>01429 <span class="preprocessor">#endif  </span><span class="comment">/* USE_CHRIS_IMPL */</span>
<a name="l01430"></a>01430 }
<a name="l01431"></a>01431 
<a name="l01432"></a>01432 
<a name="l01433"></a>01433 
<a name="l01434"></a>01434 
<a name="l01435"></a>01435 <span class="comment">/******************************************************************************</span>
<a name="l01436"></a>01436 <span class="comment"> </span>
<a name="l01437"></a>01437 <span class="comment">Original CVS version of dbus-sysdeps.c</span>
<a name="l01438"></a>01438 <span class="comment"> </span>
<a name="l01439"></a>01439 <span class="comment">******************************************************************************/</span>
<a name="l01440"></a>01440 <span class="comment">/* -*- mode: C; c-file-style: &quot;gnu&quot;; indent-tabs-mode: nil; -*- */</span>
<a name="l01441"></a>01441 <span class="comment">/* dbus-sysdeps.c Wrappers around system/libc features (internal to D-Bus implementation)</span>
<a name="l01442"></a>01442 <span class="comment"> * </span>
<a name="l01443"></a>01443 <span class="comment"> * Copyright (C) 2002, 2003  Red Hat, Inc.</span>
<a name="l01444"></a>01444 <span class="comment"> * Copyright (C) 2003 CodeFactory AB</span>
<a name="l01445"></a>01445 <span class="comment"> * Copyright (C) 2005 Novell, Inc.</span>
<a name="l01446"></a>01446 <span class="comment"> *</span>
<a name="l01447"></a>01447 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l01448"></a>01448 <span class="comment"> * </span>
<a name="l01449"></a>01449 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l01450"></a>01450 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l01451"></a>01451 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l01452"></a>01452 <span class="comment"> * (at your option) any later version.</span>
<a name="l01453"></a>01453 <span class="comment"> *</span>
<a name="l01454"></a>01454 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l01455"></a>01455 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l01456"></a>01456 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l01457"></a>01457 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l01458"></a>01458 <span class="comment"> * </span>
<a name="l01459"></a>01459 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l01460"></a>01460 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l01461"></a>01461 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l01462"></a>01462 <span class="comment"> *</span>
<a name="l01463"></a>01463 <span class="comment"> */</span>
<a name="l01464"></a>01464 
<a name="l01465"></a>01465 
<a name="l01471"></a>01471 <span class="keywordtype">void</span>
<a name="l01472"></a><a class="code" href="group__DBusSysdeps.html#ga203e3257b50597a8fe7757c920474a20">01472</a> <a class="code" href="group__DBusSysdeps.html#ga203e3257b50597a8fe7757c920474a20" title="Exit the process, returning the given value.">_dbus_exit</a> (<span class="keywordtype">int</span> code)
<a name="l01473"></a>01473 {
<a name="l01474"></a>01474   _exit (code);
<a name="l01475"></a>01475 }
<a name="l01476"></a>01476 
<a name="l01488"></a>01488 <span class="keywordtype">int</span>
<a name="l01489"></a><a class="code" href="group__DBusSysdeps.html#gaa3adf90f6e47d30eeacf0a27d1a09ee5">01489</a> <a class="code" href="group__DBusSysdeps.html#gaa3adf90f6e47d30eeacf0a27d1a09ee5" title="Creates a socket and connects to a socket at the given host and port.">_dbus_connect_tcp_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01490"></a>01490                           <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01491"></a>01491                           <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01492"></a>01492                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01493"></a>01493 {
<a name="l01494"></a>01494   <span class="keywordflow">return</span> _dbus_connect_tcp_socket_with_nonce (host, port, family, (<span class="keyword">const</span> <span class="keywordtype">char</span>*)<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error);
<a name="l01495"></a>01495 }
<a name="l01496"></a>01496 
<a name="l01497"></a>01497 <span class="keywordtype">int</span>
<a name="l01498"></a>01498 _dbus_connect_tcp_socket_with_nonce (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01499"></a>01499                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01500"></a>01500                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01501"></a>01501                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *noncefile,
<a name="l01502"></a>01502                                      <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01503"></a>01503 {
<a name="l01504"></a>01504   <span class="keywordtype">int</span> fd = -1, res;
<a name="l01505"></a>01505   <span class="keyword">struct </span>addrinfo hints;
<a name="l01506"></a>01506   <span class="keyword">struct </span>addrinfo *ai, *tmp;
<a name="l01507"></a>01507 
<a name="l01508"></a>01508   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01509"></a>01509 
<a name="l01510"></a>01510   <span class="keywordflow">if</span> (!_dbus_win_startup_winsock ())
<a name="l01511"></a>01511     {
<a name="l01512"></a>01512       _DBUS_SET_OOM (error);
<a name="l01513"></a>01513       <span class="keywordflow">return</span> -1;
<a name="l01514"></a>01514     }
<a name="l01515"></a>01515 
<a name="l01516"></a>01516   _DBUS_ZERO (hints);
<a name="l01517"></a>01517 
<a name="l01518"></a>01518   <span class="keywordflow">if</span> (!family)
<a name="l01519"></a>01519     hints.ai_family = AF_UNSPEC;
<a name="l01520"></a>01520   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv4&quot;</span>))
<a name="l01521"></a>01521     hints.ai_family = AF_INET;
<a name="l01522"></a>01522   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv6&quot;</span>))
<a name="l01523"></a>01523     hints.ai_family = AF_INET6;
<a name="l01524"></a>01524   <span class="keywordflow">else</span>
<a name="l01525"></a>01525     {
<a name="l01526"></a>01526       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01527"></a>01527                       <a class="code" href="group__DBusProtocol.html#gacf5321b161193ad66d5bdf5c910a9792" title="Invalid arguments passed to a method call.">DBUS_ERROR_INVALID_ARGS</a>,
<a name="l01528"></a>01528                       <span class="stringliteral">&quot;Unknown address family %s&quot;</span>, family);
<a name="l01529"></a>01529       <span class="keywordflow">return</span> -1;
<a name="l01530"></a>01530     }
<a name="l01531"></a>01531   hints.ai_protocol = IPPROTO_TCP;
<a name="l01532"></a>01532   hints.ai_socktype = SOCK_STREAM;
<a name="l01533"></a>01533 <span class="preprocessor">#ifdef AI_ADDRCONFIG</span>
<a name="l01534"></a>01534 <span class="preprocessor"></span>  hints.ai_flags = AI_ADDRCONFIG;
<a name="l01535"></a>01535 <span class="preprocessor">#else</span>
<a name="l01536"></a>01536 <span class="preprocessor"></span>  hints.ai_flags = 0;
<a name="l01537"></a>01537 <span class="preprocessor">#endif</span>
<a name="l01538"></a>01538 <span class="preprocessor"></span>
<a name="l01539"></a>01539   <span class="keywordflow">if</span> ((res = getaddrinfo(host, port, &amp;hints, &amp;ai)) != 0 || !ai)
<a name="l01540"></a>01540     {
<a name="l01541"></a>01541       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01542"></a>01542                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (res),
<a name="l01543"></a>01543                       <span class="stringliteral">&quot;Failed to lookup host/port: \&quot;%s:%s\&quot;: %s (%d)&quot;</span>,
<a name="l01544"></a>01544                       host, port, _dbus_strerror(res), res);
<a name="l01545"></a>01545       <span class="keywordflow">return</span> -1;
<a name="l01546"></a>01546     }
<a name="l01547"></a>01547 
<a name="l01548"></a>01548   tmp = ai;
<a name="l01549"></a>01549   <span class="keywordflow">while</span> (tmp)
<a name="l01550"></a>01550     {
<a name="l01551"></a>01551       <span class="keywordflow">if</span> ((fd = socket (tmp-&gt;ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
<a name="l01552"></a>01552         {
<a name="l01553"></a>01553           DBUS_SOCKET_SET_ERRNO ();
<a name="l01554"></a>01554           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01555"></a>01555                           <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01556"></a>01556                           <span class="stringliteral">&quot;Failed to open socket: %s&quot;</span>,
<a name="l01557"></a>01557                           <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01558"></a>01558           freeaddrinfo(ai);
<a name="l01559"></a>01559           <span class="keywordflow">return</span> -1;
<a name="l01560"></a>01560         }
<a name="l01561"></a>01561       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01562"></a>01562 
<a name="l01563"></a>01563       <span class="keywordflow">if</span> (connect (fd, (<span class="keyword">struct</span> sockaddr*) tmp-&gt;ai_addr, tmp-&gt;ai_addrlen) == SOCKET_ERROR)
<a name="l01564"></a>01564         {
<a name="l01565"></a>01565           DBUS_SOCKET_SET_ERRNO ();
<a name="l01566"></a>01566           closesocket(fd);
<a name="l01567"></a>01567           fd = -1;
<a name="l01568"></a>01568           tmp = tmp-&gt;ai_next;
<a name="l01569"></a>01569           <span class="keywordflow">continue</span>;
<a name="l01570"></a>01570         }
<a name="l01571"></a>01571 
<a name="l01572"></a>01572       <span class="keywordflow">break</span>;
<a name="l01573"></a>01573     }
<a name="l01574"></a>01574   freeaddrinfo(ai);
<a name="l01575"></a>01575 
<a name="l01576"></a>01576   <span class="keywordflow">if</span> (fd == -1)
<a name="l01577"></a>01577     {
<a name="l01578"></a>01578       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01579"></a>01579                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01580"></a>01580                       <span class="stringliteral">&quot;Failed to connect to socket \&quot;%s:%s\&quot; %s&quot;</span>,
<a name="l01581"></a>01581                       host, port, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01582"></a>01582       <span class="keywordflow">return</span> -1;
<a name="l01583"></a>01583     }
<a name="l01584"></a>01584 
<a name="l01585"></a>01585   <span class="keywordflow">if</span> (noncefile != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l01586"></a>01586     {
<a name="l01587"></a>01587       <a class="code" href="structDBusString.html">DBusString</a> noncefileStr;
<a name="l01588"></a>01588       <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> ret;
<a name="l01589"></a>01589       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;noncefileStr) ||
<a name="l01590"></a>01590           !<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(&amp;noncefileStr, noncefile))
<a name="l01591"></a>01591         {
<a name="l01592"></a>01592           closesocket (fd);
<a name="l01593"></a>01593           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01594"></a>01594           <span class="keywordflow">return</span> -1;
<a name="l01595"></a>01595         }
<a name="l01596"></a>01596 
<a name="l01597"></a>01597       ret = _dbus_send_nonce (fd, &amp;noncefileStr, error);
<a name="l01598"></a>01598 
<a name="l01599"></a>01599       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;noncefileStr);
<a name="l01600"></a>01600 
<a name="l01601"></a>01601       <span class="keywordflow">if</span> (!ret)
<a name="l01602"></a>01602         {
<a name="l01603"></a>01603           closesocket (fd);
<a name="l01604"></a>01604           <span class="keywordflow">return</span> -1;
<a name="l01605"></a>01605         }
<a name="l01606"></a>01606     }
<a name="l01607"></a>01607 
<a name="l01608"></a>01608   <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (fd);
<a name="l01609"></a>01609 
<a name="l01610"></a>01610   <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (fd, error))
<a name="l01611"></a>01611     {
<a name="l01612"></a>01612       closesocket (fd);
<a name="l01613"></a>01613       <span class="keywordflow">return</span> -1;
<a name="l01614"></a>01614     }
<a name="l01615"></a>01615 
<a name="l01616"></a>01616   <span class="keywordflow">return</span> fd;
<a name="l01617"></a>01617 }
<a name="l01618"></a>01618 
<a name="l01634"></a>01634 <span class="keywordtype">int</span>
<a name="l01635"></a><a class="code" href="group__DBusSysdeps.html#gafdae31b3b61299dbaaccfcb1205a6f30">01635</a> <a class="code" href="group__DBusSysdeps.html#gafdae31b3b61299dbaaccfcb1205a6f30" title="Creates a socket and binds it to the given path, then listens on the socket.">_dbus_listen_tcp_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01636"></a>01636                          <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01637"></a>01637                          <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01638"></a>01638                          <a class="code" href="structDBusString.html">DBusString</a>     *retport,
<a name="l01639"></a>01639                          <span class="keywordtype">int</span>           **fds_p,
<a name="l01640"></a>01640                          <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01641"></a>01641 {
<a name="l01642"></a>01642   <span class="keywordtype">int</span> nlisten_fd = 0, *listen_fd = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, res, i, port_num = -1;
<a name="l01643"></a>01643   <span class="keyword">struct </span>addrinfo hints;
<a name="l01644"></a>01644   <span class="keyword">struct </span>addrinfo *ai, *tmp;
<a name="l01645"></a>01645 
<a name="l01646"></a>01646   <span class="comment">// On Vista, sockaddr_gen must be a sockaddr_in6, and not a sockaddr_in6_old</span>
<a name="l01647"></a>01647   <span class="comment">//That&#39;s required for family == IPv6(which is the default on Vista if family is not given)</span>
<a name="l01648"></a>01648   <span class="comment">//So we use our own union instead of sockaddr_gen:</span>
<a name="l01649"></a>01649 
<a name="l01650"></a>01650   <span class="keyword">typedef</span> <span class="keyword">union </span>{
<a name="l01651"></a>01651         <span class="keyword">struct </span>sockaddr Address;
<a name="l01652"></a>01652         <span class="keyword">struct </span>sockaddr_in AddressIn;
<a name="l01653"></a>01653         <span class="keyword">struct </span>sockaddr_in6 AddressIn6;
<a name="l01654"></a>01654   } mysockaddr_gen;
<a name="l01655"></a>01655 
<a name="l01656"></a>01656   *fds_p = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01657"></a>01657   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01658"></a>01658 
<a name="l01659"></a>01659   <span class="keywordflow">if</span> (!_dbus_win_startup_winsock ())
<a name="l01660"></a>01660     {
<a name="l01661"></a>01661       _DBUS_SET_OOM (error);
<a name="l01662"></a>01662       <span class="keywordflow">return</span> -1;
<a name="l01663"></a>01663     }
<a name="l01664"></a>01664 
<a name="l01665"></a>01665   _DBUS_ZERO (hints);
<a name="l01666"></a>01666 
<a name="l01667"></a>01667   <span class="keywordflow">if</span> (!family)
<a name="l01668"></a>01668     hints.ai_family = AF_UNSPEC;
<a name="l01669"></a>01669   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv4&quot;</span>))
<a name="l01670"></a>01670     hints.ai_family = AF_INET;
<a name="l01671"></a>01671   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv6&quot;</span>))
<a name="l01672"></a>01672     hints.ai_family = AF_INET6;
<a name="l01673"></a>01673   <span class="keywordflow">else</span>
<a name="l01674"></a>01674     {
<a name="l01675"></a>01675       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01676"></a>01676                       <a class="code" href="group__DBusProtocol.html#gacf5321b161193ad66d5bdf5c910a9792" title="Invalid arguments passed to a method call.">DBUS_ERROR_INVALID_ARGS</a>,
<a name="l01677"></a>01677                       <span class="stringliteral">&quot;Unknown address family %s&quot;</span>, family);
<a name="l01678"></a>01678       <span class="keywordflow">return</span> -1;
<a name="l01679"></a>01679     }
<a name="l01680"></a>01680 
<a name="l01681"></a>01681   hints.ai_protocol = IPPROTO_TCP;
<a name="l01682"></a>01682   hints.ai_socktype = SOCK_STREAM;
<a name="l01683"></a>01683 <span class="preprocessor">#ifdef AI_ADDRCONFIG</span>
<a name="l01684"></a>01684 <span class="preprocessor"></span>  hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
<a name="l01685"></a>01685 <span class="preprocessor">#else</span>
<a name="l01686"></a>01686 <span class="preprocessor"></span>  hints.ai_flags = AI_PASSIVE;
<a name="l01687"></a>01687 <span class="preprocessor">#endif</span>
<a name="l01688"></a>01688 <span class="preprocessor"></span>
<a name="l01689"></a>01689  redo_lookup_with_port:
<a name="l01690"></a>01690   <span class="keywordflow">if</span> ((res = getaddrinfo(host, port, &amp;hints, &amp;ai)) != 0 || !ai)
<a name="l01691"></a>01691     {
<a name="l01692"></a>01692       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01693"></a>01693                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (res),
<a name="l01694"></a>01694                       <span class="stringliteral">&quot;Failed to lookup host/port: \&quot;%s:%s\&quot;: %s (%d)&quot;</span>,
<a name="l01695"></a>01695                       host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, _dbus_strerror(res), res);
<a name="l01696"></a>01696       <span class="keywordflow">return</span> -1;
<a name="l01697"></a>01697     }
<a name="l01698"></a>01698 
<a name="l01699"></a>01699   tmp = ai;
<a name="l01700"></a>01700   <span class="keywordflow">while</span> (tmp)
<a name="l01701"></a>01701     {
<a name="l01702"></a>01702       <span class="keywordtype">int</span> fd = -1, *newlisten_fd;
<a name="l01703"></a>01703       <span class="keywordflow">if</span> ((fd = socket (tmp-&gt;ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
<a name="l01704"></a>01704         {
<a name="l01705"></a>01705           DBUS_SOCKET_SET_ERRNO ();
<a name="l01706"></a>01706           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01707"></a>01707                           <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01708"></a>01708                          <span class="stringliteral">&quot;Failed to open socket: %s&quot;</span>,
<a name="l01709"></a>01709                          <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01710"></a>01710           <span class="keywordflow">goto</span> failed;
<a name="l01711"></a>01711         }
<a name="l01712"></a>01712       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01713"></a>01713 
<a name="l01714"></a>01714       <span class="keywordflow">if</span> (bind (fd, (<span class="keyword">struct</span> sockaddr*) tmp-&gt;ai_addr, tmp-&gt;ai_addrlen) == SOCKET_ERROR)
<a name="l01715"></a>01715         {
<a name="l01716"></a>01716           DBUS_SOCKET_SET_ERRNO ();
<a name="l01717"></a>01717           closesocket (fd);
<a name="l01718"></a>01718           <span class="keywordflow">if</span> (errno == WSAEADDRINUSE)
<a name="l01719"></a>01719           {
<a name="l01720"></a>01720               <span class="comment">/* Calling this function with port=0 tries to</span>
<a name="l01721"></a>01721 <span class="comment">               * bind the same port twice, so we should</span>
<a name="l01722"></a>01722 <span class="comment">               * ignore the second bind.</span>
<a name="l01723"></a>01723 <span class="comment">               */</span>
<a name="l01724"></a>01724               tmp = tmp-&gt;ai_next;
<a name="l01725"></a>01725               <span class="keywordflow">continue</span>;
<a name="l01726"></a>01726           }
<a name="l01727"></a>01727           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01728"></a>01728                           <span class="stringliteral">&quot;Failed to bind socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01729"></a>01729                           host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01730"></a>01730           <span class="keywordflow">goto</span> failed;
<a name="l01731"></a>01731     }
<a name="l01732"></a>01732 
<a name="l01733"></a>01733       <span class="keywordflow">if</span> (listen (fd, 30 <span class="comment">/* backlog */</span>) == SOCKET_ERROR)
<a name="l01734"></a>01734         {
<a name="l01735"></a>01735           DBUS_SOCKET_SET_ERRNO ();
<a name="l01736"></a>01736           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01737"></a>01737                           <span class="stringliteral">&quot;Failed to listen on socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01738"></a>01738                           host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01739"></a>01739           closesocket (fd);
<a name="l01740"></a>01740           <span class="keywordflow">goto</span> failed;
<a name="l01741"></a>01741         }
<a name="l01742"></a>01742 
<a name="l01743"></a>01743       newlisten_fd = <a class="code" href="group__DBusMemory.html#ga2d505f2960ccf343042d363170b27f9c" title="Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_realloc</a>(listen_fd, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)*(nlisten_fd+1));
<a name="l01744"></a>01744       <span class="keywordflow">if</span> (!newlisten_fd)
<a name="l01745"></a>01745         {
<a name="l01746"></a>01746           closesocket (fd);
<a name="l01747"></a>01747           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>,
<a name="l01748"></a>01748                           <span class="stringliteral">&quot;Failed to allocate file handle array&quot;</span>);
<a name="l01749"></a>01749           <span class="keywordflow">goto</span> failed;
<a name="l01750"></a>01750         }
<a name="l01751"></a>01751       listen_fd = newlisten_fd;
<a name="l01752"></a>01752       listen_fd[nlisten_fd] = fd;
<a name="l01753"></a>01753       nlisten_fd++;
<a name="l01754"></a>01754 
<a name="l01755"></a>01755       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a>(retport))
<a name="l01756"></a>01756         {
<a name="l01757"></a>01757           <span class="comment">/* If the user didn&#39;t specify a port, or used 0, then</span>
<a name="l01758"></a>01758 <span class="comment">             the kernel chooses a port. After the first address</span>
<a name="l01759"></a>01759 <span class="comment">             is bound to, we need to force all remaining addresses</span>
<a name="l01760"></a>01760 <span class="comment">             to use the same port */</span>
<a name="l01761"></a>01761           <span class="keywordflow">if</span> (!port || !strcmp(port, <span class="stringliteral">&quot;0&quot;</span>))
<a name="l01762"></a>01762             {
<a name="l01763"></a>01763               mysockaddr_gen addr;
<a name="l01764"></a>01764               socklen_t addrlen = <span class="keyword">sizeof</span>(addr);
<a name="l01765"></a>01765               <span class="keywordtype">char</span> portbuf[10];
<a name="l01766"></a>01766 
<a name="l01767"></a>01767               <span class="keywordflow">if</span> (getsockname(fd, &amp;addr.Address, &amp;addrlen) == SOCKET_ERROR)
<a name="l01768"></a>01768                 {
<a name="l01769"></a>01769                   DBUS_SOCKET_SET_ERRNO ();
<a name="l01770"></a>01770                   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01771"></a>01771                                   <span class="stringliteral">&quot;Failed to resolve port \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01772"></a>01772                                   host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a>());
<a name="l01773"></a>01773                   <span class="keywordflow">goto</span> failed;
<a name="l01774"></a>01774                 }
<a name="l01775"></a>01775               <span class="keywordflow">if</span> (addr.AddressIn.sin_family = AF_INET)
<a name="l01776"></a>01776                   snprintf( portbuf, <span class="keyword">sizeof</span>( portbuf ) - 1, <span class="stringliteral">&quot;%d&quot;</span>, ntohs(addr.AddressIn.sin_port) );
<a name="l01777"></a>01777               <span class="keywordflow">else</span>
<a name="l01778"></a>01778                   snprintf( portbuf, <span class="keyword">sizeof</span>( portbuf ) - 1, <span class="stringliteral">&quot;%d&quot;</span>, ntohs(addr.AddressIn6.sin6_port) );
<a name="l01779"></a>01779               <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(retport, portbuf))
<a name="l01780"></a>01780                 {
<a name="l01781"></a>01781                   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01782"></a>01782                   <span class="keywordflow">goto</span> failed;
<a name="l01783"></a>01783                 }
<a name="l01784"></a>01784 
<a name="l01785"></a>01785               <span class="comment">/* Release current address list &amp; redo lookup */</span>
<a name="l01786"></a>01786               port = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(retport);
<a name="l01787"></a>01787               freeaddrinfo(ai);
<a name="l01788"></a>01788               <span class="keywordflow">goto</span> redo_lookup_with_port;
<a name="l01789"></a>01789             }
<a name="l01790"></a>01790           <span class="keywordflow">else</span>
<a name="l01791"></a>01791             {
<a name="l01792"></a>01792               <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(retport, port))
<a name="l01793"></a>01793                 {
<a name="l01794"></a>01794                     <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01795"></a>01795                     <span class="keywordflow">goto</span> failed;
<a name="l01796"></a>01796                 }
<a name="l01797"></a>01797             }
<a name="l01798"></a>01798         }
<a name="l01799"></a>01799   
<a name="l01800"></a>01800       tmp = tmp-&gt;ai_next;
<a name="l01801"></a>01801     }
<a name="l01802"></a>01802   freeaddrinfo(ai);
<a name="l01803"></a>01803   ai = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01804"></a>01804 
<a name="l01805"></a>01805   <span class="keywordflow">if</span> (!nlisten_fd)
<a name="l01806"></a>01806     {
<a name="l01807"></a>01807       _dbus_win_set_errno (WSAEADDRINUSE);
<a name="l01808"></a>01808       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01809"></a>01809                       <span class="stringliteral">&quot;Failed to bind socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01810"></a>01810                       host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01811"></a>01811       <span class="keywordflow">return</span> -1;
<a name="l01812"></a>01812     }
<a name="l01813"></a>01813 
<a name="l01814"></a>01814   sscanf(<a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(retport), <span class="stringliteral">&quot;%d&quot;</span>, &amp;port_num);
<a name="l01815"></a>01815 
<a name="l01816"></a>01816   <span class="keywordflow">for</span> (i = 0 ; i &lt; nlisten_fd ; i++)
<a name="l01817"></a>01817     {
<a name="l01818"></a>01818       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (listen_fd[i]);
<a name="l01819"></a>01819       <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (listen_fd[i], error))
<a name="l01820"></a>01820         {
<a name="l01821"></a>01821           <span class="keywordflow">goto</span> failed;
<a name="l01822"></a>01822         }
<a name="l01823"></a>01823     }
<a name="l01824"></a>01824 
<a name="l01825"></a>01825   *fds_p = listen_fd;
<a name="l01826"></a>01826 
<a name="l01827"></a>01827   <span class="keywordflow">return</span> nlisten_fd;
<a name="l01828"></a>01828 
<a name="l01829"></a>01829  failed:
<a name="l01830"></a>01830   <span class="keywordflow">if</span> (ai)
<a name="l01831"></a>01831     freeaddrinfo(ai);
<a name="l01832"></a>01832   <span class="keywordflow">for</span> (i = 0 ; i &lt; nlisten_fd ; i++)
<a name="l01833"></a>01833     closesocket (listen_fd[i]);
<a name="l01834"></a>01834   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a>(listen_fd);
<a name="l01835"></a>01835   <span class="keywordflow">return</span> -1;
<a name="l01836"></a>01836 }
<a name="l01837"></a>01837 
<a name="l01838"></a>01838 
<a name="l01846"></a>01846 <span class="keywordtype">int</span>
<a name="l01847"></a><a class="code" href="group__DBusSysdeps.html#ga687f4393a365474ec16f02e40c418cce">01847</a> <a class="code" href="group__DBusSysdeps.html#ga687f4393a365474ec16f02e40c418cce" title="Accepts a connection on a listening socket.">_dbus_accept</a>  (<span class="keywordtype">int</span> listen_fd)
<a name="l01848"></a>01848 {
<a name="l01849"></a>01849   <span class="keywordtype">int</span> client_fd;
<a name="l01850"></a>01850 
<a name="l01851"></a>01851  retry:
<a name="l01852"></a>01852   client_fd = accept (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01853"></a>01853 
<a name="l01854"></a>01854   <span class="keywordflow">if</span> (DBUS_SOCKET_IS_INVALID (client_fd))
<a name="l01855"></a>01855     {
<a name="l01856"></a>01856       DBUS_SOCKET_SET_ERRNO ();
<a name="l01857"></a>01857       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l01858"></a>01858         <span class="keywordflow">goto</span> retry;
<a name="l01859"></a>01859     }
<a name="l01860"></a>01860 
<a name="l01861"></a>01861   _dbus_verbose (<span class="stringliteral">&quot;client fd %d accepted\n&quot;</span>, client_fd);
<a name="l01862"></a>01862   
<a name="l01863"></a>01863   <span class="keywordflow">return</span> client_fd;
<a name="l01864"></a>01864 }
<a name="l01865"></a>01865 
<a name="l01866"></a>01866 
<a name="l01867"></a>01867 
<a name="l01868"></a>01868 
<a name="l01869"></a>01869 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01870"></a><a class="code" href="group__DBusSysdeps.html#ga6cc9916aa1dde4d44072ee85b5691b5b">01870</a> <a class="code" href="group__DBusSysdeps.html#ga6cc9916aa1dde4d44072ee85b5691b5b" title="Sends a single nul byte with our UNIX credentials as ancillary data.">_dbus_send_credentials_socket</a> (<span class="keywordtype">int</span>            handle,
<a name="l01871"></a>01871                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01872"></a>01872 {
<a name="l01873"></a>01873 <span class="comment">/* FIXME: for the session bus credentials shouldn&#39;t matter (?), but</span>
<a name="l01874"></a>01874 <span class="comment"> * for the system bus they are presumably essential. A rough outline</span>
<a name="l01875"></a>01875 <span class="comment"> * of a way to implement the credential transfer would be this:</span>
<a name="l01876"></a>01876 <span class="comment"> *</span>
<a name="l01877"></a>01877 <span class="comment"> * client waits to *read* a byte.</span>
<a name="l01878"></a>01878 <span class="comment"> *</span>
<a name="l01879"></a>01879 <span class="comment"> * server creates a named pipe with a random name, sends a byte</span>
<a name="l01880"></a>01880 <span class="comment"> * contining its length, and its name.</span>
<a name="l01881"></a>01881 <span class="comment"> *</span>
<a name="l01882"></a>01882 <span class="comment"> * client reads the name, connects to it (using Win32 API).</span>
<a name="l01883"></a>01883 <span class="comment"> *</span>
<a name="l01884"></a>01884 <span class="comment"> * server waits for connection to the named pipe, then calls</span>
<a name="l01885"></a>01885 <span class="comment"> * ImpersonateNamedPipeClient(), notes its now-current credentials,</span>
<a name="l01886"></a>01886 <span class="comment"> * calls RevertToSelf(), closes its handles to the named pipe, and</span>
<a name="l01887"></a>01887 <span class="comment"> * is done. (Maybe there is some other way to get the SID of a named</span>
<a name="l01888"></a>01888 <span class="comment"> * pipe client without having to use impersonation?)</span>
<a name="l01889"></a>01889 <span class="comment"> *</span>
<a name="l01890"></a>01890 <span class="comment"> * client closes its handles and is done.</span>
<a name="l01891"></a>01891 <span class="comment"> * </span>
<a name="l01892"></a>01892 <span class="comment"> * Ralf: Why not sending credentials over the given this connection ?</span>
<a name="l01893"></a>01893 <span class="comment"> * Using named pipes makes it impossible to be connected from a unix client.  </span>
<a name="l01894"></a>01894 <span class="comment"> *</span>
<a name="l01895"></a>01895 <span class="comment"> */</span>
<a name="l01896"></a>01896   <span class="keywordtype">int</span> bytes_written;
<a name="l01897"></a>01897   <a class="code" href="structDBusString.html">DBusString</a> buf; 
<a name="l01898"></a>01898 
<a name="l01899"></a>01899   <a class="code" href="group__DBusString.html#ga6792a5c1725faa9d635d95f7a3b5bfae" title="Initializes a constant string with a length.">_dbus_string_init_const_len</a> (&amp;buf, <span class="stringliteral">&quot;\0&quot;</span>, 1);
<a name="l01900"></a>01900 again:
<a name="l01901"></a>01901   bytes_written = <a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de" title="Like _dbus_write(), but only supports sockets and is thus available on Windows.">_dbus_write_socket</a> (handle, &amp;buf, 0, 1 );
<a name="l01902"></a>01902 
<a name="l01903"></a>01903   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l01904"></a>01904     <span class="keywordflow">goto</span> again;
<a name="l01905"></a>01905 
<a name="l01906"></a>01906   <span class="keywordflow">if</span> (bytes_written &lt; 0)
<a name="l01907"></a>01907     {
<a name="l01908"></a>01908       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01909"></a>01909                       <span class="stringliteral">&quot;Failed to write credentials byte: %s&quot;</span>,
<a name="l01910"></a>01910                      <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l01911"></a>01911       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01912"></a>01912     }
<a name="l01913"></a>01913   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bytes_written == 0)
<a name="l01914"></a>01914     {
<a name="l01915"></a>01915       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga445d7ad73da94c796ef441df2dcc3cc8" title="Something went wrong reading or writing to a socket, for example.">DBUS_ERROR_IO_ERROR</a>,
<a name="l01916"></a>01916                       <span class="stringliteral">&quot;wrote zero bytes writing credentials byte&quot;</span>);
<a name="l01917"></a>01917       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01918"></a>01918     }
<a name="l01919"></a>01919   <span class="keywordflow">else</span>
<a name="l01920"></a>01920     {
<a name="l01921"></a>01921       _dbus_assert (bytes_written == 1);
<a name="l01922"></a>01922       _dbus_verbose (<span class="stringliteral">&quot;wrote 1 zero byte, credential sending isn&#39;t implemented yet\n&quot;</span>);
<a name="l01923"></a>01923       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01924"></a>01924     }
<a name="l01925"></a>01925   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01926"></a>01926 }
<a name="l01927"></a>01927 
<a name="l01946"></a>01946 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01947"></a><a class="code" href="group__DBusSysdeps.html#ga9906c86bebb51358f0d8df6a42af30f6">01947</a> <a class="code" href="group__DBusSysdeps.html#ga9906c86bebb51358f0d8df6a42af30f6" title="Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if avai...">_dbus_read_credentials_socket</a>  (<span class="keywordtype">int</span>              handle,
<a name="l01948"></a>01948                                 <a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials,
<a name="l01949"></a>01949                                 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>       *error)
<a name="l01950"></a>01950 {
<a name="l01951"></a>01951   <span class="keywordtype">int</span> bytes_read = 0;
<a name="l01952"></a>01952   <a class="code" href="structDBusString.html">DBusString</a> buf;
<a name="l01953"></a>01953 
<a name="l01954"></a>01954   <span class="keywordtype">char</span> *sid = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01955"></a>01955   <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> pid;
<a name="l01956"></a>01956   <span class="keywordtype">int</span> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01957"></a>01957 
<a name="l01958"></a>01958   <span class="comment">// could fail due too OOM</span>
<a name="l01959"></a>01959   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;buf))
<a name="l01960"></a>01960     {
<a name="l01961"></a>01961       bytes_read = <a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530" title="Like _dbus_read(), but only works on sockets so is available on Windows.">_dbus_read_socket</a> (handle, &amp;buf, 1 );
<a name="l01962"></a>01962 
<a name="l01963"></a>01963       <span class="keywordflow">if</span> (bytes_read &gt; 0) 
<a name="l01964"></a>01964         _dbus_verbose (<span class="stringliteral">&quot;got one zero byte from server\n&quot;</span>);
<a name="l01965"></a>01965 
<a name="l01966"></a>01966       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;buf);
<a name="l01967"></a>01967     }
<a name="l01968"></a>01968 
<a name="l01969"></a>01969   pid = _dbus_get_peer_pid_from_tcp_handle (handle);
<a name="l01970"></a>01970   <span class="keywordflow">if</span> (pid == 0)
<a name="l01971"></a>01971     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01972"></a>01972 
<a name="l01973"></a>01973   <a class="code" href="group__DBusCredentials.html#gaad133a8d06af2a447307266a8425a9f8" title="Add a UNIX process ID to the credentials.">_dbus_credentials_add_pid</a> (credentials, pid);
<a name="l01974"></a>01974 
<a name="l01975"></a>01975   <span class="keywordflow">if</span> (_dbus_getsid (&amp;sid, pid))
<a name="l01976"></a>01976     {
<a name="l01977"></a>01977       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#ga9d2186a4cfa8a421c552ae4592b400f5" title="Add a Windows user SID to the credentials.">_dbus_credentials_add_windows_sid</a> (credentials, sid))
<a name="l01978"></a>01978         <span class="keywordflow">goto</span> out;
<a name="l01979"></a>01979     }
<a name="l01980"></a>01980 
<a name="l01981"></a>01981   retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01982"></a>01982 
<a name="l01983"></a>01983 out:
<a name="l01984"></a>01984   <span class="keywordflow">if</span> (sid)
<a name="l01985"></a>01985     LocalFree (sid);
<a name="l01986"></a>01986 
<a name="l01987"></a>01987   <span class="keywordflow">return</span> retval;
<a name="l01988"></a>01988 }
<a name="l01989"></a>01989 
<a name="l01998"></a>01998 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01999"></a><a class="code" href="group__DBusSysdeps.html#ga8e16f75e361d9fed43223f69baf0e2a5">01999</a> <a class="code" href="group__DBusSysdeps.html#ga8e16f75e361d9fed43223f69baf0e2a5" title="Checks to make sure the given directory is private to the user.">_dbus_check_dir_is_private_to_user</a> (<a class="code" href="structDBusString.html">DBusString</a> *dir, <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l02000"></a>02000 {
<a name="l02001"></a>02001   <span class="comment">/* TODO */</span>
<a name="l02002"></a>02002   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02003"></a>02003   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02004"></a>02004 }
<a name="l02005"></a>02005 
<a name="l02006"></a>02006 
<a name="l02017"></a>02017 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02018"></a><a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d">02018</a> <a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d" title="Appends the given filename to the given directory.">_dbus_concat_dir_and_file</a> (<a class="code" href="structDBusString.html">DBusString</a>       *dir,
<a name="l02019"></a>02019                            <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *next_component)
<a name="l02020"></a>02020 {
<a name="l02021"></a>02021   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> dir_ends_in_slash;
<a name="l02022"></a>02022   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> file_starts_with_slash;
<a name="l02023"></a>02023 
<a name="l02024"></a>02024   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir) == 0 ||
<a name="l02025"></a>02025       <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (next_component) == 0)
<a name="l02026"></a>02026     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02027"></a>02027 
<a name="l02028"></a>02028   dir_ends_in_slash =
<a name="l02029"></a>02029     (<span class="charliteral">&#39;/&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (dir, <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir) - 1) ||
<a name="l02030"></a>02030      <span class="charliteral">&#39;\\&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (dir, <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir) - 1));
<a name="l02031"></a>02031 
<a name="l02032"></a>02032   file_starts_with_slash =
<a name="l02033"></a>02033     (<span class="charliteral">&#39;/&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (next_component, 0) ||
<a name="l02034"></a>02034      <span class="charliteral">&#39;\\&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (next_component, 0));
<a name="l02035"></a>02035 
<a name="l02036"></a>02036   <span class="keywordflow">if</span> (dir_ends_in_slash &amp;&amp; file_starts_with_slash)
<a name="l02037"></a>02037     {
<a name="l02038"></a>02038       <a class="code" href="group__DBusString.html#ga7af1cbfa905f26d972ab644d890548b8" title="Makes a string shorter by the given number of bytes.">_dbus_string_shorten</a> (dir, 1);
<a name="l02039"></a>02039     }
<a name="l02040"></a>02040   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!(dir_ends_in_slash || file_starts_with_slash))
<a name="l02041"></a>02041     {
<a name="l02042"></a>02042       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#gaa6ecf36e70263659f921a4ef0335db12" title="Appends a single byte to the string, returning FALSE if not enough memory.">_dbus_string_append_byte</a> (dir, <span class="charliteral">&#39;\\&#39;</span>))
<a name="l02043"></a>02043         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02044"></a>02044     }
<a name="l02045"></a>02045 
<a name="l02046"></a>02046   <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#ga3c10f0d1bcaa3b450025b9c6a8b901d7" title="Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...">_dbus_string_copy</a> (next_component, 0, dir,
<a name="l02047"></a>02047                             <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir));
<a name="l02048"></a>02048 }
<a name="l02049"></a>02049 
<a name="l02050"></a>02050 <span class="comment">/*---------------- DBusCredentials ----------------------------------*/</span>
<a name="l02051"></a>02051 
<a name="l02059"></a>02059 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02060"></a><a class="code" href="group__DBusSysdeps.html#gacecdbb00a3c8b63e821edae537ae3c7b">02060</a> <a class="code" href="group__DBusSysdeps.html#gacecdbb00a3c8b63e821edae537ae3c7b" title="Adds the credentials corresponding to the given username.">_dbus_credentials_add_from_user</a> (<a class="code" href="structDBusCredentials.html">DBusCredentials</a>  *credentials,
<a name="l02061"></a>02061                                      <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *username)
<a name="l02062"></a>02062 {
<a name="l02063"></a>02063   <span class="keywordflow">return</span> <a class="code" href="group__DBusCredentials.html#ga9d2186a4cfa8a421c552ae4592b400f5" title="Add a Windows user SID to the credentials.">_dbus_credentials_add_windows_sid</a> (credentials,
<a name="l02064"></a>02064                     <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(username));
<a name="l02065"></a>02065 }
<a name="l02066"></a>02066 
<a name="l02075"></a>02075 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02076"></a><a class="code" href="group__DBusSysdeps.html#ga9d5493f8bd1c5577060c8c6dce44d09f">02076</a> <a class="code" href="group__DBusSysdeps.html#ga9d5493f8bd1c5577060c8c6dce44d09f" title="Adds the credentials of the current process to the passed-in credentials object.">_dbus_credentials_add_from_current_process</a> (<a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials)
<a name="l02077"></a>02077 {
<a name="l02078"></a>02078   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02079"></a>02079   <span class="keywordtype">char</span> *sid = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02080"></a>02080 
<a name="l02081"></a>02081   <span class="keywordflow">if</span> (!_dbus_getsid(&amp;sid, <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a>()))
<a name="l02082"></a>02082     <span class="keywordflow">goto</span> failed;
<a name="l02083"></a>02083 
<a name="l02084"></a>02084   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#gaad133a8d06af2a447307266a8425a9f8" title="Add a UNIX process ID to the credentials.">_dbus_credentials_add_pid</a> (credentials, <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a>()))
<a name="l02085"></a>02085     <span class="keywordflow">goto</span> failed;
<a name="l02086"></a>02086 
<a name="l02087"></a>02087   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#ga9d2186a4cfa8a421c552ae4592b400f5" title="Add a Windows user SID to the credentials.">_dbus_credentials_add_windows_sid</a> (credentials,sid))
<a name="l02088"></a>02088     <span class="keywordflow">goto</span> failed;
<a name="l02089"></a>02089 
<a name="l02090"></a>02090   retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02091"></a>02091   <span class="keywordflow">goto</span> end;
<a name="l02092"></a>02092 failed:
<a name="l02093"></a>02093   retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02094"></a>02094 end:
<a name="l02095"></a>02095   <span class="keywordflow">if</span> (sid)
<a name="l02096"></a>02096     LocalFree(sid);
<a name="l02097"></a>02097 
<a name="l02098"></a>02098   <span class="keywordflow">return</span> retval;
<a name="l02099"></a>02099 }
<a name="l02100"></a>02100 
<a name="l02113"></a>02113 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02114"></a><a class="code" href="group__DBusSysdeps.html#ga095c54de3974c6d04c29ef86c6e06e35">02114</a> <a class="code" href="group__DBusSysdeps.html#ga095c54de3974c6d04c29ef86c6e06e35" title="Append to the string the identity we would like to have when we authenticate, on UNIX this is the cur...">_dbus_append_user_from_current_process</a> (<a class="code" href="structDBusString.html">DBusString</a> *str)
<a name="l02115"></a>02115 {
<a name="l02116"></a>02116   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02117"></a>02117   <span class="keywordtype">char</span> *sid = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02118"></a>02118 
<a name="l02119"></a>02119   <span class="keywordflow">if</span> (!_dbus_getsid(&amp;sid, <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a>()))
<a name="l02120"></a>02120     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02121"></a>02121 
<a name="l02122"></a>02122   retval = <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (str,sid);
<a name="l02123"></a>02123 
<a name="l02124"></a>02124   LocalFree(sid);
<a name="l02125"></a>02125   <span class="keywordflow">return</span> retval;
<a name="l02126"></a>02126 }
<a name="l02127"></a>02127 
<a name="l02132"></a>02132 <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>
<a name="l02133"></a><a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147">02133</a> <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a> (<span class="keywordtype">void</span>)
<a name="l02134"></a>02134 {
<a name="l02135"></a>02135   <span class="keywordflow">return</span> GetCurrentProcessId ();
<a name="l02136"></a>02136 }
<a name="l02137"></a>02137 
<a name="l02139"></a>02139 <span class="preprocessor">#define NANOSECONDS_PER_SECOND       1000000000</span>
<a name="l02140"></a>02140 <span class="preprocessor"></span>
<a name="l02141"></a>02141 <span class="preprocessor">#define MICROSECONDS_PER_SECOND      1000000</span>
<a name="l02142"></a>02142 <span class="preprocessor"></span>
<a name="l02143"></a>02143 <span class="preprocessor">#define MILLISECONDS_PER_SECOND      1000</span>
<a name="l02144"></a>02144 <span class="preprocessor"></span>
<a name="l02145"></a>02145 <span class="preprocessor">#define NANOSECONDS_PER_MILLISECOND  1000000</span>
<a name="l02146"></a>02146 <span class="preprocessor"></span>
<a name="l02147"></a>02147 <span class="preprocessor">#define MICROSECONDS_PER_MILLISECOND 1000</span>
<a name="l02148"></a>02148 <span class="preprocessor"></span>
<a name="l02153"></a>02153 <span class="keywordtype">void</span>
<a name="l02154"></a><a class="code" href="group__DBusSysdeps.html#ga1153b4669819148af6b3f6f2b7c9183a">02154</a> <a class="code" href="group__DBusSysdeps.html#ga1153b4669819148af6b3f6f2b7c9183a" title="Sleeps the given number of milliseconds.">_dbus_sleep_milliseconds</a> (<span class="keywordtype">int</span> milliseconds)
<a name="l02155"></a>02155 {
<a name="l02156"></a>02156   Sleep (milliseconds);
<a name="l02157"></a>02157 }
<a name="l02158"></a>02158 
<a name="l02159"></a>02159 
<a name="l02167"></a>02167 <span class="keywordtype">void</span>
<a name="l02168"></a><a class="code" href="group__DBusSysdeps.html#gae10ee21ab353beadbe2493728065f600">02168</a> <a class="code" href="group__DBusSysdeps.html#gae10ee21ab353beadbe2493728065f600" title="Get current time, as in gettimeofday().">_dbus_get_real_time</a> (<span class="keywordtype">long</span> *tv_sec,
<a name="l02169"></a>02169                      <span class="keywordtype">long</span> *tv_usec)
<a name="l02170"></a>02170 {
<a name="l02171"></a>02171   FILETIME ft;
<a name="l02172"></a>02172   <a class="code" href="group__DBusTypes.html#ga0a7c275002dbafa34536a76db079a950" title="A 64-bit unsigned integer.">dbus_uint64_t</a> time64;
<a name="l02173"></a>02173 
<a name="l02174"></a>02174   GetSystemTimeAsFileTime (&amp;ft);
<a name="l02175"></a>02175 
<a name="l02176"></a>02176   memcpy (&amp;time64, &amp;ft, <span class="keyword">sizeof</span> (time64));
<a name="l02177"></a>02177 
<a name="l02178"></a>02178   <span class="comment">/* Convert from 100s of nanoseconds since 1601-01-01</span>
<a name="l02179"></a>02179 <span class="comment">  * to Unix epoch. Yes, this is Y2038 unsafe.</span>
<a name="l02180"></a>02180 <span class="comment">  */</span>
<a name="l02181"></a>02181   time64 -= <a class="code" href="group__DBusTypes.html#ga8deac39e1bf9fcca44854afeaaaf6199" title="Declare a 64-bit signed integer constant.">DBUS_INT64_CONSTANT</a> (116444736000000000);
<a name="l02182"></a>02182   time64 /= 10;
<a name="l02183"></a>02183 
<a name="l02184"></a>02184   <span class="keywordflow">if</span> (tv_sec)
<a name="l02185"></a>02185     *tv_sec = time64 / 1000000;
<a name="l02186"></a>02186 
<a name="l02187"></a>02187   <span class="keywordflow">if</span> (tv_usec)
<a name="l02188"></a>02188     *tv_usec = time64 % 1000000;
<a name="l02189"></a>02189 }
<a name="l02190"></a>02190 
<a name="l02198"></a>02198 <span class="keywordtype">void</span>
<a name="l02199"></a><a class="code" href="group__DBusSysdeps.html#gab9951a7fd8c33188bf86314e7fd56300">02199</a> <a class="code" href="group__DBusSysdeps.html#gab9951a7fd8c33188bf86314e7fd56300" title="Get current time, as in gettimeofday().">_dbus_get_monotonic_time</a> (<span class="keywordtype">long</span> *tv_sec,
<a name="l02200"></a>02200                           <span class="keywordtype">long</span> *tv_usec)
<a name="l02201"></a>02201 {
<a name="l02202"></a>02202   <span class="comment">/* no implementation yet, fall back to wall-clock time */</span>
<a name="l02203"></a>02203   <a class="code" href="group__DBusSysdeps.html#gae10ee21ab353beadbe2493728065f600" title="Get current time, as in gettimeofday().">_dbus_get_real_time</a> (tv_sec, tv_usec);
<a name="l02204"></a>02204 }
<a name="l02205"></a>02205 
<a name="l02209"></a>02209 <span class="keywordtype">void</span>
<a name="l02210"></a><a class="code" href="group__DBusSysdeps.html#ga6890d4cde3afec0bf274ca2af8c9e204">02210</a> <a class="code" href="group__DBusSysdeps.html#ga6890d4cde3afec0bf274ca2af8c9e204" title="signal (SIGPIPE, SIG_IGN);">_dbus_disable_sigpipe</a> (<span class="keywordtype">void</span>)
<a name="l02211"></a>02211 {
<a name="l02212"></a>02212 }
<a name="l02213"></a>02213 
<a name="l02222"></a>02222 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02223"></a><a class="code" href="group__DBusSysdeps.html#gaa47156dedbe573ee9b213d1fd3f7bb79">02223</a> <a class="code" href="group__DBusSysdeps.html#gaa47156dedbe573ee9b213d1fd3f7bb79" title="Creates a directory; succeeds if the directory is created or already existed.">_dbus_create_directory</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l02224"></a>02224                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l02225"></a>02225 {
<a name="l02226"></a>02226   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l02227"></a>02227 
<a name="l02228"></a>02228   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02229"></a>02229 
<a name="l02230"></a>02230   filename_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (filename);
<a name="l02231"></a>02231 
<a name="l02232"></a>02232   <span class="keywordflow">if</span> (!CreateDirectoryA (filename_c, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l02233"></a>02233     {
<a name="l02234"></a>02234       <span class="keywordflow">if</span> (GetLastError () == ERROR_ALREADY_EXISTS)
<a name="l02235"></a>02235         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02236"></a>02236 
<a name="l02237"></a>02237       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l02238"></a>02238                       <span class="stringliteral">&quot;Failed to create directory %s: %s\n&quot;</span>,
<a name="l02239"></a>02239                       filename_c, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l02240"></a>02240       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02241"></a>02241     }
<a name="l02242"></a>02242   <span class="keywordflow">else</span>
<a name="l02243"></a>02243     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02244"></a>02244 }
<a name="l02245"></a>02245 
<a name="l02246"></a>02246 
<a name="l02255"></a>02255 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02256"></a><a class="code" href="group__DBusSysdeps.html#gac9fd08af5e54c0e9b3db108b48a65778">02256</a> <a class="code" href="group__DBusSysdeps.html#gac9fd08af5e54c0e9b3db108b48a65778" title="Generates the given number of random bytes, using the best mechanism we can come up with...">_dbus_generate_random_bytes</a> (<a class="code" href="structDBusString.html">DBusString</a> *str,
<a name="l02257"></a>02257                              <span class="keywordtype">int</span>         n_bytes)
<a name="l02258"></a>02258 {
<a name="l02259"></a>02259   <span class="keywordtype">int</span> old_len;
<a name="l02260"></a>02260   <span class="keywordtype">char</span> *p;
<a name="l02261"></a>02261   HCRYPTPROV hprov;
<a name="l02262"></a>02262 
<a name="l02263"></a>02263   old_len = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (str);
<a name="l02264"></a>02264 
<a name="l02265"></a>02265   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga8f13997d90ceed2f437706e6b7804d9b" title="Makes a string longer by the given number of bytes.">_dbus_string_lengthen</a> (str, n_bytes))
<a name="l02266"></a>02266     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02267"></a>02267 
<a name="l02268"></a>02268   p = <a class="code" href="group__DBusString.html#ga7a73fb373398606e6e1d0a86c4587a3c" title="Gets a sub-portion of the raw character buffer from the string.">_dbus_string_get_data_len</a> (str, old_len, n_bytes);
<a name="l02269"></a>02269 
<a name="l02270"></a>02270   <span class="keywordflow">if</span> (!CryptAcquireContext (&amp;hprov, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
<a name="l02271"></a>02271     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02272"></a>02272 
<a name="l02273"></a>02273   <span class="keywordflow">if</span> (!CryptGenRandom (hprov, n_bytes, p))
<a name="l02274"></a>02274     {
<a name="l02275"></a>02275       CryptReleaseContext (hprov, 0);
<a name="l02276"></a>02276       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02277"></a>02277     }
<a name="l02278"></a>02278 
<a name="l02279"></a>02279   CryptReleaseContext (hprov, 0);
<a name="l02280"></a>02280 
<a name="l02281"></a>02281   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02282"></a>02282 }
<a name="l02283"></a>02283 
<a name="l02290"></a>02290 <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l02291"></a><a class="code" href="group__DBusSysdeps.html#ga3ecdae905f2d9e95fd35891b20f06532">02291</a> <a class="code" href="group__DBusSysdeps.html#ga3ecdae905f2d9e95fd35891b20f06532" title="Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.">_dbus_get_tmpdir</a>(<span class="keywordtype">void</span>)
<a name="l02292"></a>02292 {
<a name="l02293"></a>02293   <span class="comment">/* Protected by _DBUS_LOCK_sysdeps */</span>
<a name="l02294"></a>02294   <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* tmpdir = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02295"></a>02295   <span class="keyword">static</span> <span class="keywordtype">char</span> buf[1000];
<a name="l02296"></a>02296 
<a name="l02297"></a>02297   <span class="keywordflow">if</span> (!_DBUS_LOCK (sysdeps))
<a name="l02298"></a>02298     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02299"></a>02299 
<a name="l02300"></a>02300   <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02301"></a>02301     {
<a name="l02302"></a>02302       <span class="keywordtype">char</span> *last_slash;
<a name="l02303"></a>02303 
<a name="l02304"></a>02304       <span class="keywordflow">if</span> (!GetTempPathA (<span class="keyword">sizeof</span> (buf), buf))
<a name="l02305"></a>02305         {
<a name="l02306"></a>02306           <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;GetTempPath failed\n&quot;</span>);
<a name="l02307"></a>02307           <a class="code" href="group__DBusSysdeps.html#ga83c51771d3c4e612522bd5ad72e6ad7a" title="Aborts the program with SIGABRT (dumping core).">_dbus_abort</a> ();
<a name="l02308"></a>02308         }
<a name="l02309"></a>02309 
<a name="l02310"></a>02310       <span class="comment">/* Drop terminating backslash or slash */</span>
<a name="l02311"></a>02311       last_slash = _mbsrchr (buf, <span class="charliteral">&#39;\\&#39;</span>);
<a name="l02312"></a>02312       <span class="keywordflow">if</span> (last_slash &gt; buf &amp;&amp; last_slash[1] == <span class="charliteral">&#39;\0&#39;</span>)
<a name="l02313"></a>02313         last_slash[0] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l02314"></a>02314       last_slash = _mbsrchr (buf, <span class="charliteral">&#39;/&#39;</span>);
<a name="l02315"></a>02315       <span class="keywordflow">if</span> (last_slash &gt; buf &amp;&amp; last_slash[1] == <span class="charliteral">&#39;\0&#39;</span>)
<a name="l02316"></a>02316         last_slash[0] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l02317"></a>02317 
<a name="l02318"></a>02318       tmpdir = buf;
<a name="l02319"></a>02319     }
<a name="l02320"></a>02320 
<a name="l02321"></a>02321   _DBUS_UNLOCK (sysdeps);
<a name="l02322"></a>02322 
<a name="l02323"></a>02323   _dbus_assert(tmpdir != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02324"></a>02324 
<a name="l02325"></a>02325   <span class="keywordflow">return</span> tmpdir;
<a name="l02326"></a>02326 }
<a name="l02327"></a>02327 
<a name="l02328"></a>02328 
<a name="l02337"></a>02337 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02338"></a><a class="code" href="group__DBusFile.html#ga4d4936493cddac47b6e7e4ab3f390627">02338</a> <a class="code" href="group__DBusFile.html#ga4d4936493cddac47b6e7e4ab3f390627" title="Deletes the given file.">_dbus_delete_file</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l02339"></a>02339                    <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l02340"></a>02340 {
<a name="l02341"></a>02341   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l02342"></a>02342 
<a name="l02343"></a>02343   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02344"></a>02344 
<a name="l02345"></a>02345   filename_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (filename);
<a name="l02346"></a>02346 
<a name="l02347"></a>02347   <span class="keywordflow">if</span> (DeleteFileA (filename_c) == 0)
<a name="l02348"></a>02348     {
<a name="l02349"></a>02349       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l02350"></a>02350                       <span class="stringliteral">&quot;Failed to delete file %s: %s\n&quot;</span>,
<a name="l02351"></a>02351                       filename_c, <a class="code" href="group__DBusInternalsUtils.html#ga56de84795d6df4162ad79b3be7af7588" title="Get error message from errno.">_dbus_strerror_from_errno</a> ());
<a name="l02352"></a>02352       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02353"></a>02353     }
<a name="l02354"></a>02354   <span class="keywordflow">else</span>
<a name="l02355"></a>02355     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02356"></a>02356 }
<a name="l02357"></a>02357 
<a name="l02358"></a>02358 <span class="preprocessor">#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_ENABLE_EMBEDDED_TESTS)</span>
<a name="l02359"></a>02359 <span class="preprocessor"></span>
<a name="l02360"></a>02360 <span class="preprocessor">#if defined(_MSC_VER) || defined(DBUS_WINCE)</span>
<a name="l02361"></a>02361 <span class="preprocessor"></span><span class="preprocessor"># ifdef BACKTRACES</span>
<a name="l02362"></a>02362 <span class="preprocessor"></span><span class="preprocessor">#  undef BACKTRACES</span>
<a name="l02363"></a>02363 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
<a name="l02364"></a>02364 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l02365"></a>02365 <span class="preprocessor"></span><span class="preprocessor"># define BACKTRACES</span>
<a name="l02366"></a>02366 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l02367"></a>02367 <span class="preprocessor"></span>
<a name="l02368"></a>02368 <span class="preprocessor">#ifdef BACKTRACES</span>
<a name="l02369"></a>02369 <span class="preprocessor"></span><span class="comment">/*</span>
<a name="l02370"></a>02370 <span class="comment"> * Backtrace Generator</span>
<a name="l02371"></a>02371 <span class="comment"> *</span>
<a name="l02372"></a>02372 <span class="comment"> * Copyright 2004 Eric Poech</span>
<a name="l02373"></a>02373 <span class="comment"> * Copyright 2004 Robert Shearman</span>
<a name="l02374"></a>02374 <span class="comment"> *</span>
<a name="l02375"></a>02375 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l02376"></a>02376 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l02377"></a>02377 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l02378"></a>02378 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l02379"></a>02379 <span class="comment"> *</span>
<a name="l02380"></a>02380 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l02381"></a>02381 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l02382"></a>02382 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l02383"></a>02383 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l02384"></a>02384 <span class="comment"> *</span>
<a name="l02385"></a>02385 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l02386"></a>02386 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l02387"></a>02387 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l02388"></a>02388 <span class="comment"> */</span>
<a name="l02389"></a>02389 
<a name="l02390"></a>02390 <span class="preprocessor">#include &lt;winver.h&gt;</span>
<a name="l02391"></a>02391 <span class="preprocessor">#include &lt;imagehlp.h&gt;</span>
<a name="l02392"></a>02392 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l02393"></a>02393 
<a name="l02394"></a>02394 <span class="preprocessor">#define DPRINTF _dbus_warn</span>
<a name="l02395"></a>02395 <span class="preprocessor"></span>
<a name="l02396"></a>02396 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l02397"></a>02397 <span class="preprocessor"></span><span class="preprocessor">#define BOOL int</span>
<a name="l02398"></a>02398 <span class="preprocessor"></span>
<a name="l02399"></a>02399 <span class="preprocessor">#define __i386__</span>
<a name="l02400"></a>02400 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l02401"></a>02401 <span class="preprocessor"></span>
<a name="l02402"></a>02402 <span class="comment">//#define MAKE_FUNCPTR(f) static typeof(f) * p##f</span>
<a name="l02403"></a>02403 
<a name="l02404"></a>02404 <span class="comment">//MAKE_FUNCPTR(StackWalk);</span>
<a name="l02405"></a>02405 <span class="comment">//MAKE_FUNCPTR(SymGetModuleBase);</span>
<a name="l02406"></a>02406 <span class="comment">//MAKE_FUNCPTR(SymFunctionTableAccess);</span>
<a name="l02407"></a>02407 <span class="comment">//MAKE_FUNCPTR(SymInitialize);</span>
<a name="l02408"></a>02408 <span class="comment">//MAKE_FUNCPTR(SymGetSymFromAddr);</span>
<a name="l02409"></a>02409 <span class="comment">//MAKE_FUNCPTR(SymGetModuleInfo);</span>
<a name="l02410"></a>02410 <span class="keyword">static</span> BOOL (WINAPI *pStackWalk)(
<a name="l02411"></a>02411   DWORD MachineType,
<a name="l02412"></a>02412   HANDLE hProcess,
<a name="l02413"></a>02413   HANDLE hThread,
<a name="l02414"></a>02414   LPSTACKFRAME StackFrame,
<a name="l02415"></a>02415   PVOID ContextRecord,
<a name="l02416"></a>02416   PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
<a name="l02417"></a>02417   PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
<a name="l02418"></a>02418   PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
<a name="l02419"></a>02419   PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
<a name="l02420"></a>02420 );
<a name="l02421"></a>02421 <span class="preprocessor">#ifdef _WIN64</span>
<a name="l02422"></a>02422 <span class="preprocessor"></span><span class="keyword">static</span> DWORD64 (WINAPI *pSymGetModuleBase)(
<a name="l02423"></a>02423   HANDLE hProcess,
<a name="l02424"></a>02424   DWORD64 dwAddr
<a name="l02425"></a>02425 );
<a name="l02426"></a>02426 <span class="keyword">static</span> PVOID  (WINAPI *pSymFunctionTableAccess)(
<a name="l02427"></a>02427   HANDLE hProcess,
<a name="l02428"></a>02428   DWORD64 AddrBase
<a name="l02429"></a>02429 );
<a name="l02430"></a>02430 <span class="preprocessor">#else</span>
<a name="l02431"></a>02431 <span class="preprocessor"></span><span class="keyword">static</span> DWORD (WINAPI *pSymGetModuleBase)(
<a name="l02432"></a>02432   HANDLE hProcess,
<a name="l02433"></a>02433   DWORD dwAddr
<a name="l02434"></a>02434 );
<a name="l02435"></a>02435 <span class="keyword">static</span> PVOID  (WINAPI *pSymFunctionTableAccess)(
<a name="l02436"></a>02436   HANDLE hProcess,
<a name="l02437"></a>02437   DWORD AddrBase
<a name="l02438"></a>02438 );
<a name="l02439"></a>02439 <span class="preprocessor">#endif</span>
<a name="l02440"></a>02440 <span class="preprocessor"></span><span class="keyword">static</span> BOOL  (WINAPI *pSymInitialize)(
<a name="l02441"></a>02441   HANDLE hProcess,
<a name="l02442"></a>02442   PSTR UserSearchPath,
<a name="l02443"></a>02443   BOOL fInvadeProcess
<a name="l02444"></a>02444 );
<a name="l02445"></a>02445 <span class="keyword">static</span> BOOL  (WINAPI *pSymGetSymFromAddr)(
<a name="l02446"></a>02446   HANDLE hProcess,
<a name="l02447"></a>02447   DWORD Address,
<a name="l02448"></a>02448   PDWORD Displacement,
<a name="l02449"></a>02449   PIMAGEHLP_SYMBOL Symbol
<a name="l02450"></a>02450 );
<a name="l02451"></a>02451 <span class="keyword">static</span> BOOL  (WINAPI *pSymGetModuleInfo)(
<a name="l02452"></a>02452   HANDLE hProcess,
<a name="l02453"></a>02453   DWORD dwAddr,
<a name="l02454"></a>02454   PIMAGEHLP_MODULE ModuleInfo
<a name="l02455"></a>02455 );
<a name="l02456"></a>02456 <span class="keyword">static</span> DWORD  (WINAPI *pSymSetOptions)(
<a name="l02457"></a>02457   DWORD SymOptions
<a name="l02458"></a>02458 );
<a name="l02459"></a>02459 
<a name="l02460"></a>02460 
<a name="l02461"></a>02461 <span class="keyword">static</span> BOOL init_backtrace()
<a name="l02462"></a>02462 {
<a name="l02463"></a>02463     HMODULE hmodDbgHelp = LoadLibraryA(<span class="stringliteral">&quot;dbghelp&quot;</span>);
<a name="l02464"></a>02464 <span class="comment">/*</span>
<a name="l02465"></a>02465 <span class="comment">    #define GETFUNC(x) \</span>
<a name="l02466"></a>02466 <span class="comment">    p##x = (typeof(x)*)GetProcAddress(hmodDbgHelp, #x); \</span>
<a name="l02467"></a>02467 <span class="comment">    if (!p##x) \</span>
<a name="l02468"></a>02468 <span class="comment">    { \</span>
<a name="l02469"></a>02469 <span class="comment">        return FALSE; \</span>
<a name="l02470"></a>02470 <span class="comment">    }</span>
<a name="l02471"></a>02471 <span class="comment">    */</span>
<a name="l02472"></a>02472 
<a name="l02473"></a>02473 
<a name="l02474"></a>02474 <span class="comment">//    GETFUNC(StackWalk);</span>
<a name="l02475"></a>02475 <span class="comment">//    GETFUNC(SymGetModuleBase);</span>
<a name="l02476"></a>02476 <span class="comment">//    GETFUNC(SymFunctionTableAccess);</span>
<a name="l02477"></a>02477 <span class="comment">//    GETFUNC(SymInitialize);</span>
<a name="l02478"></a>02478 <span class="comment">//    GETFUNC(SymGetSymFromAddr);</span>
<a name="l02479"></a>02479 <span class="comment">//    GETFUNC(SymGetModuleInfo);</span>
<a name="l02480"></a>02480 
<a name="l02481"></a>02481 <span class="preprocessor">#define FUNC(x) #x</span>
<a name="l02482"></a>02482 <span class="preprocessor"></span>
<a name="l02483"></a>02483       pStackWalk = (BOOL  (WINAPI *)(
<a name="l02484"></a>02484 DWORD MachineType,
<a name="l02485"></a>02485 HANDLE hProcess,
<a name="l02486"></a>02486 HANDLE hThread,
<a name="l02487"></a>02487 LPSTACKFRAME StackFrame,
<a name="l02488"></a>02488 PVOID ContextRecord,
<a name="l02489"></a>02489 PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
<a name="l02490"></a>02490 PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
<a name="l02491"></a>02491 PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
<a name="l02492"></a>02492 PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
<a name="l02493"></a>02493 ))GetProcAddress (hmodDbgHelp, FUNC(StackWalk));
<a name="l02494"></a>02494 <span class="preprocessor">#ifdef _WIN64</span>
<a name="l02495"></a>02495 <span class="preprocessor"></span>    pSymGetModuleBase=(DWORD64  (WINAPI *)(
<a name="l02496"></a>02496   HANDLE hProcess,
<a name="l02497"></a>02497   DWORD64 dwAddr
<a name="l02498"></a>02498 ))GetProcAddress (hmodDbgHelp, FUNC(SymGetModuleBase));
<a name="l02499"></a>02499     pSymFunctionTableAccess=(PVOID  (WINAPI *)(
<a name="l02500"></a>02500   HANDLE hProcess,
<a name="l02501"></a>02501   DWORD64 AddrBase
<a name="l02502"></a>02502 ))GetProcAddress (hmodDbgHelp, FUNC(SymFunctionTableAccess));
<a name="l02503"></a>02503 <span class="preprocessor">#else</span>
<a name="l02504"></a>02504 <span class="preprocessor"></span>    pSymGetModuleBase=(DWORD  (WINAPI *)(
<a name="l02505"></a>02505   HANDLE hProcess,
<a name="l02506"></a>02506   DWORD dwAddr
<a name="l02507"></a>02507 ))GetProcAddress (hmodDbgHelp, FUNC(SymGetModuleBase));
<a name="l02508"></a>02508     pSymFunctionTableAccess=(PVOID  (WINAPI *)(
<a name="l02509"></a>02509   HANDLE hProcess,
<a name="l02510"></a>02510   DWORD AddrBase
<a name="l02511"></a>02511 ))GetProcAddress (hmodDbgHelp, FUNC(SymFunctionTableAccess));
<a name="l02512"></a>02512 <span class="preprocessor">#endif</span>
<a name="l02513"></a>02513 <span class="preprocessor"></span>    pSymInitialize = (BOOL  (WINAPI *)(
<a name="l02514"></a>02514   HANDLE hProcess,
<a name="l02515"></a>02515   PSTR UserSearchPath,
<a name="l02516"></a>02516   BOOL fInvadeProcess
<a name="l02517"></a>02517 ))GetProcAddress (hmodDbgHelp, FUNC(SymInitialize));
<a name="l02518"></a>02518     pSymGetSymFromAddr = (BOOL  (WINAPI *)(
<a name="l02519"></a>02519   HANDLE hProcess,
<a name="l02520"></a>02520   DWORD Address,
<a name="l02521"></a>02521   PDWORD Displacement,
<a name="l02522"></a>02522   PIMAGEHLP_SYMBOL Symbol
<a name="l02523"></a>02523 ))GetProcAddress (hmodDbgHelp, FUNC(SymGetSymFromAddr));
<a name="l02524"></a>02524     pSymGetModuleInfo = (BOOL  (WINAPI *)(
<a name="l02525"></a>02525   HANDLE hProcess,
<a name="l02526"></a>02526   DWORD dwAddr,
<a name="l02527"></a>02527   PIMAGEHLP_MODULE ModuleInfo
<a name="l02528"></a>02528 ))GetProcAddress (hmodDbgHelp, FUNC(SymGetModuleInfo));
<a name="l02529"></a>02529 pSymSetOptions = (DWORD  (WINAPI *)(
<a name="l02530"></a>02530 DWORD SymOptions
<a name="l02531"></a>02531 ))GetProcAddress (hmodDbgHelp, FUNC(SymSetOptions));
<a name="l02532"></a>02532 
<a name="l02533"></a>02533 
<a name="l02534"></a>02534     pSymSetOptions(SYMOPT_UNDNAME);
<a name="l02535"></a>02535 
<a name="l02536"></a>02536     pSymInitialize(GetCurrentProcess(), <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>);
<a name="l02537"></a>02537 
<a name="l02538"></a>02538     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02539"></a>02539 }
<a name="l02540"></a>02540 
<a name="l02541"></a>02541 <span class="keyword">static</span> <span class="keywordtype">void</span> dump_backtrace_for_thread(HANDLE hThread)
<a name="l02542"></a>02542 {
<a name="l02543"></a>02543     STACKFRAME sf;
<a name="l02544"></a>02544     CONTEXT context;
<a name="l02545"></a>02545     DWORD dwImageType;
<a name="l02546"></a>02546 
<a name="l02547"></a>02547     <span class="keywordflow">if</span> (!pStackWalk)
<a name="l02548"></a>02548         <span class="keywordflow">if</span> (!init_backtrace())
<a name="l02549"></a>02549             <span class="keywordflow">return</span>;
<a name="l02550"></a>02550 
<a name="l02551"></a>02551     <span class="comment">/* can&#39;t use this function for current thread as GetThreadContext</span>
<a name="l02552"></a>02552 <span class="comment">     * doesn&#39;t support getting context from current thread */</span>
<a name="l02553"></a>02553     <span class="keywordflow">if</span> (hThread == GetCurrentThread())
<a name="l02554"></a>02554         <span class="keywordflow">return</span>;
<a name="l02555"></a>02555 
<a name="l02556"></a>02556     DPRINTF(<span class="stringliteral">&quot;Backtrace:\n&quot;</span>);
<a name="l02557"></a>02557 
<a name="l02558"></a>02558     _DBUS_ZERO(context);
<a name="l02559"></a>02559     context.ContextFlags = CONTEXT_FULL;
<a name="l02560"></a>02560 
<a name="l02561"></a>02561     SuspendThread(hThread);
<a name="l02562"></a>02562 
<a name="l02563"></a>02563     <span class="keywordflow">if</span> (!GetThreadContext(hThread, &amp;context))
<a name="l02564"></a>02564     {
<a name="l02565"></a>02565         DPRINTF(<span class="stringliteral">&quot;Couldn&#39;t get thread context (error %ld)\n&quot;</span>, GetLastError());
<a name="l02566"></a>02566         ResumeThread(hThread);
<a name="l02567"></a>02567         <span class="keywordflow">return</span>;
<a name="l02568"></a>02568     }
<a name="l02569"></a>02569 
<a name="l02570"></a>02570     _DBUS_ZERO(sf);
<a name="l02571"></a>02571 
<a name="l02572"></a>02572 <span class="preprocessor">#ifdef __i386__</span>
<a name="l02573"></a>02573 <span class="preprocessor"></span>    sf.AddrFrame.Offset = context.Ebp;
<a name="l02574"></a>02574     sf.AddrFrame.Mode = AddrModeFlat;
<a name="l02575"></a>02575     sf.AddrPC.Offset = context.Eip;
<a name="l02576"></a>02576     sf.AddrPC.Mode = AddrModeFlat;
<a name="l02577"></a>02577     dwImageType = IMAGE_FILE_MACHINE_I386;
<a name="l02578"></a>02578 <span class="preprocessor">#elif _M_X64</span>
<a name="l02579"></a>02579 <span class="preprocessor"></span>  dwImageType                = IMAGE_FILE_MACHINE_AMD64;
<a name="l02580"></a>02580   sf.AddrPC.Offset    = context.Rip;
<a name="l02581"></a>02581   sf.AddrPC.Mode      = AddrModeFlat;
<a name="l02582"></a>02582   sf.AddrFrame.Offset = context.Rsp;
<a name="l02583"></a>02583   sf.AddrFrame.Mode   = AddrModeFlat;
<a name="l02584"></a>02584   sf.AddrStack.Offset = context.Rsp;
<a name="l02585"></a>02585   sf.AddrStack.Mode   = AddrModeFlat;
<a name="l02586"></a>02586 <span class="preprocessor">#elif _M_IA64</span>
<a name="l02587"></a>02587 <span class="preprocessor"></span>  dwImageType                 = IMAGE_FILE_MACHINE_IA64;
<a name="l02588"></a>02588   sf.AddrPC.Offset    = context.StIIP;
<a name="l02589"></a>02589   sf.AddrPC.Mode      = AddrModeFlat;
<a name="l02590"></a>02590   sf.AddrFrame.Offset = context.IntSp;
<a name="l02591"></a>02591   sf.AddrFrame.Mode   = AddrModeFlat;
<a name="l02592"></a>02592   sf.AddrBStore.Offset= context.RsBSP;
<a name="l02593"></a>02593   sf.AddrBStore.Mode  = AddrModeFlat;
<a name="l02594"></a>02594   sf.AddrStack.Offset = context.IntSp;
<a name="l02595"></a>02595   sf.AddrStack.Mode   = AddrModeFlat;
<a name="l02596"></a>02596 <span class="preprocessor">#else</span>
<a name="l02597"></a>02597 <span class="preprocessor"></span><span class="preprocessor"># error You need to fill in the STACKFRAME structure for your architecture</span>
<a name="l02598"></a>02598 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l02599"></a>02599 <span class="preprocessor"></span>
<a name="l02600"></a>02600     <span class="keywordflow">while</span> (pStackWalk(dwImageType, GetCurrentProcess(),
<a name="l02601"></a>02601                      hThread, &amp;sf, &amp;context, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, pSymFunctionTableAccess,
<a name="l02602"></a>02602                      pSymGetModuleBase, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l02603"></a>02603     {
<a name="l02604"></a>02604         BYTE buffer[256];
<a name="l02605"></a>02605         IMAGEHLP_SYMBOL * pSymbol = (IMAGEHLP_SYMBOL *)buffer;
<a name="l02606"></a>02606         DWORD dwDisplacement;
<a name="l02607"></a>02607 
<a name="l02608"></a>02608         pSymbol-&gt;SizeOfStruct = <span class="keyword">sizeof</span>(IMAGEHLP_SYMBOL);
<a name="l02609"></a>02609         pSymbol-&gt;MaxNameLength = <span class="keyword">sizeof</span>(buffer) - <span class="keyword">sizeof</span>(IMAGEHLP_SYMBOL) + 1;
<a name="l02610"></a>02610 
<a name="l02611"></a>02611         <span class="keywordflow">if</span> (!pSymGetSymFromAddr(GetCurrentProcess(), sf.AddrPC.Offset,
<a name="l02612"></a>02612                                 &amp;dwDisplacement, pSymbol))
<a name="l02613"></a>02613         {
<a name="l02614"></a>02614             IMAGEHLP_MODULE ModuleInfo;
<a name="l02615"></a>02615             ModuleInfo.SizeOfStruct = <span class="keyword">sizeof</span>(ModuleInfo);
<a name="l02616"></a>02616 
<a name="l02617"></a>02617             <span class="keywordflow">if</span> (!pSymGetModuleInfo(GetCurrentProcess(), sf.AddrPC.Offset,
<a name="l02618"></a>02618                                    &amp;ModuleInfo))
<a name="l02619"></a>02619                 DPRINTF(<span class="stringliteral">&quot;1\t%p\n&quot;</span>, (<span class="keywordtype">void</span>*)sf.AddrPC.Offset);
<a name="l02620"></a>02620             <span class="keywordflow">else</span>
<a name="l02621"></a>02621                 DPRINTF(<span class="stringliteral">&quot;2\t%s+0x%lx\n&quot;</span>, ModuleInfo.ImageName,
<a name="l02622"></a>02622                     sf.AddrPC.Offset - ModuleInfo.BaseOfImage);
<a name="l02623"></a>02623         }
<a name="l02624"></a>02624         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dwDisplacement)
<a name="l02625"></a>02625             DPRINTF(<span class="stringliteral">&quot;3\t%s+0x%lx\n&quot;</span>, pSymbol-&gt;Name, dwDisplacement);
<a name="l02626"></a>02626         <span class="keywordflow">else</span>
<a name="l02627"></a>02627             DPRINTF(<span class="stringliteral">&quot;4\t%s\n&quot;</span>, pSymbol-&gt;Name);
<a name="l02628"></a>02628     }
<a name="l02629"></a>02629 
<a name="l02630"></a>02630     ResumeThread(hThread);
<a name="l02631"></a>02631 }
<a name="l02632"></a>02632 
<a name="l02633"></a>02633 <span class="keyword">static</span> DWORD WINAPI dump_thread_proc(LPVOID lpParameter)
<a name="l02634"></a>02634 {
<a name="l02635"></a>02635     dump_backtrace_for_thread((HANDLE)lpParameter);
<a name="l02636"></a>02636     <span class="keywordflow">return</span> 0;
<a name="l02637"></a>02637 }
<a name="l02638"></a>02638 
<a name="l02639"></a>02639 <span class="comment">/* cannot get valid context from current thread, so we have to execute</span>
<a name="l02640"></a>02640 <span class="comment"> * backtrace from another thread */</span>
<a name="l02641"></a>02641 <span class="keyword">static</span> <span class="keywordtype">void</span> dump_backtrace()
<a name="l02642"></a>02642 {
<a name="l02643"></a>02643     HANDLE hCurrentThread;
<a name="l02644"></a>02644     HANDLE hThread;
<a name="l02645"></a>02645     DWORD dwThreadId;
<a name="l02646"></a>02646     DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
<a name="l02647"></a>02647         GetCurrentProcess(), &amp;hCurrentThread, 0, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, DUPLICATE_SAME_ACCESS);
<a name="l02648"></a>02648     hThread = CreateThread(<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0, dump_thread_proc, (LPVOID)hCurrentThread,
<a name="l02649"></a>02649         0, &amp;dwThreadId);
<a name="l02650"></a>02650     WaitForSingleObject(hThread, INFINITE);
<a name="l02651"></a>02651     CloseHandle(hThread);
<a name="l02652"></a>02652     CloseHandle(hCurrentThread);
<a name="l02653"></a>02653 }
<a name="l02654"></a>02654 <span class="preprocessor">#endif</span>
<a name="l02655"></a>02655 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* asserts or tests enabled */</span>
<a name="l02656"></a>02656 
<a name="l02657"></a>02657 <span class="preprocessor">#ifdef BACKTRACES</span>
<a name="l02658"></a><a class="code" href="group__DBusSysdeps.html#ga8646ab2ef727fcc862c7904113c88a8d">02658</a> <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="group__DBusSysdeps.html#ga8646ab2ef727fcc862c7904113c88a8d" title="On GNU libc systems, print a crude backtrace to stderr.">_dbus_print_backtrace</a>(<span class="keywordtype">void</span>)
<a name="l02659"></a>02659 {
<a name="l02660"></a>02660   init_backtrace();
<a name="l02661"></a>02661   dump_backtrace();
<a name="l02662"></a>02662 }
<a name="l02663"></a>02663 <span class="preprocessor">#else</span>
<a name="l02664"></a>02664 <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="group__DBusSysdeps.html#ga8646ab2ef727fcc862c7904113c88a8d" title="On GNU libc systems, print a crude backtrace to stderr.">_dbus_print_backtrace</a>(<span class="keywordtype">void</span>)
<a name="l02665"></a>02665 {
<a name="l02666"></a>02666   _dbus_verbose (<span class="stringliteral">&quot;  D-Bus not compiled with backtrace support\n&quot;</span>);
<a name="l02667"></a>02667 }
<a name="l02668"></a>02668 <span class="preprocessor">#endif</span>
<a name="l02669"></a>02669 <span class="preprocessor"></span>
<a name="l02670"></a>02670 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#gaf513803b030613a669cc7ef199f90a8b" title="A 32-bit unsigned integer on all platforms.">dbus_uint32_t</a> fromAscii(<span class="keywordtype">char</span> ascii)
<a name="l02671"></a>02671 {
<a name="l02672"></a>02672     <span class="keywordflow">if</span>(ascii &gt;= <span class="charliteral">&#39;0&#39;</span> &amp;&amp; ascii &lt;= <span class="charliteral">&#39;9&#39;</span>)
<a name="l02673"></a>02673         <span class="keywordflow">return</span> ascii - <span class="charliteral">&#39;0&#39;</span>;
<a name="l02674"></a>02674     <span class="keywordflow">if</span>(ascii &gt;= <span class="charliteral">&#39;A&#39;</span> &amp;&amp; ascii &lt;= <span class="charliteral">&#39;F&#39;</span>)
<a name="l02675"></a>02675         <span class="keywordflow">return</span> ascii - <span class="charliteral">&#39;A&#39;</span> + 10;
<a name="l02676"></a>02676     <span class="keywordflow">if</span>(ascii &gt;= <span class="charliteral">&#39;a&#39;</span> &amp;&amp; ascii &lt;= <span class="charliteral">&#39;f&#39;</span>)
<a name="l02677"></a>02677         <span class="keywordflow">return</span> ascii - <span class="charliteral">&#39;a&#39;</span> + 10;
<a name="l02678"></a>02678     <span class="keywordflow">return</span> 0;    
<a name="l02679"></a>02679 }
<a name="l02680"></a>02680 
<a name="l02681"></a><a class="code" href="group__DBusSysdeps.html#ga3f073afc8ef8397471531baf513e1bb5">02681</a> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> <a class="code" href="group__DBusSysdeps.html#ga3f073afc8ef8397471531baf513e1bb5" title="Reads the uuid of the machine we&#39;re running on from the dbus configuration.">_dbus_read_local_machine_uuid</a>   (<a class="code" href="group__DBusSysdeps.html#ga24015a2f75b94c1307360755ce97f869" title="Type representing a universally unique ID.">DBusGUID</a>         *machine_id,
<a name="l02682"></a>02682                                              <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>       create_if_not_found,
<a name="l02683"></a>02683                                              <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l02684"></a>02684 {
<a name="l02685"></a>02685 <span class="preprocessor">#ifdef DBUS_WINCE</span>
<a name="l02686"></a>02686 <span class="preprocessor"></span>        <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02687"></a>02687   <span class="comment">// TODO</span>
<a name="l02688"></a>02688 <span class="preprocessor">#else</span>
<a name="l02689"></a>02689 <span class="preprocessor"></span>    HW_PROFILE_INFOA info;
<a name="l02690"></a>02690     <span class="keywordtype">char</span> *lpc = &amp;info.szHwProfileGuid[0];
<a name="l02691"></a>02691     <a class="code" href="group__DBusTypes.html#gaf513803b030613a669cc7ef199f90a8b" title="A 32-bit unsigned integer on all platforms.">dbus_uint32_t</a> u;
<a name="l02692"></a>02692 
<a name="l02693"></a>02693     <span class="comment">//  the hw-profile guid lives long enough</span>
<a name="l02694"></a>02694     <span class="keywordflow">if</span>(!GetCurrentHwProfileA(&amp;info))
<a name="l02695"></a>02695       {
<a name="l02696"></a>02696         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>); <span class="comment">// FIXME</span>
<a name="l02697"></a>02697         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;  
<a name="l02698"></a>02698       }
<a name="l02699"></a>02699 
<a name="l02700"></a>02700     <span class="comment">// Form: {12340001-4980-1920-6788-123456789012}</span>
<a name="l02701"></a>02701     lpc++;
<a name="l02702"></a>02702     <span class="comment">// 12340001</span>
<a name="l02703"></a>02703     u = ((fromAscii(lpc[0]) &lt;&lt;  0) |
<a name="l02704"></a>02704          (fromAscii(lpc[1]) &lt;&lt;  4) |
<a name="l02705"></a>02705          (fromAscii(lpc[2]) &lt;&lt;  8) |
<a name="l02706"></a>02706          (fromAscii(lpc[3]) &lt;&lt; 12) |
<a name="l02707"></a>02707          (fromAscii(lpc[4]) &lt;&lt; 16) |
<a name="l02708"></a>02708          (fromAscii(lpc[5]) &lt;&lt; 20) |
<a name="l02709"></a>02709          (fromAscii(lpc[6]) &lt;&lt; 24) |
<a name="l02710"></a>02710          (fromAscii(lpc[7]) &lt;&lt; 28));
<a name="l02711"></a>02711     machine_id-&gt;as_uint32s[0] = u;
<a name="l02712"></a>02712 
<a name="l02713"></a>02713     lpc += 9;
<a name="l02714"></a>02714     <span class="comment">// 4980-1920</span>
<a name="l02715"></a>02715     u = ((fromAscii(lpc[0]) &lt;&lt;  0) |
<a name="l02716"></a>02716          (fromAscii(lpc[1]) &lt;&lt;  4) |
<a name="l02717"></a>02717          (fromAscii(lpc[2]) &lt;&lt;  8) |
<a name="l02718"></a>02718          (fromAscii(lpc[3]) &lt;&lt; 12) |
<a name="l02719"></a>02719          (fromAscii(lpc[5]) &lt;&lt; 16) |
<a name="l02720"></a>02720          (fromAscii(lpc[6]) &lt;&lt; 20) |
<a name="l02721"></a>02721          (fromAscii(lpc[7]) &lt;&lt; 24) |
<a name="l02722"></a>02722          (fromAscii(lpc[8]) &lt;&lt; 28));
<a name="l02723"></a>02723     machine_id-&gt;as_uint32s[1] = u;
<a name="l02724"></a>02724     
<a name="l02725"></a>02725     lpc += 10;
<a name="l02726"></a>02726     <span class="comment">// 6788-1234</span>
<a name="l02727"></a>02727     u = ((fromAscii(lpc[0]) &lt;&lt;  0) |
<a name="l02728"></a>02728          (fromAscii(lpc[1]) &lt;&lt;  4) |
<a name="l02729"></a>02729          (fromAscii(lpc[2]) &lt;&lt;  8) |
<a name="l02730"></a>02730          (fromAscii(lpc[3]) &lt;&lt; 12) |
<a name="l02731"></a>02731          (fromAscii(lpc[5]) &lt;&lt; 16) |
<a name="l02732"></a>02732          (fromAscii(lpc[6]) &lt;&lt; 20) |
<a name="l02733"></a>02733          (fromAscii(lpc[7]) &lt;&lt; 24) |
<a name="l02734"></a>02734          (fromAscii(lpc[8]) &lt;&lt; 28));
<a name="l02735"></a>02735     machine_id-&gt;as_uint32s[2] = u;
<a name="l02736"></a>02736     
<a name="l02737"></a>02737     lpc += 9;
<a name="l02738"></a>02738     <span class="comment">// 56789012</span>
<a name="l02739"></a>02739     u = ((fromAscii(lpc[0]) &lt;&lt;  0) |
<a name="l02740"></a>02740          (fromAscii(lpc[1]) &lt;&lt;  4) |
<a name="l02741"></a>02741          (fromAscii(lpc[2]) &lt;&lt;  8) |
<a name="l02742"></a>02742          (fromAscii(lpc[3]) &lt;&lt; 12) |
<a name="l02743"></a>02743          (fromAscii(lpc[4]) &lt;&lt; 16) |
<a name="l02744"></a>02744          (fromAscii(lpc[5]) &lt;&lt; 20) |
<a name="l02745"></a>02745          (fromAscii(lpc[6]) &lt;&lt; 24) |
<a name="l02746"></a>02746          (fromAscii(lpc[7]) &lt;&lt; 28));
<a name="l02747"></a>02747     machine_id-&gt;as_uint32s[3] = u;
<a name="l02748"></a>02748 <span class="preprocessor">#endif</span>
<a name="l02749"></a>02749 <span class="preprocessor"></span>    <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02750"></a>02750 }
<a name="l02751"></a>02751 
<a name="l02752"></a>02752 <span class="keyword">static</span>
<a name="l02753"></a>02753 HANDLE _dbus_global_lock (<span class="keyword">const</span> <span class="keywordtype">char</span> *mutexname)
<a name="l02754"></a>02754 {
<a name="l02755"></a>02755   HANDLE mutex;
<a name="l02756"></a>02756   DWORD gotMutex;
<a name="l02757"></a>02757 
<a name="l02758"></a>02758   mutex = CreateMutexA( <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, mutexname );
<a name="l02759"></a>02759   <span class="keywordflow">if</span>( !mutex )
<a name="l02760"></a>02760     {
<a name="l02761"></a>02761       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02762"></a>02762     }
<a name="l02763"></a>02763 
<a name="l02764"></a>02764    gotMutex = WaitForSingleObject( mutex, INFINITE );
<a name="l02765"></a>02765    <span class="keywordflow">switch</span>( gotMutex )
<a name="l02766"></a>02766      {
<a name="l02767"></a>02767        <span class="keywordflow">case</span> WAIT_ABANDONED:
<a name="l02768"></a>02768                ReleaseMutex (mutex);
<a name="l02769"></a>02769                CloseHandle (mutex);
<a name="l02770"></a>02770                <span class="keywordflow">return</span> 0;
<a name="l02771"></a>02771        <span class="keywordflow">case</span> WAIT_FAILED:
<a name="l02772"></a>02772        <span class="keywordflow">case</span> WAIT_TIMEOUT:
<a name="l02773"></a>02773                <span class="keywordflow">return</span> 0;
<a name="l02774"></a>02774      }
<a name="l02775"></a>02775 
<a name="l02776"></a>02776    <span class="keywordflow">return</span> mutex;
<a name="l02777"></a>02777 }
<a name="l02778"></a>02778 
<a name="l02779"></a>02779 <span class="keyword">static</span>
<a name="l02780"></a>02780 <span class="keywordtype">void</span> _dbus_global_unlock (HANDLE mutex)
<a name="l02781"></a>02781 {
<a name="l02782"></a>02782   ReleaseMutex (mutex);
<a name="l02783"></a>02783   CloseHandle (mutex); 
<a name="l02784"></a>02784 }
<a name="l02785"></a>02785 
<a name="l02786"></a>02786 <span class="comment">// for proper cleanup in dbus-daemon</span>
<a name="l02787"></a>02787 <span class="keyword">static</span> HANDLE hDBusDaemonMutex = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02788"></a>02788 <span class="keyword">static</span> HANDLE hDBusSharedMem = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02789"></a>02789 <span class="comment">// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs</span>
<a name="l02790"></a>02790 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *cUniqueDBusInitMutex = <span class="stringliteral">&quot;UniqueDBusInitMutex&quot;</span>;
<a name="l02791"></a>02791 <span class="comment">// sync _dbus_get_autolaunch_address</span>
<a name="l02792"></a>02792 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *cDBusAutolaunchMutex = <span class="stringliteral">&quot;DBusAutolaunchMutex&quot;</span>;
<a name="l02793"></a>02793 <span class="comment">// mutex to determine if dbus-daemon is already started (per user)</span>
<a name="l02794"></a>02794 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *cDBusDaemonMutex = <span class="stringliteral">&quot;DBusDaemonMutex&quot;</span>;
<a name="l02795"></a>02795 <span class="comment">// named shm for dbus adress info (per user)</span>
<a name="l02796"></a>02796 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *cDBusDaemonAddressInfo = <span class="stringliteral">&quot;DBusDaemonAddressInfo&quot;</span>;
<a name="l02797"></a>02797 
<a name="l02798"></a>02798 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02799"></a>02799 _dbus_get_install_root_as_hash(<a class="code" href="structDBusString.html">DBusString</a> *out)
<a name="l02800"></a>02800 {
<a name="l02801"></a>02801     <a class="code" href="structDBusString.html">DBusString</a> install_path;
<a name="l02802"></a>02802 
<a name="l02803"></a>02803     <span class="keywordtype">char</span> path[MAX_PATH*2];
<a name="l02804"></a>02804     <span class="keywordtype">int</span> path_size = <span class="keyword">sizeof</span>(path);
<a name="l02805"></a>02805 
<a name="l02806"></a>02806     <span class="keywordflow">if</span> (!_dbus_get_install_root(path,path_size))
<a name="l02807"></a>02807         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02808"></a>02808 
<a name="l02809"></a>02809     <a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a>(&amp;install_path);
<a name="l02810"></a>02810     <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(&amp;install_path,path);
<a name="l02811"></a>02811 
<a name="l02812"></a>02812     <a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a>(out);
<a name="l02813"></a>02813     <a class="code" href="group__DBusString.html#ga698f4b0299e6c6a707fd7e9c14915f00" title="Converts the given range of the string to lower case.">_dbus_string_tolower_ascii</a>(&amp;install_path,0,<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a>(&amp;install_path));
<a name="l02814"></a>02814 
<a name="l02815"></a>02815     <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSHA.html#ga4278fb9df967943834c4ad6332f2c28b" title="Computes the ASCII hex-encoded shasum of the given data and appends it to the output string...">_dbus_sha_compute</a> (&amp;install_path, out))
<a name="l02816"></a>02816         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02817"></a>02817 
<a name="l02818"></a>02818     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02819"></a>02819 }
<a name="l02820"></a>02820 
<a name="l02821"></a>02821 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02822"></a>02822 _dbus_get_address_string (<a class="code" href="structDBusString.html">DBusString</a> *out, <span class="keyword">const</span> <span class="keywordtype">char</span> *basestring, <span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l02823"></a>02823 {
<a name="l02824"></a>02824   <a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a>(out);
<a name="l02825"></a>02825   <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,basestring);
<a name="l02826"></a>02826 
<a name="l02827"></a>02827   <span class="keywordflow">if</span> (!scope)
<a name="l02828"></a>02828     {
<a name="l02829"></a>02829       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02830"></a>02830     }
<a name="l02831"></a>02831   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(scope,<span class="stringliteral">&quot;*install-path&quot;</span>) == 0
<a name="l02832"></a>02832         <span class="comment">// for 1.3 compatibility</span>
<a name="l02833"></a>02833         || strcmp(scope,<span class="stringliteral">&quot;install-path&quot;</span>) == 0)
<a name="l02834"></a>02834     {
<a name="l02835"></a>02835       <a class="code" href="structDBusString.html">DBusString</a> temp;
<a name="l02836"></a>02836       <span class="keywordflow">if</span> (!_dbus_get_install_root_as_hash(&amp;temp))
<a name="l02837"></a>02837         {
<a name="l02838"></a>02838           <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(out);
<a name="l02839"></a>02839            <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02840"></a>02840         }
<a name="l02841"></a>02841       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,<span class="stringliteral">&quot;-&quot;</span>);
<a name="l02842"></a>02842       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,<a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(&amp;temp));
<a name="l02843"></a>02843       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;temp);
<a name="l02844"></a>02844     }
<a name="l02845"></a>02845   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(scope,<span class="stringliteral">&quot;*user&quot;</span>) == 0)
<a name="l02846"></a>02846     {
<a name="l02847"></a>02847       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,<span class="stringliteral">&quot;-&quot;</span>);
<a name="l02848"></a>02848       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#ga095c54de3974c6d04c29ef86c6e06e35" title="Append to the string the identity we would like to have when we authenticate, on UNIX this is the cur...">_dbus_append_user_from_current_process</a>(out))
<a name="l02849"></a>02849         {
<a name="l02850"></a>02850            <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(out);
<a name="l02851"></a>02851            <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02852"></a>02852         }
<a name="l02853"></a>02853     }
<a name="l02854"></a>02854   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strlen(scope) &gt; 0)
<a name="l02855"></a>02855     {
<a name="l02856"></a>02856       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,<span class="stringliteral">&quot;-&quot;</span>);
<a name="l02857"></a>02857       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(out,scope);
<a name="l02858"></a>02858       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02859"></a>02859     }
<a name="l02860"></a>02860   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02861"></a>02861 }
<a name="l02862"></a>02862 
<a name="l02863"></a>02863 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02864"></a>02864 _dbus_get_shm_name (<a class="code" href="structDBusString.html">DBusString</a> *out,<span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l02865"></a>02865 {
<a name="l02866"></a>02866   <span class="keywordflow">return</span> _dbus_get_address_string (out,cDBusDaemonAddressInfo,scope);
<a name="l02867"></a>02867 }
<a name="l02868"></a>02868 
<a name="l02869"></a>02869 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02870"></a>02870 _dbus_get_mutex_name (<a class="code" href="structDBusString.html">DBusString</a> *out,<span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l02871"></a>02871 {
<a name="l02872"></a>02872   <span class="keywordflow">return</span> _dbus_get_address_string (out,cDBusDaemonMutex,scope);
<a name="l02873"></a>02873 }
<a name="l02874"></a>02874 
<a name="l02875"></a>02875 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02876"></a>02876 _dbus_daemon_is_session_bus_address_published (<span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l02877"></a>02877 {
<a name="l02878"></a>02878   HANDLE lock;
<a name="l02879"></a>02879   <a class="code" href="structDBusString.html">DBusString</a> mutex_name;
<a name="l02880"></a>02880 
<a name="l02881"></a>02881   <span class="keywordflow">if</span> (!_dbus_get_mutex_name(&amp;mutex_name,scope))
<a name="l02882"></a>02882     {
<a name="l02883"></a>02883       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l02884"></a>02884       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02885"></a>02885     }
<a name="l02886"></a>02886 
<a name="l02887"></a>02887   <span class="keywordflow">if</span> (hDBusDaemonMutex)
<a name="l02888"></a>02888       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02889"></a>02889 
<a name="l02890"></a>02890   <span class="comment">// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs</span>
<a name="l02891"></a>02891   lock = _dbus_global_lock( cUniqueDBusInitMutex );
<a name="l02892"></a>02892 
<a name="l02893"></a>02893   <span class="comment">// we use CreateMutex instead of OpenMutex because of possible race conditions,</span>
<a name="l02894"></a>02894   <span class="comment">// see http://msdn.microsoft.com/en-us/library/ms684315%28VS.85%29.aspx</span>
<a name="l02895"></a>02895   hDBusDaemonMutex = CreateMutexA( <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(&amp;mutex_name) );
<a name="l02896"></a>02896 
<a name="l02897"></a>02897   <span class="comment">/* The client uses mutex ownership to detect a running server, so the server should do so too.</span>
<a name="l02898"></a>02898 <span class="comment">     Fortunally the client deletes the mutex in the lock protected area, so checking presence </span>
<a name="l02899"></a>02899 <span class="comment">     will work too.  */</span>
<a name="l02900"></a>02900 
<a name="l02901"></a>02901   _dbus_global_unlock( lock );
<a name="l02902"></a>02902 
<a name="l02903"></a>02903   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l02904"></a>02904 
<a name="l02905"></a>02905   <span class="keywordflow">if</span> (hDBusDaemonMutex  == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02906"></a>02906       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02907"></a>02907   <span class="keywordflow">if</span> (GetLastError() == ERROR_ALREADY_EXISTS)
<a name="l02908"></a>02908     {
<a name="l02909"></a>02909       CloseHandle(hDBusDaemonMutex);
<a name="l02910"></a>02910       hDBusDaemonMutex = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02911"></a>02911       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02912"></a>02912     }
<a name="l02913"></a>02913   <span class="comment">// mutex wasn&#39;t created before, so return false.</span>
<a name="l02914"></a>02914   <span class="comment">// We leave the mutex name allocated for later reusage</span>
<a name="l02915"></a>02915   <span class="comment">// in _dbus_daemon_publish_session_bus_address.</span>
<a name="l02916"></a>02916   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02917"></a>02917 }
<a name="l02918"></a>02918 
<a name="l02919"></a>02919 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02920"></a>02920 _dbus_daemon_publish_session_bus_address (<span class="keyword">const</span> <span class="keywordtype">char</span>* address, <span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l02921"></a>02921 {
<a name="l02922"></a>02922   HANDLE lock;
<a name="l02923"></a>02923   <span class="keywordtype">char</span> *shared_addr = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02924"></a>02924   <a class="code" href="structDBusString.html">DBusString</a> shm_name;
<a name="l02925"></a>02925   <a class="code" href="structDBusString.html">DBusString</a> mutex_name;
<a name="l02926"></a>02926 
<a name="l02927"></a>02927   _dbus_assert (address);
<a name="l02928"></a>02928 
<a name="l02929"></a>02929   <span class="keywordflow">if</span> (!_dbus_get_mutex_name(&amp;mutex_name,scope))
<a name="l02930"></a>02930     {
<a name="l02931"></a>02931       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l02932"></a>02932       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02933"></a>02933     }
<a name="l02934"></a>02934 
<a name="l02935"></a>02935   <span class="comment">// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs</span>
<a name="l02936"></a>02936   lock = _dbus_global_lock( cUniqueDBusInitMutex );
<a name="l02937"></a>02937 
<a name="l02938"></a>02938   <span class="keywordflow">if</span> (!hDBusDaemonMutex)
<a name="l02939"></a>02939     {
<a name="l02940"></a>02940       hDBusDaemonMutex = CreateMutexA( <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(&amp;mutex_name) );
<a name="l02941"></a>02941     }
<a name="l02942"></a>02942   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l02943"></a>02943 
<a name="l02944"></a>02944   <span class="comment">// acquire the mutex</span>
<a name="l02945"></a>02945   <span class="keywordflow">if</span> (WaitForSingleObject( hDBusDaemonMutex, 10 ) != WAIT_OBJECT_0)
<a name="l02946"></a>02946     {
<a name="l02947"></a>02947       _dbus_global_unlock( lock );
<a name="l02948"></a>02948       CloseHandle( hDBusDaemonMutex );
<a name="l02949"></a>02949       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02950"></a>02950     }
<a name="l02951"></a>02951 
<a name="l02952"></a>02952   <span class="keywordflow">if</span> (!_dbus_get_shm_name(&amp;shm_name,scope))
<a name="l02953"></a>02953     {
<a name="l02954"></a>02954       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;shm_name );
<a name="l02955"></a>02955       _dbus_global_unlock( lock );
<a name="l02956"></a>02956       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02957"></a>02957     }
<a name="l02958"></a>02958 
<a name="l02959"></a>02959   <span class="comment">// create shm</span>
<a name="l02960"></a>02960   hDBusSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, PAGE_READWRITE,
<a name="l02961"></a>02961                                        0, strlen( address ) + 1, <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(&amp;shm_name) );
<a name="l02962"></a>02962   _dbus_assert( hDBusSharedMem );
<a name="l02963"></a>02963 
<a name="l02964"></a>02964   shared_addr = MapViewOfFile( hDBusSharedMem, FILE_MAP_WRITE, 0, 0, 0 );
<a name="l02965"></a>02965 
<a name="l02966"></a>02966   _dbus_assert (shared_addr);
<a name="l02967"></a>02967 
<a name="l02968"></a>02968   strcpy( shared_addr, address);
<a name="l02969"></a>02969 
<a name="l02970"></a>02970   <span class="comment">// cleanup</span>
<a name="l02971"></a>02971   UnmapViewOfFile( shared_addr );
<a name="l02972"></a>02972 
<a name="l02973"></a>02973   _dbus_global_unlock( lock );
<a name="l02974"></a>02974   _dbus_verbose( <span class="stringliteral">&quot;published session bus address at %s\n&quot;</span>,<a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (&amp;shm_name) );
<a name="l02975"></a>02975 
<a name="l02976"></a>02976   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;shm_name );
<a name="l02977"></a>02977   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02978"></a>02978 }
<a name="l02979"></a>02979 
<a name="l02980"></a>02980 <span class="keywordtype">void</span>
<a name="l02981"></a>02981 _dbus_daemon_unpublish_session_bus_address (<span class="keywordtype">void</span>)
<a name="l02982"></a>02982 {
<a name="l02983"></a>02983   HANDLE lock;
<a name="l02984"></a>02984 
<a name="l02985"></a>02985   <span class="comment">// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs</span>
<a name="l02986"></a>02986   lock = _dbus_global_lock( cUniqueDBusInitMutex );
<a name="l02987"></a>02987 
<a name="l02988"></a>02988   CloseHandle( hDBusSharedMem );
<a name="l02989"></a>02989 
<a name="l02990"></a>02990   hDBusSharedMem = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02991"></a>02991 
<a name="l02992"></a>02992   ReleaseMutex( hDBusDaemonMutex );
<a name="l02993"></a>02993 
<a name="l02994"></a>02994   CloseHandle( hDBusDaemonMutex );
<a name="l02995"></a>02995 
<a name="l02996"></a>02996   hDBusDaemonMutex = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02997"></a>02997 
<a name="l02998"></a>02998   _dbus_global_unlock( lock );
<a name="l02999"></a>02999 }
<a name="l03000"></a>03000 
<a name="l03001"></a>03001 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03002"></a>03002 _dbus_get_autolaunch_shm (<a class="code" href="structDBusString.html">DBusString</a> *address, <a class="code" href="structDBusString.html">DBusString</a> *shm_name)
<a name="l03003"></a>03003 {
<a name="l03004"></a>03004   HANDLE sharedMem;
<a name="l03005"></a>03005   <span class="keywordtype">char</span> *shared_addr;
<a name="l03006"></a>03006   <span class="keywordtype">int</span> i;
<a name="l03007"></a>03007 
<a name="l03008"></a>03008   <span class="comment">// read shm</span>
<a name="l03009"></a>03009   <span class="keywordflow">for</span>(i=0;i&lt;20;++i) {
<a name="l03010"></a>03010       <span class="comment">// we know that dbus-daemon is available, so we wait until shm is available</span>
<a name="l03011"></a>03011       sharedMem = OpenFileMappingA( FILE_MAP_READ, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(shm_name));
<a name="l03012"></a>03012       <span class="keywordflow">if</span>( sharedMem == 0 )
<a name="l03013"></a>03013           Sleep( 100 );
<a name="l03014"></a>03014       <span class="keywordflow">if</span> ( sharedMem != 0)
<a name="l03015"></a>03015           <span class="keywordflow">break</span>;
<a name="l03016"></a>03016   }
<a name="l03017"></a>03017 
<a name="l03018"></a>03018   <span class="keywordflow">if</span>( sharedMem == 0 )
<a name="l03019"></a>03019       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03020"></a>03020 
<a name="l03021"></a>03021   shared_addr = MapViewOfFile( sharedMem, FILE_MAP_READ, 0, 0, 0 );
<a name="l03022"></a>03022 
<a name="l03023"></a>03023   <span class="keywordflow">if</span>( !shared_addr )
<a name="l03024"></a>03024       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03025"></a>03025 
<a name="l03026"></a>03026   <a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a>( address );
<a name="l03027"></a>03027 
<a name="l03028"></a>03028   <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>( address, shared_addr );
<a name="l03029"></a>03029 
<a name="l03030"></a>03030   <span class="comment">// cleanup</span>
<a name="l03031"></a>03031   UnmapViewOfFile( shared_addr );
<a name="l03032"></a>03032 
<a name="l03033"></a>03033   CloseHandle( sharedMem );
<a name="l03034"></a>03034 
<a name="l03035"></a>03035   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03036"></a>03036 }
<a name="l03037"></a>03037 
<a name="l03038"></a>03038 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03039"></a>03039 _dbus_daemon_already_runs (<a class="code" href="structDBusString.html">DBusString</a> *address, <a class="code" href="structDBusString.html">DBusString</a> *shm_name, <span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l03040"></a>03040 {
<a name="l03041"></a>03041   HANDLE lock;
<a name="l03042"></a>03042   HANDLE daemon;
<a name="l03043"></a>03043   <a class="code" href="structDBusString.html">DBusString</a> mutex_name;
<a name="l03044"></a>03044   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> bRet = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03045"></a>03045 
<a name="l03046"></a>03046   <span class="keywordflow">if</span> (!_dbus_get_mutex_name(&amp;mutex_name,scope))
<a name="l03047"></a>03047     {
<a name="l03048"></a>03048       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l03049"></a>03049       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03050"></a>03050     }
<a name="l03051"></a>03051 
<a name="l03052"></a>03052   <span class="comment">// sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs</span>
<a name="l03053"></a>03053   lock = _dbus_global_lock( cUniqueDBusInitMutex );
<a name="l03054"></a>03054 
<a name="l03055"></a>03055   <span class="comment">// do checks</span>
<a name="l03056"></a>03056   daemon = CreateMutexA( <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(&amp;mutex_name) );
<a name="l03057"></a>03057   <span class="keywordflow">if</span>(WaitForSingleObject( daemon, 10 ) != WAIT_TIMEOUT)
<a name="l03058"></a>03058     {
<a name="l03059"></a>03059       ReleaseMutex (daemon);
<a name="l03060"></a>03060       CloseHandle (daemon);
<a name="l03061"></a>03061 
<a name="l03062"></a>03062       _dbus_global_unlock( lock );
<a name="l03063"></a>03063       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l03064"></a>03064       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03065"></a>03065     }
<a name="l03066"></a>03066 
<a name="l03067"></a>03067   <span class="comment">// read shm</span>
<a name="l03068"></a>03068   bRet = _dbus_get_autolaunch_shm( address, shm_name );
<a name="l03069"></a>03069 
<a name="l03070"></a>03070   <span class="comment">// cleanup</span>
<a name="l03071"></a>03071   CloseHandle ( daemon );
<a name="l03072"></a>03072 
<a name="l03073"></a>03073   _dbus_global_unlock( lock );
<a name="l03074"></a>03074   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>( &amp;mutex_name );
<a name="l03075"></a>03075 
<a name="l03076"></a>03076   <span class="keywordflow">return</span> bRet;
<a name="l03077"></a>03077 }
<a name="l03078"></a>03078 
<a name="l03079"></a>03079 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03080"></a><a class="code" href="group__DBusSysdeps.html#gabc4712c0db91f11854cdd933027355af">03080</a> <a class="code" href="group__DBusSysdeps.html#gabc4712c0db91f11854cdd933027355af" title="Returns the address of a new session bus.">_dbus_get_autolaunch_address</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *scope, <a class="code" href="structDBusString.html">DBusString</a> *address,
<a name="l03081"></a>03081                               <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l03082"></a>03082 {
<a name="l03083"></a>03083   HANDLE mutex;
<a name="l03084"></a>03084   STARTUPINFOA si;
<a name="l03085"></a>03085   PROCESS_INFORMATION pi;
<a name="l03086"></a>03086   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03087"></a>03087   LPSTR lpFile;
<a name="l03088"></a>03088   <span class="keywordtype">char</span> dbus_exe_path[MAX_PATH];
<a name="l03089"></a>03089   <span class="keywordtype">char</span> dbus_args[MAX_PATH * 2];
<a name="l03090"></a>03090   <span class="keyword">const</span> <span class="keywordtype">char</span> * daemon_name = DBUS_DAEMON_NAME <span class="stringliteral">&quot;.exe&quot;</span>;
<a name="l03091"></a>03091   <a class="code" href="structDBusString.html">DBusString</a> shm_name;
<a name="l03092"></a>03092 
<a name="l03093"></a>03093   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03094"></a>03094 
<a name="l03095"></a>03095   <span class="keywordflow">if</span> (!_dbus_get_shm_name(&amp;shm_name,scope))
<a name="l03096"></a>03096     {
<a name="l03097"></a>03097         <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;could not determine shm name&quot;</span>);
<a name="l03098"></a>03098         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03099"></a>03099     }
<a name="l03100"></a>03100 
<a name="l03101"></a>03101   mutex = _dbus_global_lock ( cDBusAutolaunchMutex );
<a name="l03102"></a>03102 
<a name="l03103"></a>03103   <span class="keywordflow">if</span> (_dbus_daemon_already_runs(address,&amp;shm_name,scope))
<a name="l03104"></a>03104     {
<a name="l03105"></a>03105         _dbus_verbose( <span class="stringliteral">&quot;found running dbus daemon at %s\n&quot;</span>,
<a name="l03106"></a>03106                        <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (&amp;shm_name) );
<a name="l03107"></a>03107         retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03108"></a>03108         <span class="keywordflow">goto</span> out;
<a name="l03109"></a>03109     }
<a name="l03110"></a>03110 
<a name="l03111"></a>03111   <span class="keywordflow">if</span> (!SearchPathA(<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, daemon_name, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <span class="keyword">sizeof</span>(dbus_exe_path), dbus_exe_path, &amp;lpFile))
<a name="l03112"></a>03112     {
<a name="l03113"></a>03113       <span class="comment">// Look in directory containing dbus shared library</span>
<a name="l03114"></a>03114       HMODULE hmod;
<a name="l03115"></a>03115       <span class="keywordtype">char</span> dbus_module_path[MAX_PATH];
<a name="l03116"></a>03116       DWORD rc;
<a name="l03117"></a>03117 
<a name="l03118"></a>03118       _dbus_verbose( <span class="stringliteral">&quot;did not found dbus daemon executable on default search path, &quot;</span>
<a name="l03119"></a>03119             <span class="stringliteral">&quot;trying path where dbus shared library is located&quot;</span>);
<a name="l03120"></a>03120 
<a name="l03121"></a>03121       hmod = _dbus_win_get_dll_hmodule();
<a name="l03122"></a>03122       rc = GetModuleFileNameA(hmod, dbus_module_path, <span class="keyword">sizeof</span>(dbus_module_path));
<a name="l03123"></a>03123       <span class="keywordflow">if</span> (rc &lt;= 0)
<a name="l03124"></a>03124         {
<a name="l03125"></a>03125           <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;could not retrieve dbus shared library file name&quot;</span>);
<a name="l03126"></a>03126           retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03127"></a>03127           <span class="keywordflow">goto</span> out;
<a name="l03128"></a>03128         }
<a name="l03129"></a>03129       <span class="keywordflow">else</span>
<a name="l03130"></a>03130         {
<a name="l03131"></a>03131           <span class="keywordtype">char</span> *ext_idx = strrchr(dbus_module_path, <span class="charliteral">&#39;\\&#39;</span>);
<a name="l03132"></a>03132           <span class="keywordflow">if</span> (ext_idx)
<a name="l03133"></a>03133           *ext_idx = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l03134"></a>03134           <span class="keywordflow">if</span> (!SearchPathA(dbus_module_path, daemon_name, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <span class="keyword">sizeof</span>(dbus_exe_path), dbus_exe_path, &amp;lpFile))
<a name="l03135"></a>03135             {
<a name="l03136"></a>03136               <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;could not find dbus-daemon executable&quot;</span>);
<a name="l03137"></a>03137               retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03138"></a>03138               printf (<span class="stringliteral">&quot;please add the path to %s to your PATH environment variable\n&quot;</span>, daemon_name);
<a name="l03139"></a>03139               printf (<span class="stringliteral">&quot;or start the daemon manually\n\n&quot;</span>);
<a name="l03140"></a>03140               <span class="keywordflow">goto</span> out;
<a name="l03141"></a>03141             }
<a name="l03142"></a>03142           _dbus_verbose( <span class="stringliteral">&quot;found dbus daemon executable at %s&quot;</span>,dbus_module_path);
<a name="l03143"></a>03143         }
<a name="l03144"></a>03144     }
<a name="l03145"></a>03145 
<a name="l03146"></a>03146 
<a name="l03147"></a>03147   <span class="comment">// Create process</span>
<a name="l03148"></a>03148   ZeroMemory( &amp;si, <span class="keyword">sizeof</span>(si) );
<a name="l03149"></a>03149   si.cb = <span class="keyword">sizeof</span>(si);
<a name="l03150"></a>03150   ZeroMemory( &amp;pi, <span class="keyword">sizeof</span>(pi) );
<a name="l03151"></a>03151 
<a name="l03152"></a>03152   _snprintf(dbus_args, <span class="keyword">sizeof</span>(dbus_args) - 1, <span class="stringliteral">&quot;\&quot;%s\&quot; %s&quot;</span>, dbus_exe_path,  <span class="stringliteral">&quot; --session&quot;</span>);
<a name="l03153"></a>03153 
<a name="l03154"></a>03154 <span class="comment">//  argv[i] = &quot;--config-file=bus\\session.conf&quot;;</span>
<a name="l03155"></a>03155 <span class="comment">//  printf(&quot;create process \&quot;%s\&quot; %s\n&quot;, dbus_exe_path, dbus_args);</span>
<a name="l03156"></a>03156   <span class="keywordflow">if</span>(CreateProcessA(dbus_exe_path, dbus_args, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, CREATE_NO_WINDOW, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, &amp;si, &amp;pi))
<a name="l03157"></a>03157     {
<a name="l03158"></a>03158       CloseHandle (pi.hThread);
<a name="l03159"></a>03159       CloseHandle (pi.hProcess);
<a name="l03160"></a>03160       retval = _dbus_get_autolaunch_shm( address, &amp;shm_name );
<a name="l03161"></a>03161       <span class="keywordflow">if</span> (retval == <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>)
<a name="l03162"></a>03162         <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;Failed to get autolaunch address from launched dbus-daemon&quot;</span>);
<a name="l03163"></a>03163     }
<a name="l03164"></a>03164   <span class="keywordflow">else</span>
<a name="l03165"></a>03165     {
<a name="l03166"></a>03166       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>, <span class="stringliteral">&quot;Failed to launch dbus-daemon&quot;</span>);
<a name="l03167"></a>03167       retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03168"></a>03168     }
<a name="l03169"></a>03169 
<a name="l03170"></a>03170 out:
<a name="l03171"></a>03171   <span class="keywordflow">if</span> (retval)
<a name="l03172"></a>03172     _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03173"></a>03173   <span class="keywordflow">else</span>
<a name="l03174"></a>03174     _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l03175"></a>03175   
<a name="l03176"></a>03176   _dbus_global_unlock (mutex);
<a name="l03177"></a>03177 
<a name="l03178"></a>03178   <span class="keywordflow">return</span> retval;
<a name="l03179"></a>03179  }
<a name="l03180"></a>03180 
<a name="l03181"></a>03181 
<a name="l03188"></a>03188 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03189"></a><a class="code" href="group__DBusFile.html#ga7c83e2e20811330d1d1b2f6249dbe66c">03189</a> <a class="code" href="group__DBusFile.html#ga7c83e2e20811330d1d1b2f6249dbe66c" title="Makes the file readable by every user in the system.">_dbus_make_file_world_readable</a>(<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l03190"></a>03190                                <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l03191"></a>03191 {
<a name="l03192"></a>03192   <span class="comment">// TODO</span>
<a name="l03193"></a>03193   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03194"></a>03194 }
<a name="l03195"></a>03195 
<a name="l03203"></a>03203 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l03204"></a><a class="code" href="group__DBusSysdeps.html#gae74c3fcf12acaeccdb152ef907de951c">03204</a> <a class="code" href="group__DBusSysdeps.html#gae74c3fcf12acaeccdb152ef907de951c" title="Atomically increments an integer.">_dbus_atomic_inc</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l03205"></a>03205 {
<a name="l03206"></a>03206   <span class="comment">// +/- 1 is needed here!</span>
<a name="l03207"></a>03207   <span class="comment">// no volatile argument with mingw</span>
<a name="l03208"></a>03208   <span class="keywordflow">return</span> InterlockedIncrement (&amp;atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>) - 1;
<a name="l03209"></a>03209 }
<a name="l03210"></a>03210 
<a name="l03218"></a>03218 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l03219"></a><a class="code" href="group__DBusSysdeps.html#ga3c50a069f795dceeb9172fe2b517bbdc">03219</a> <a class="code" href="group__DBusSysdeps.html#ga3c50a069f795dceeb9172fe2b517bbdc" title="Atomically decrement an integer.">_dbus_atomic_dec</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l03220"></a>03220 {
<a name="l03221"></a>03221   <span class="comment">// +/- 1 is needed here!</span>
<a name="l03222"></a>03222   <span class="comment">// no volatile argument with mingw</span>
<a name="l03223"></a>03223   <span class="keywordflow">return</span> InterlockedDecrement (&amp;atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>) + 1;
<a name="l03224"></a>03224 }
<a name="l03225"></a>03225 
<a name="l03233"></a>03233 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l03234"></a><a class="code" href="group__DBusSysdeps.html#ga626c810359ba0e362367ce2ec6691aca">03234</a> <a class="code" href="group__DBusSysdeps.html#ga626c810359ba0e362367ce2ec6691aca" title="Atomically get the value of an integer.">_dbus_atomic_get</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l03235"></a>03235 {
<a name="l03236"></a>03236   <span class="comment">/* In this situation, GLib issues a MemoryBarrier() and then returns</span>
<a name="l03237"></a>03237 <span class="comment">   * atomic-&gt;value. However, mingw from mingw.org (not to be confused with</span>
<a name="l03238"></a>03238 <span class="comment">   * mingw-w64 from mingw-w64.sf.net) does not have MemoryBarrier in its</span>
<a name="l03239"></a>03239 <span class="comment">   * headers, so we have to get a memory barrier some other way.</span>
<a name="l03240"></a>03240 <span class="comment">   *</span>
<a name="l03241"></a>03241 <span class="comment">   * InterlockedIncrement is older, and is documented on MSDN to be a full</span>
<a name="l03242"></a>03242 <span class="comment">   * memory barrier, so let&#39;s use that.</span>
<a name="l03243"></a>03243 <span class="comment">   */</span>
<a name="l03244"></a>03244   <span class="keywordtype">long</span> dummy = 0;
<a name="l03245"></a>03245 
<a name="l03246"></a>03246   InterlockedExchange (&amp;dummy, 1);
<a name="l03247"></a>03247 
<a name="l03248"></a>03248   <span class="keywordflow">return</span> atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>;
<a name="l03249"></a>03249 }
<a name="l03250"></a>03250 
<a name="l03258"></a>03258 <span class="keywordtype">void</span>
<a name="l03259"></a><a class="code" href="group__DBusSysdeps.html#ga184b42c4b42b91ef73e9ee50a1fa12c2">03259</a> <a class="code" href="group__DBusSysdeps.html#ga184b42c4b42b91ef73e9ee50a1fa12c2" title="Called when the bus daemon is signaled to reload its configuration; any caches should be nuked...">_dbus_flush_caches</a> (<span class="keywordtype">void</span>)
<a name="l03260"></a>03260 {
<a name="l03261"></a>03261 }
<a name="l03262"></a>03262 
<a name="l03269"></a>03269 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03270"></a><a class="code" href="group__DBusSysdeps.html#gaa03e5d4d95ef46a70d25fe315e674e24">03270</a> <a class="code" href="group__DBusSysdeps.html#gaa03e5d4d95ef46a70d25fe315e674e24" title="See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)...">_dbus_get_is_errno_eagain_or_ewouldblock</a> (<span class="keywordtype">void</span>)
<a name="l03271"></a>03271 {
<a name="l03272"></a>03272   <span class="keywordflow">return</span> errno == WSAEWOULDBLOCK;
<a name="l03273"></a>03273 }
<a name="l03274"></a>03274 
<a name="l03282"></a>03282 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03283"></a>03283 _dbus_get_install_root(<span class="keywordtype">char</span> *prefix, <span class="keywordtype">int</span> len)
<a name="l03284"></a>03284 {
<a name="l03285"></a>03285     <span class="comment">//To find the prefix, we cut the filename and also \bin\ if present</span>
<a name="l03286"></a>03286     DWORD pathLength;
<a name="l03287"></a>03287     <span class="keywordtype">char</span> *lastSlash;
<a name="l03288"></a>03288     SetLastError( 0 );
<a name="l03289"></a>03289     pathLength = GetModuleFileNameA(_dbus_win_get_dll_hmodule(), prefix, len);
<a name="l03290"></a>03290     <span class="keywordflow">if</span> ( pathLength == 0 || GetLastError() != 0 ) {
<a name="l03291"></a>03291         *prefix = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l03292"></a>03292         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03293"></a>03293     }
<a name="l03294"></a>03294     lastSlash = _mbsrchr(prefix, <span class="charliteral">&#39;\\&#39;</span>);
<a name="l03295"></a>03295     <span class="keywordflow">if</span> (lastSlash == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>) {
<a name="l03296"></a>03296         *prefix = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l03297"></a>03297         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03298"></a>03298     }
<a name="l03299"></a>03299     <span class="comment">//cut off binary name</span>
<a name="l03300"></a>03300     lastSlash[1] = 0;
<a name="l03301"></a>03301 
<a name="l03302"></a>03302     <span class="comment">//cut possible &quot;\\bin&quot;</span>
<a name="l03303"></a>03303 
<a name="l03304"></a>03304     <span class="comment">//this fails if we are in a double-byte system codepage and the</span>
<a name="l03305"></a>03305     <span class="comment">//folder&#39;s name happens to end with the *bytes*</span>
<a name="l03306"></a>03306     <span class="comment">//&quot;\\bin&quot;... (I.e. the second byte of some Han character and then</span>
<a name="l03307"></a>03307     <span class="comment">//the Latin &quot;bin&quot;, but that is not likely I think...</span>
<a name="l03308"></a>03308     <span class="keywordflow">if</span> (lastSlash - prefix &gt;= 4 &amp;&amp; strnicmp(lastSlash - 4, <span class="stringliteral">&quot;\\bin&quot;</span>, 4) == 0)
<a name="l03309"></a>03309         lastSlash[-3] = 0;
<a name="l03310"></a>03310     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (lastSlash - prefix &gt;= 10 &amp;&amp; strnicmp(lastSlash - 10, <span class="stringliteral">&quot;\\bin\\debug&quot;</span>, 10) == 0)
<a name="l03311"></a>03311         lastSlash[-9] = 0;
<a name="l03312"></a>03312     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (lastSlash - prefix &gt;= 12 &amp;&amp; strnicmp(lastSlash - 12, <span class="stringliteral">&quot;\\bin\\release&quot;</span>, 12) == 0)
<a name="l03313"></a>03313         lastSlash[-11] = 0;
<a name="l03314"></a>03314 
<a name="l03315"></a>03315     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03316"></a>03316 }
<a name="l03317"></a>03317 
<a name="l03331"></a>03331 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> 
<a name="l03332"></a>03332 _dbus_get_config_file_name(<a class="code" href="structDBusString.html">DBusString</a> *config_file, <span class="keywordtype">char</span> *s)
<a name="l03333"></a>03333 {
<a name="l03334"></a>03334   <span class="keywordtype">char</span> path[MAX_PATH*2];
<a name="l03335"></a>03335   <span class="keywordtype">int</span> path_size = <span class="keyword">sizeof</span>(path);
<a name="l03336"></a>03336 
<a name="l03337"></a>03337   <span class="keywordflow">if</span> (!_dbus_get_install_root(path,path_size))
<a name="l03338"></a>03338     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03339"></a>03339 
<a name="l03340"></a>03340   <span class="keywordflow">if</span>(strlen(s) + 4 + strlen(path) &gt; <span class="keyword">sizeof</span>(path)-2)
<a name="l03341"></a>03341     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03342"></a>03342   strcat(path,<span class="stringliteral">&quot;etc\\&quot;</span>);
<a name="l03343"></a>03343   strcat(path,s);
<a name="l03344"></a>03344   <span class="keywordflow">if</span> (<a class="code" href="group__DBusFile.html#ga13a527e32c05b63e8b32a63d728e20e8" title="File interface.">_dbus_file_exists</a>(path)) 
<a name="l03345"></a>03345     {
<a name="l03346"></a>03346       <span class="comment">// find path from executable </span>
<a name="l03347"></a>03347       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (config_file, path))
<a name="l03348"></a>03348         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03349"></a>03349     }
<a name="l03350"></a>03350   <span class="keywordflow">else</span> 
<a name="l03351"></a>03351     {
<a name="l03352"></a>03352       <span class="keywordflow">if</span> (!_dbus_get_install_root(path,path_size))
<a name="l03353"></a>03353         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03354"></a>03354       <span class="keywordflow">if</span>(strlen(s) + 11 + strlen(path) &gt; <span class="keyword">sizeof</span>(path)-2)
<a name="l03355"></a>03355         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03356"></a>03356       strcat(path,<span class="stringliteral">&quot;etc\\dbus-1\\&quot;</span>);
<a name="l03357"></a>03357       strcat(path,s);
<a name="l03358"></a>03358   
<a name="l03359"></a>03359       <span class="keywordflow">if</span> (<a class="code" href="group__DBusFile.html#ga13a527e32c05b63e8b32a63d728e20e8" title="File interface.">_dbus_file_exists</a>(path)) 
<a name="l03360"></a>03360         {
<a name="l03361"></a>03361           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (config_file, path))
<a name="l03362"></a>03362             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03363"></a>03363         }
<a name="l03364"></a>03364       <span class="keywordflow">else</span>
<a name="l03365"></a>03365         {
<a name="l03366"></a>03366           <span class="keywordflow">if</span> (!_dbus_get_install_root(path,path_size))
<a name="l03367"></a>03367             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03368"></a>03368           <span class="keywordflow">if</span>(strlen(s) + 4 + strlen(path) &gt; <span class="keyword">sizeof</span>(path)-2)
<a name="l03369"></a>03369             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03370"></a>03370           strcat(path,<span class="stringliteral">&quot;bus\\&quot;</span>);
<a name="l03371"></a>03371           strcat(path,s);
<a name="l03372"></a>03372           
<a name="l03373"></a>03373           <span class="keywordflow">if</span> (<a class="code" href="group__DBusFile.html#ga13a527e32c05b63e8b32a63d728e20e8" title="File interface.">_dbus_file_exists</a>(path)) 
<a name="l03374"></a>03374             {
<a name="l03375"></a>03375               <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (config_file, path))
<a name="l03376"></a>03376                 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03377"></a>03377             }
<a name="l03378"></a>03378         }
<a name="l03379"></a>03379     }
<a name="l03380"></a>03380   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03381"></a>03381 }    
<a name="l03382"></a>03382 
<a name="l03383"></a>03383 <span class="comment">/* See comment in dbus-sysdeps-unix.c */</span>
<a name="l03384"></a>03384 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03385"></a><a class="code" href="group__DBusSysdeps.html#gade479f90c1083346d74bc21af178d856">03385</a> <a class="code" href="group__DBusSysdeps.html#gade479f90c1083346d74bc21af178d856" title="Determines the address of the session bus by querying a platform-specific method.">_dbus_lookup_session_address</a> (<a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> *supported,
<a name="l03386"></a>03386                               <a class="code" href="structDBusString.html">DBusString</a>  *address,
<a name="l03387"></a>03387                               <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>   *error)
<a name="l03388"></a>03388 {
<a name="l03389"></a>03389   <span class="comment">/* Probably fill this in with something based on COM? */</span>
<a name="l03390"></a>03390   *supported = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03391"></a>03391   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03392"></a>03392 }
<a name="l03393"></a>03393 
<a name="l03407"></a>03407 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03408"></a><a class="code" href="group__DBusSysdeps.html#ga3cc5a5734416858fa58f3166ed181a64">03408</a> <a class="code" href="group__DBusSysdeps.html#ga3cc5a5734416858fa58f3166ed181a64" title="Appends the directory in which a keyring for the given credentials should be stored.">_dbus_append_keyring_directory_for_credentials</a> (<a class="code" href="structDBusString.html">DBusString</a>      *directory,
<a name="l03409"></a>03409                                                 <a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials)
<a name="l03410"></a>03410 {
<a name="l03411"></a>03411   <a class="code" href="structDBusString.html">DBusString</a> homedir;
<a name="l03412"></a>03412   <a class="code" href="structDBusString.html">DBusString</a> dotdir;
<a name="l03413"></a>03413   <span class="keyword">const</span> <span class="keywordtype">char</span> *homepath;
<a name="l03414"></a>03414   <span class="keyword">const</span> <span class="keywordtype">char</span> *homedrive;
<a name="l03415"></a>03415 
<a name="l03416"></a>03416   _dbus_assert (credentials != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03417"></a>03417   _dbus_assert (!<a class="code" href="group__DBusCredentials.html#gabfd7a1f681a91b45ba2f4e7461131827" title="Checks whether a credentials object contains a user identity.">_dbus_credentials_are_anonymous</a> (credentials));
<a name="l03418"></a>03418   
<a name="l03419"></a>03419   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;homedir))
<a name="l03420"></a>03420     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03421"></a>03421 
<a name="l03422"></a>03422   homedrive = <a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a>(<span class="stringliteral">&quot;HOMEDRIVE&quot;</span>);
<a name="l03423"></a>03423   <span class="keywordflow">if</span> (homedrive != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> &amp;&amp; *homedrive != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03424"></a>03424     {
<a name="l03425"></a>03425       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(&amp;homedir,homedrive);
<a name="l03426"></a>03426     }
<a name="l03427"></a>03427 
<a name="l03428"></a>03428   homepath = <a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a>(<span class="stringliteral">&quot;HOMEPATH&quot;</span>);
<a name="l03429"></a>03429   <span class="keywordflow">if</span> (homepath != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> &amp;&amp; *homepath != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03430"></a>03430     {
<a name="l03431"></a>03431       <a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(&amp;homedir,homepath);
<a name="l03432"></a>03432     }
<a name="l03433"></a>03433   
<a name="l03434"></a>03434 <span class="preprocessor">#ifdef DBUS_ENABLE_EMBEDDED_TESTS</span>
<a name="l03435"></a>03435 <span class="preprocessor"></span>  {
<a name="l03436"></a>03436     <span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keyword">override</span>;
<a name="l03437"></a>03437     
<a name="l03438"></a>03438     <span class="keyword">override</span> = <a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a> (<span class="stringliteral">&quot;DBUS_TEST_HOMEDIR&quot;</span>);
<a name="l03439"></a>03439     <span class="keywordflow">if</span> (<span class="keyword">override</span> != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> &amp;&amp; *<span class="keyword">override</span> != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03440"></a>03440       {
<a name="l03441"></a>03441         <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (&amp;homedir, 0);
<a name="l03442"></a>03442         <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (&amp;homedir, <span class="keyword">override</span>))
<a name="l03443"></a>03443           <span class="keywordflow">goto</span> failed;
<a name="l03444"></a>03444 
<a name="l03445"></a>03445         _dbus_verbose (<span class="stringliteral">&quot;Using fake homedir for testing: %s\n&quot;</span>,
<a name="l03446"></a>03446                        <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (&amp;homedir));
<a name="l03447"></a>03447       }
<a name="l03448"></a>03448     <span class="keywordflow">else</span>
<a name="l03449"></a>03449       {
<a name="l03450"></a>03450         <span class="comment">/* Not strictly thread-safe, but if we fail at thread-safety here,</span>
<a name="l03451"></a>03451 <span class="comment">         * the worst that will happen is some extra warnings. */</span>
<a name="l03452"></a>03452         <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> already_warned = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03453"></a>03453         <span class="keywordflow">if</span> (!already_warned)
<a name="l03454"></a>03454           {
<a name="l03455"></a>03455             <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid\n&quot;</span>);
<a name="l03456"></a>03456             already_warned = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03457"></a>03457           }
<a name="l03458"></a>03458       }
<a name="l03459"></a>03459   }
<a name="l03460"></a>03460 <span class="preprocessor">#endif</span>
<a name="l03461"></a>03461 <span class="preprocessor"></span>
<a name="l03462"></a>03462 <span class="preprocessor">#ifdef DBUS_WINCE</span>
<a name="l03463"></a>03463 <span class="preprocessor"></span>  <span class="comment">/* It&#39;s not possible to create a .something directory in Windows CE</span>
<a name="l03464"></a>03464 <span class="comment">     using the file explorer.  */</span>
<a name="l03465"></a>03465 <span class="preprocessor">#define KEYRING_DIR &quot;dbus-keyrings&quot;</span>
<a name="l03466"></a>03466 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l03467"></a>03467 <span class="preprocessor"></span><span class="preprocessor">#define KEYRING_DIR &quot;.dbus-keyrings&quot;</span>
<a name="l03468"></a>03468 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l03469"></a>03469 <span class="preprocessor"></span>
<a name="l03470"></a>03470   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;dotdir, KEYRING_DIR);
<a name="l03471"></a>03471   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d" title="Appends the given filename to the given directory.">_dbus_concat_dir_and_file</a> (&amp;homedir,
<a name="l03472"></a>03472                                   &amp;dotdir))
<a name="l03473"></a>03473     <span class="keywordflow">goto</span> failed;
<a name="l03474"></a>03474   
<a name="l03475"></a>03475   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga3c10f0d1bcaa3b450025b9c6a8b901d7" title="Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...">_dbus_string_copy</a> (&amp;homedir, 0,
<a name="l03476"></a>03476                           directory, <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (directory))) {
<a name="l03477"></a>03477     <span class="keywordflow">goto</span> failed;
<a name="l03478"></a>03478   }
<a name="l03479"></a>03479 
<a name="l03480"></a>03480   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;homedir);
<a name="l03481"></a>03481   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03482"></a>03482   
<a name="l03483"></a>03483  failed: 
<a name="l03484"></a>03484   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;homedir);
<a name="l03485"></a>03485   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03486"></a>03486 }
<a name="l03487"></a>03487 
<a name="l03493"></a>03493 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> 
<a name="l03494"></a><a class="code" href="group__DBusFile.html#ga13a527e32c05b63e8b32a63d728e20e8">03494</a> <a class="code" href="group__DBusFile.html#ga13a527e32c05b63e8b32a63d728e20e8" title="File interface.">_dbus_file_exists</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *file)
<a name="l03495"></a>03495 {
<a name="l03496"></a>03496   DWORD attributes = GetFileAttributesA (file);
<a name="l03497"></a>03497 
<a name="l03498"></a>03498   <span class="keywordflow">if</span> (attributes != INVALID_FILE_ATTRIBUTES &amp;&amp; GetLastError() != ERROR_PATH_NOT_FOUND)
<a name="l03499"></a>03499     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03500"></a>03500   <span class="keywordflow">else</span>
<a name="l03501"></a>03501     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;  
<a name="l03502"></a>03502 }
<a name="l03503"></a>03503 
<a name="l03511"></a>03511 <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l03512"></a>03512 _dbus_strerror (<span class="keywordtype">int</span> error_number)
<a name="l03513"></a>03513 {
<a name="l03514"></a>03514 <span class="preprocessor">#ifdef DBUS_WINCE</span>
<a name="l03515"></a>03515 <span class="preprocessor"></span>  <span class="comment">// TODO</span>
<a name="l03516"></a>03516   <span class="keywordflow">return</span> <span class="stringliteral">&quot;unknown&quot;</span>;
<a name="l03517"></a>03517 <span class="preprocessor">#else</span>
<a name="l03518"></a>03518 <span class="preprocessor"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span> *msg;
<a name="l03519"></a>03519 
<a name="l03520"></a>03520   <span class="keywordflow">switch</span> (error_number)
<a name="l03521"></a>03521     {
<a name="l03522"></a>03522     <span class="keywordflow">case</span> WSAEINTR:
<a name="l03523"></a>03523       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Interrupted function call&quot;</span>;
<a name="l03524"></a>03524     <span class="keywordflow">case</span> WSAEACCES:
<a name="l03525"></a>03525       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Permission denied&quot;</span>;
<a name="l03526"></a>03526     <span class="keywordflow">case</span> WSAEFAULT:
<a name="l03527"></a>03527       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Bad address&quot;</span>;
<a name="l03528"></a>03528     <span class="keywordflow">case</span> WSAEINVAL:
<a name="l03529"></a>03529       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Invalid argument&quot;</span>;
<a name="l03530"></a>03530     <span class="keywordflow">case</span> WSAEMFILE:
<a name="l03531"></a>03531       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Too many open files&quot;</span>;
<a name="l03532"></a>03532     <span class="keywordflow">case</span> WSAEWOULDBLOCK:
<a name="l03533"></a>03533       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Resource temporarily unavailable&quot;</span>;
<a name="l03534"></a>03534     <span class="keywordflow">case</span> WSAEINPROGRESS:
<a name="l03535"></a>03535       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Operation now in progress&quot;</span>;
<a name="l03536"></a>03536     <span class="keywordflow">case</span> WSAEALREADY:
<a name="l03537"></a>03537       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Operation already in progress&quot;</span>;
<a name="l03538"></a>03538     <span class="keywordflow">case</span> WSAENOTSOCK:
<a name="l03539"></a>03539       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Socket operation on nonsocket&quot;</span>;
<a name="l03540"></a>03540     <span class="keywordflow">case</span> WSAEDESTADDRREQ:
<a name="l03541"></a>03541       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Destination address required&quot;</span>;
<a name="l03542"></a>03542     <span class="keywordflow">case</span> WSAEMSGSIZE:
<a name="l03543"></a>03543       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Message too long&quot;</span>;
<a name="l03544"></a>03544     <span class="keywordflow">case</span> WSAEPROTOTYPE:
<a name="l03545"></a>03545       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Protocol wrong type for socket&quot;</span>;
<a name="l03546"></a>03546     <span class="keywordflow">case</span> WSAENOPROTOOPT:
<a name="l03547"></a>03547       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Bad protocol option&quot;</span>;
<a name="l03548"></a>03548     <span class="keywordflow">case</span> WSAEPROTONOSUPPORT:
<a name="l03549"></a>03549       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Protocol not supported&quot;</span>;
<a name="l03550"></a>03550     <span class="keywordflow">case</span> WSAESOCKTNOSUPPORT:
<a name="l03551"></a>03551       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Socket type not supported&quot;</span>;
<a name="l03552"></a>03552     <span class="keywordflow">case</span> WSAEOPNOTSUPP:
<a name="l03553"></a>03553       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Operation not supported&quot;</span>;
<a name="l03554"></a>03554     <span class="keywordflow">case</span> WSAEPFNOSUPPORT:
<a name="l03555"></a>03555       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Protocol family not supported&quot;</span>;
<a name="l03556"></a>03556     <span class="keywordflow">case</span> WSAEAFNOSUPPORT:
<a name="l03557"></a>03557       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Address family not supported by protocol family&quot;</span>;
<a name="l03558"></a>03558     <span class="keywordflow">case</span> WSAEADDRINUSE:
<a name="l03559"></a>03559       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Address already in use&quot;</span>;
<a name="l03560"></a>03560     <span class="keywordflow">case</span> WSAEADDRNOTAVAIL:
<a name="l03561"></a>03561       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Cannot assign requested address&quot;</span>;
<a name="l03562"></a>03562     <span class="keywordflow">case</span> WSAENETDOWN:
<a name="l03563"></a>03563       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Network is down&quot;</span>;
<a name="l03564"></a>03564     <span class="keywordflow">case</span> WSAENETUNREACH:
<a name="l03565"></a>03565       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Network is unreachable&quot;</span>;
<a name="l03566"></a>03566     <span class="keywordflow">case</span> WSAENETRESET:
<a name="l03567"></a>03567       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Network dropped connection on reset&quot;</span>;
<a name="l03568"></a>03568     <span class="keywordflow">case</span> WSAECONNABORTED:
<a name="l03569"></a>03569       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Software caused connection abort&quot;</span>;
<a name="l03570"></a>03570     <span class="keywordflow">case</span> WSAECONNRESET:
<a name="l03571"></a>03571       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Connection reset by peer&quot;</span>;
<a name="l03572"></a>03572     <span class="keywordflow">case</span> WSAENOBUFS:
<a name="l03573"></a>03573       <span class="keywordflow">return</span> <span class="stringliteral">&quot;No buffer space available&quot;</span>;
<a name="l03574"></a>03574     <span class="keywordflow">case</span> WSAEISCONN:
<a name="l03575"></a>03575       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Socket is already connected&quot;</span>;
<a name="l03576"></a>03576     <span class="keywordflow">case</span> WSAENOTCONN:
<a name="l03577"></a>03577       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Socket is not connected&quot;</span>;
<a name="l03578"></a>03578     <span class="keywordflow">case</span> WSAESHUTDOWN:
<a name="l03579"></a>03579       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Cannot send after socket shutdown&quot;</span>;
<a name="l03580"></a>03580     <span class="keywordflow">case</span> WSAETIMEDOUT:
<a name="l03581"></a>03581       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Connection timed out&quot;</span>;
<a name="l03582"></a>03582     <span class="keywordflow">case</span> WSAECONNREFUSED:
<a name="l03583"></a>03583       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Connection refused&quot;</span>;
<a name="l03584"></a>03584     <span class="keywordflow">case</span> WSAEHOSTDOWN:
<a name="l03585"></a>03585       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Host is down&quot;</span>;
<a name="l03586"></a>03586     <span class="keywordflow">case</span> WSAEHOSTUNREACH:
<a name="l03587"></a>03587       <span class="keywordflow">return</span> <span class="stringliteral">&quot;No route to host&quot;</span>;
<a name="l03588"></a>03588     <span class="keywordflow">case</span> WSAEPROCLIM:
<a name="l03589"></a>03589       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Too many processes&quot;</span>;
<a name="l03590"></a>03590     <span class="keywordflow">case</span> WSAEDISCON:
<a name="l03591"></a>03591       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Graceful shutdown in progress&quot;</span>;
<a name="l03592"></a>03592     <span class="keywordflow">case</span> WSATYPE_NOT_FOUND:
<a name="l03593"></a>03593       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Class type not found&quot;</span>;
<a name="l03594"></a>03594     <span class="keywordflow">case</span> WSAHOST_NOT_FOUND:
<a name="l03595"></a>03595       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Host not found&quot;</span>;
<a name="l03596"></a>03596     <span class="keywordflow">case</span> WSATRY_AGAIN:
<a name="l03597"></a>03597       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Nonauthoritative host not found&quot;</span>;
<a name="l03598"></a>03598     <span class="keywordflow">case</span> WSANO_RECOVERY:
<a name="l03599"></a>03599       <span class="keywordflow">return</span> <span class="stringliteral">&quot;This is a nonrecoverable error&quot;</span>;
<a name="l03600"></a>03600     <span class="keywordflow">case</span> WSANO_DATA:
<a name="l03601"></a>03601       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Valid name, no data record of requested type&quot;</span>;
<a name="l03602"></a>03602     <span class="keywordflow">case</span> WSA_INVALID_HANDLE:
<a name="l03603"></a>03603       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Specified event object handle is invalid&quot;</span>;
<a name="l03604"></a>03604     <span class="keywordflow">case</span> WSA_INVALID_PARAMETER:
<a name="l03605"></a>03605       <span class="keywordflow">return</span> <span class="stringliteral">&quot;One or more parameters are invalid&quot;</span>;
<a name="l03606"></a>03606     <span class="keywordflow">case</span> WSA_IO_INCOMPLETE:
<a name="l03607"></a>03607       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Overlapped I/O event object not in signaled state&quot;</span>;
<a name="l03608"></a>03608     <span class="keywordflow">case</span> WSA_IO_PENDING:
<a name="l03609"></a>03609       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Overlapped operations will complete later&quot;</span>;
<a name="l03610"></a>03610     <span class="keywordflow">case</span> WSA_NOT_ENOUGH_MEMORY:
<a name="l03611"></a>03611       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Insufficient memory available&quot;</span>;
<a name="l03612"></a>03612     <span class="keywordflow">case</span> WSA_OPERATION_ABORTED:
<a name="l03613"></a>03613       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Overlapped operation aborted&quot;</span>;
<a name="l03614"></a>03614 <span class="preprocessor">#ifdef WSAINVALIDPROCTABLE</span>
<a name="l03615"></a>03615 <span class="preprocessor"></span>
<a name="l03616"></a>03616     <span class="keywordflow">case</span> WSAINVALIDPROCTABLE:
<a name="l03617"></a>03617       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Invalid procedure table from service provider&quot;</span>;
<a name="l03618"></a>03618 <span class="preprocessor">#endif</span>
<a name="l03619"></a>03619 <span class="preprocessor"></span><span class="preprocessor">#ifdef WSAINVALIDPROVIDER</span>
<a name="l03620"></a>03620 <span class="preprocessor"></span>
<a name="l03621"></a>03621     <span class="keywordflow">case</span> WSAINVALIDPROVIDER:
<a name="l03622"></a>03622       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Invalid service provider version number&quot;</span>;
<a name="l03623"></a>03623 <span class="preprocessor">#endif</span>
<a name="l03624"></a>03624 <span class="preprocessor"></span><span class="preprocessor">#ifdef WSAPROVIDERFAILEDINIT</span>
<a name="l03625"></a>03625 <span class="preprocessor"></span>
<a name="l03626"></a>03626     <span class="keywordflow">case</span> WSAPROVIDERFAILEDINIT:
<a name="l03627"></a>03627       <span class="keywordflow">return</span> <span class="stringliteral">&quot;Unable to initialize a service provider&quot;</span>;
<a name="l03628"></a>03628 <span class="preprocessor">#endif</span>
<a name="l03629"></a>03629 <span class="preprocessor"></span>
<a name="l03630"></a>03630     <span class="keywordflow">case</span> WSASYSCALLFAILURE:
<a name="l03631"></a>03631       <span class="keywordflow">return</span> <span class="stringliteral">&quot;System call failure&quot;</span>;
<a name="l03632"></a>03632     }
<a name="l03633"></a>03633   msg = strerror (error_number);
<a name="l03634"></a>03634   <span class="keywordflow">if</span> (msg == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03635"></a>03635     msg = <span class="stringliteral">&quot;unknown&quot;</span>;
<a name="l03636"></a>03636 
<a name="l03637"></a>03637   <span class="keywordflow">return</span> msg;
<a name="l03638"></a>03638 <span class="preprocessor">#endif //DBUS_WINCE</span>
<a name="l03639"></a>03639 <span class="preprocessor"></span>}
<a name="l03640"></a>03640 
<a name="l03648"></a>03648 <span class="keywordtype">void</span>
<a name="l03649"></a>03649 _dbus_win_set_error_from_win_error (<a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error,
<a name="l03650"></a>03650                                     <span class="keywordtype">int</span>        code)
<a name="l03651"></a>03651 {
<a name="l03652"></a>03652   <span class="keywordtype">char</span> *msg;
<a name="l03653"></a>03653 
<a name="l03654"></a>03654   <span class="comment">/* As we want the English message, use the A API */</span>
<a name="l03655"></a>03655   FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
<a name="l03656"></a>03656                   FORMAT_MESSAGE_IGNORE_INSERTS |
<a name="l03657"></a>03657                   FORMAT_MESSAGE_FROM_SYSTEM,
<a name="l03658"></a>03658                   <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, code, MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US),
<a name="l03659"></a>03659                   (LPSTR) &amp;msg, 0, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03660"></a>03660   <span class="keywordflow">if</span> (msg)
<a name="l03661"></a>03661     {
<a name="l03662"></a>03662       <span class="keywordtype">char</span> *msg_copy;
<a name="l03663"></a>03663 
<a name="l03664"></a>03664       msg_copy = <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (strlen (msg));
<a name="l03665"></a>03665       strcpy (msg_copy, msg);
<a name="l03666"></a>03666       LocalFree (msg);
<a name="l03667"></a>03667 
<a name="l03668"></a>03668       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <span class="stringliteral">&quot;win32.error&quot;</span>, <span class="stringliteral">&quot;%s&quot;</span>, msg_copy);
<a name="l03669"></a>03669     }
<a name="l03670"></a>03670   <span class="keywordflow">else</span>
<a name="l03671"></a>03671     <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <span class="stringliteral">&quot;win32.error&quot;</span>, <span class="stringliteral">&quot;Unknown error code %d or FormatMessage failed&quot;</span>, code);
<a name="l03672"></a>03672 }
<a name="l03673"></a>03673 
<a name="l03674"></a>03674 <span class="keywordtype">void</span>
<a name="l03675"></a>03675 _dbus_win_warn_win_error (<span class="keyword">const</span> <span class="keywordtype">char</span> *message,
<a name="l03676"></a>03676                           <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> code)
<a name="l03677"></a>03677 {
<a name="l03678"></a>03678   <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> error;
<a name="l03679"></a>03679 
<a name="l03680"></a>03680   <a class="code" href="group__DBusErrors.html#ga8937f0b7cdf8554fa6305158ce453fbe" title="Initializes a DBusError structure.">dbus_error_init</a> (&amp;error);
<a name="l03681"></a>03681   _dbus_win_set_error_from_win_error (&amp;error, code);
<a name="l03682"></a>03682   <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;%s: %s\n&quot;</span>, message, error.<a class="code" href="structDBusError.html#afb559175326de5b6b340e26204e92d72" title="public error message field">message</a>);
<a name="l03683"></a>03683   <a class="code" href="group__DBusErrors.html#gaac6c14ead14829ee4e090f39de6a7568" title="Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...">dbus_error_free</a> (&amp;error);
<a name="l03684"></a>03684 }
<a name="l03685"></a>03685 
<a name="l03693"></a>03693 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03694"></a><a class="code" href="group__DBusSysdeps.html#ga3bc1512aef42cea17a2aaacc7d8e7211">03694</a> <a class="code" href="group__DBusSysdeps.html#ga3bc1512aef42cea17a2aaacc7d8e7211" title="Removes a directory; Directory must be empty.">_dbus_delete_directory</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l03695"></a>03695                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l03696"></a>03696 {
<a name="l03697"></a>03697   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l03698"></a>03698 
<a name="l03699"></a>03699   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03700"></a>03700 
<a name="l03701"></a>03701   filename_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (filename);
<a name="l03702"></a>03702 
<a name="l03703"></a>03703   <span class="keywordflow">if</span> (RemoveDirectoryA (filename_c) == 0)
<a name="l03704"></a>03704     {
<a name="l03705"></a>03705       <span class="keywordtype">char</span> *emsg = _dbus_win_error_string (GetLastError ());
<a name="l03706"></a>03706       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, _dbus_win_error_from_last_error (),
<a name="l03707"></a>03707                       <span class="stringliteral">&quot;Failed to remove directory %s: %s&quot;</span>,
<a name="l03708"></a>03708                       filename_c, emsg);
<a name="l03709"></a>03709       _dbus_win_free_error_string (emsg);
<a name="l03710"></a>03710       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03711"></a>03711     }
<a name="l03712"></a>03712 
<a name="l03713"></a>03713   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03714"></a>03714 }
<a name="l03715"></a>03715 
<a name="l03722"></a>03722 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03723"></a><a class="code" href="group__DBusSysdeps.html#ga6d80876bcae54f47cde79d0bce20321d">03723</a> <a class="code" href="group__DBusInternalsUtils.html#ga6d80876bcae54f47cde79d0bce20321d" title="Checks whether the filename is an absolute path.">_dbus_path_is_absolute</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename)
<a name="l03724"></a>03724 {
<a name="l03725"></a>03725   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (filename) &gt; 0)
<a name="l03726"></a>03726     <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (filename, 1) == <span class="charliteral">&#39;:&#39;</span>
<a name="l03727"></a>03727            || <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (filename, 0) == <span class="charliteral">&#39;\\&#39;</span>
<a name="l03728"></a>03728            || <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (filename, 0) == <span class="charliteral">&#39;/&#39;</span>;
<a name="l03729"></a>03729   <span class="keywordflow">else</span>
<a name="l03730"></a>03730     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03731"></a>03731 }
<a name="l03732"></a>03732 
<a name="l03733"></a>03733 
<a name="l03735"></a>03735 <span class="comment">/* tests in dbus-sysdeps-util.c */</span>
<a name="l03736"></a>03736 
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Mar 3 2016 17:50:31 for D-Bus by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>