fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwi / helper / networkdomain.cxx
blobbbb2a1526b0d69dea1f62798607ab44595cec40d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <helper/networkdomain.hxx>
22 #ifdef WNT
24 // Windows
26 #define UNICODE
27 #if defined _MSC_VER
28 #pragma warning(push, 1)
29 #endif
30 #include <windows.h>
31 #if defined _MSC_VER
32 #pragma warning(pop)
33 #endif
35 static DWORD WINAPI GetUserDomainW_NT( LPWSTR lpBuffer, DWORD nSize )
37 return GetEnvironmentVariable( TEXT("USERDOMAIN"), lpBuffer, nSize );
40 static OUString GetUserDomain()
42 sal_Unicode aBuffer[256];
43 DWORD nResult;
45 nResult = GetUserDomainW_NT( reinterpret_cast<LPWSTR>(aBuffer), sizeof( aBuffer ) );
47 if ( nResult > 0 )
48 return OUString( aBuffer );
49 else
50 return OUString();
53 // Windows
55 namespace framework
58 OUString NetworkDomain::GetYPDomainName()
60 return OUString();
63 OUString NetworkDomain::GetNTDomainName()
65 return GetUserDomain();
70 #elif defined( UNIX )
72 #include <rtl/ustring.h>
73 #include <stdlib.h>
74 #include <errno.h>
75 #include <osl/thread.h>
77 // Unix
79 #if defined( SOLARIS )
81 // Solaris
83 #include <sys/systeminfo.h>
84 #include <sal/alloca.h>
86 static rtl_uString *getDomainName()
88 /* Initialize and assume failure */
89 rtl_uString *ustrDomainName = NULL;
91 char szBuffer[256];
93 long nCopied = sizeof(szBuffer);
94 char *pBuffer = szBuffer;
95 long nBufSize;
99 nBufSize = nCopied;
100 nCopied = sysinfo( SI_SRPC_DOMAIN, pBuffer, nBufSize );
102 /* If nCopied is greater than buffersize we need to allocate
103 a buffer with suitable size */
105 if ( nCopied > nBufSize )
106 pBuffer = (char *)alloca( nCopied );
108 } while ( nCopied > nBufSize );
110 if ( -1 != nCopied )
112 rtl_string2UString(
113 &ustrDomainName,
114 pBuffer,
115 nCopied - 1,
116 osl_getThreadTextEncoding(),
117 OSTRING_TO_OUSTRING_CVTFLAGS );
120 return ustrDomainName;
123 #elif defined( LINUX ) /* endif SOLARIS */
125 // Linux
127 #include <unistd.h>
128 #include <string.h>
130 static rtl_uString *getDomainName()
132 /* Initialize and assume failure */
133 rtl_uString *ustrDomainName = NULL;
135 char *pBuffer;
136 int result;
137 size_t nBufSize = 0;
141 nBufSize += 256; /* Increase buffer size by steps of 256 bytes */
142 pBuffer = static_cast<char *>(alloca( nBufSize ));
143 result = getdomainname( pBuffer, nBufSize );
144 /* If buffersize in not large enough -1 is returned and errno
145 is set to EINVAL. This only applies to libc. With glibc the name
146 is truncated. */
147 } while ( -1 == result && EINVAL == errno );
149 if ( 0 == result )
151 rtl_string2UString(
152 &ustrDomainName,
153 pBuffer,
154 strlen( pBuffer ),
155 osl_getThreadTextEncoding(),
156 OSTRING_TO_OUSTRING_CVTFLAGS );
159 return ustrDomainName;
162 #else /* LINUX */
164 // Other Unix
166 static rtl_uString *getDomainName()
168 return NULL;
171 #endif
173 // Unix
175 namespace framework
178 OUString NetworkDomain::GetYPDomainName()
180 rtl_uString* pResult = getDomainName();
181 if ( pResult )
182 return OUString( pResult );
183 else
184 return OUString();
187 OUString NetworkDomain::GetNTDomainName()
189 return OUString();
194 #else /* UNIX */
196 // Other operating systems (non-Windows and non-Unix)
198 namespace framework
201 OUString NetworkDomain::GetYPDomainName()
203 return OUString();
206 OUString NetworkDomain::GetNTDomainName()
208 return OUString();
213 #endif
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */