@@ -1452,6 +1452,49 @@ _winapi_GetLastError_impl(PyObject *module)
14521452 return GetLastError ();
14531453}
14541454
1455+
1456+ /*[clinic input]
1457+ _winapi.GetLongPathName
1458+
1459+ path: LPCWSTR
1460+
1461+ Return the long version of the provided path.
1462+
1463+ If the path is already in its long form, returns the same value.
1464+
1465+ The path must already be a 'str'. If the type is not known, use
1466+ os.fsdecode before calling this function.
1467+ [clinic start generated code]*/
1468+
1469+ static PyObject *
1470+ _winapi_GetLongPathName_impl (PyObject * module , LPCWSTR path )
1471+ /*[clinic end generated code: output=c4774b080275a2d0 input=9872e211e3a4a88f]*/
1472+ {
1473+ DWORD cchBuffer ;
1474+ PyObject * result = NULL ;
1475+
1476+ Py_BEGIN_ALLOW_THREADS
1477+ cchBuffer = GetLongPathNameW (path , NULL , 0 );
1478+ Py_END_ALLOW_THREADS
1479+ if (cchBuffer ) {
1480+ WCHAR * buffer = (WCHAR * )PyMem_Malloc (cchBuffer * sizeof (WCHAR ));
1481+ if (buffer ) {
1482+ Py_BEGIN_ALLOW_THREADS
1483+ cchBuffer = GetLongPathNameW (path , buffer , cchBuffer );
1484+ Py_END_ALLOW_THREADS
1485+ if (cchBuffer ) {
1486+ result = PyUnicode_FromWideChar (buffer , cchBuffer );
1487+ } else {
1488+ PyErr_SetFromWindowsErr (0 );
1489+ }
1490+ PyMem_Free ((void * )buffer );
1491+ }
1492+ } else {
1493+ PyErr_SetFromWindowsErr (0 );
1494+ }
1495+ return result ;
1496+ }
1497+
14551498/*[clinic input]
14561499_winapi.GetModuleFileName
14571500
@@ -1486,6 +1529,48 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
14861529 return PyUnicode_FromWideChar (filename , wcslen (filename ));
14871530}
14881531
1532+ /*[clinic input]
1533+ _winapi.GetShortPathName
1534+
1535+ path: LPCWSTR
1536+
1537+ Return the short version of the provided path.
1538+
1539+ If the path is already in its short form, returns the same value.
1540+
1541+ The path must already be a 'str'. If the type is not known, use
1542+ os.fsdecode before calling this function.
1543+ [clinic start generated code]*/
1544+
1545+ static PyObject *
1546+ _winapi_GetShortPathName_impl (PyObject * module , LPCWSTR path )
1547+ /*[clinic end generated code: output=dab6ae494c621e81 input=43fa349aaf2ac718]*/
1548+ {
1549+ DWORD cchBuffer ;
1550+ PyObject * result = NULL ;
1551+
1552+ Py_BEGIN_ALLOW_THREADS
1553+ cchBuffer = GetShortPathNameW (path , NULL , 0 );
1554+ Py_END_ALLOW_THREADS
1555+ if (cchBuffer ) {
1556+ WCHAR * buffer = (WCHAR * )PyMem_Malloc (cchBuffer * sizeof (WCHAR ));
1557+ if (buffer ) {
1558+ Py_BEGIN_ALLOW_THREADS
1559+ cchBuffer = GetShortPathNameW (path , buffer , cchBuffer );
1560+ Py_END_ALLOW_THREADS
1561+ if (cchBuffer ) {
1562+ result = PyUnicode_FromWideChar (buffer , cchBuffer );
1563+ } else {
1564+ PyErr_SetFromWindowsErr (0 );
1565+ }
1566+ PyMem_Free ((void * )buffer );
1567+ }
1568+ } else {
1569+ PyErr_SetFromWindowsErr (0 );
1570+ }
1571+ return result ;
1572+ }
1573+
14891574/*[clinic input]
14901575_winapi.GetStdHandle -> HANDLE
14911576
@@ -2345,7 +2430,9 @@ static PyMethodDef winapi_functions[] = {
23452430 _WINAPI_GETCURRENTPROCESS_METHODDEF
23462431 _WINAPI_GETEXITCODEPROCESS_METHODDEF
23472432 _WINAPI_GETLASTERROR_METHODDEF
2433+ _WINAPI_GETLONGPATHNAME_METHODDEF
23482434 _WINAPI_GETMODULEFILENAME_METHODDEF
2435+ _WINAPI_GETSHORTPATHNAME_METHODDEF
23492436 _WINAPI_GETSTDHANDLE_METHODDEF
23502437 _WINAPI_GETVERSION_METHODDEF
23512438 _WINAPI_MAPVIEWOFFILE_METHODDEF
0 commit comments