Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
72f48422
Commit
72f48422
authored
Oct 29, 2010
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #9377: Use Unicode API for gethostname on Windows.
parent
83432bab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/socketmodule.c
Modules/socketmodule.c
+22
-0
No files found.
Misc/NEWS
View file @
72f48422
...
...
@@ -160,6 +160,8 @@ Library
Extensions
----------
- Issue #9377: Use Unicode API for gethostname on Windows.
- Issue #10143: Update "os.pathconf" values.
- Issue #6518: Support context manager protcol for ossaudiodev types.
...
...
Modules/socketmodule.c
View file @
72f48422
...
...
@@ -3093,6 +3093,27 @@ static PyTypeObject sock_type = {
static
PyObject
*
socket_gethostname
(
PyObject
*
self
,
PyObject
*
unused
)
{
#ifdef MS_WINDOWS
/* Don't use winsock's gethostname, as this returns the ANSI
version of the hostname, whereas we need a Unicode string.
Otherwise, gethostname apparently also returns the DNS name. */
wchar_t
buf
[
MAX_COMPUTERNAME_LENGTH
];
DWORD
size
=
sizeof
(
buf
);
if
(
!
GetComputerNameExW
(
ComputerNamePhysicalDnsHostname
,
buf
,
&
size
))
{
if
(
GetLastError
()
==
ERROR_MORE_DATA
)
{
/* MSDN says this may occur "because DNS allows longer names */
PyObject
*
result
=
PyUnicode_FromUnicode
(
NULL
,
size
);
if
(
!
result
)
return
NULL
;
if
(
GetComputerName
(
ComputerNamePhysicalDnsHostname
,
PyUnicode_AS_UNICODE
(
result
),
size
+
1
))
return
result
;
}
return
PyErr_SetExcFromWindowsErr
(
PyExc_WindowsError
,
GetLastError
());
}
return
PyUnicode_FromUnicode
(
buf
,
size
);
#else
char
buf
[
1024
];
int
res
;
Py_BEGIN_ALLOW_THREADS
...
...
@@ -3102,6 +3123,7 @@ socket_gethostname(PyObject *self, PyObject *unused)
return
set_error
();
buf
[
sizeof
buf
-
1
]
=
'\0'
;
return
PyUnicode_FromString
(
buf
);
#endif
}
PyDoc_STRVAR
(
gethostname_doc
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment