summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-11-28 23:59:46 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-11-28 23:59:46 (GMT)
commitfc889c48edc17b9502c0aef416ce2d003dbef4e6 (patch)
tree88f633faaa267ca02024a06cae0849924bbfe730 /Modules/posixmodule.c
parent1de911592ee52affd6b855d7325af46559f23407 (diff)
downloadcpython-fc889c48edc17b9502c0aef416ce2d003dbef4e6.zip
cpython-fc889c48edc17b9502c0aef416ce2d003dbef4e6.tar.gz
cpython-fc889c48edc17b9502c0aef416ce2d003dbef4e6.tar.bz2
Fix for #8879.
Amaury noticed that this was originally written in a way that would fail on names that can't be encoded with the mbcs codec. Restructured the function to work with wide names first then narrow names second, to fall in line with the way other functions are written in posixmodule.c.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 3197a0d..48dbaa5 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2252,6 +2252,22 @@ win32_link(PyObject *self, PyObject *args)
char *src, *dst;
BOOL rslt;
+ PyUnicodeObject *usrc, *udst;
+ if (PyArg_ParseTuple(args, "UU:link", &usrc, &udst)) {
+ Py_BEGIN_ALLOW_THREADS
+ rslt = CreateHardLinkW(PyUnicode_AS_UNICODE(udst),
+ PyUnicode_AS_UNICODE(usrc), NULL);
+ Py_END_ALLOW_THREADS
+
+ if (rslt == 0)
+ return win32_error("link", NULL);
+
+ Py_RETURN_NONE;
+ }
+
+ /* Narrow strings also valid. */
+ PyErr_Clear();
+
if (!PyArg_ParseTuple(args, "O&O&:link", PyUnicode_FSConverter, &osrc,
PyUnicode_FSConverter, &odst))
return NULL;
@@ -2260,13 +2276,13 @@ win32_link(PyObject *self, PyObject *args)
dst = PyBytes_AsString(odst);
Py_BEGIN_ALLOW_THREADS
- rslt = CreateHardLink(dst, src, NULL);
+ rslt = CreateHardLinkA(dst, src, NULL);
Py_END_ALLOW_THREADS
Py_DECREF(osrc);
Py_DECREF(odst);
if (rslt == 0)
- return posix_error();
+ return win32_error("link", NULL);
Py_RETURN_NONE;
}