@@ -1517,6 +1517,49 @@ _winapi_GetLastError_impl(PyObject *module)
1517
1517
return GetLastError ();
1518
1518
}
1519
1519
1520
+
1521
+ /*[clinic input]
1522
+ _winapi.GetLongPathName
1523
+
1524
+ path: LPCWSTR
1525
+
1526
+ Return the long version of the provided path.
1527
+
1528
+ If the path is already in its long form, returns the same value.
1529
+
1530
+ The path must already be a 'str'. If the type is not known, use
1531
+ os.fsdecode before calling this function.
1532
+ [clinic start generated code]*/
1533
+
1534
+ static PyObject *
1535
+ _winapi_GetLongPathName_impl (PyObject * module , LPCWSTR path )
1536
+ /*[clinic end generated code: output=c4774b080275a2d0 input=9872e211e3a4a88f]*/
1537
+ {
1538
+ DWORD cchBuffer ;
1539
+ PyObject * result = NULL ;
1540
+
1541
+ Py_BEGIN_ALLOW_THREADS
1542
+ cchBuffer = GetLongPathNameW (path , NULL , 0 );
1543
+ Py_END_ALLOW_THREADS
1544
+ if (cchBuffer ) {
1545
+ WCHAR * buffer = (WCHAR * )PyMem_Malloc (cchBuffer * sizeof (WCHAR ));
1546
+ if (buffer ) {
1547
+ Py_BEGIN_ALLOW_THREADS
1548
+ cchBuffer = GetLongPathNameW (path , buffer , cchBuffer );
1549
+ Py_END_ALLOW_THREADS
1550
+ if (cchBuffer ) {
1551
+ result = PyUnicode_FromWideChar (buffer , cchBuffer );
1552
+ } else {
1553
+ PyErr_SetFromWindowsErr (0 );
1554
+ }
1555
+ PyMem_Free ((void * )buffer );
1556
+ }
1557
+ } else {
1558
+ PyErr_SetFromWindowsErr (0 );
1559
+ }
1560
+ return result ;
1561
+ }
1562
+
1520
1563
/*[clinic input]
1521
1564
_winapi.GetModuleFileName
1522
1565
@@ -1551,6 +1594,48 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
1551
1594
return PyUnicode_FromWideChar (filename , wcslen (filename ));
1552
1595
}
1553
1596
1597
+ /*[clinic input]
1598
+ _winapi.GetShortPathName
1599
+
1600
+ path: LPCWSTR
1601
+
1602
+ Return the short version of the provided path.
1603
+
1604
+ If the path is already in its short form, returns the same value.
1605
+
1606
+ The path must already be a 'str'. If the type is not known, use
1607
+ os.fsdecode before calling this function.
1608
+ [clinic start generated code]*/
1609
+
1610
+ static PyObject *
1611
+ _winapi_GetShortPathName_impl (PyObject * module , LPCWSTR path )
1612
+ /*[clinic end generated code: output=dab6ae494c621e81 input=43fa349aaf2ac718]*/
1613
+ {
1614
+ DWORD cchBuffer ;
1615
+ PyObject * result = NULL ;
1616
+
1617
+ Py_BEGIN_ALLOW_THREADS
1618
+ cchBuffer = GetShortPathNameW (path , NULL , 0 );
1619
+ Py_END_ALLOW_THREADS
1620
+ if (cchBuffer ) {
1621
+ WCHAR * buffer = (WCHAR * )PyMem_Malloc (cchBuffer * sizeof (WCHAR ));
1622
+ if (buffer ) {
1623
+ Py_BEGIN_ALLOW_THREADS
1624
+ cchBuffer = GetShortPathNameW (path , buffer , cchBuffer );
1625
+ Py_END_ALLOW_THREADS
1626
+ if (cchBuffer ) {
1627
+ result = PyUnicode_FromWideChar (buffer , cchBuffer );
1628
+ } else {
1629
+ PyErr_SetFromWindowsErr (0 );
1630
+ }
1631
+ PyMem_Free ((void * )buffer );
1632
+ }
1633
+ } else {
1634
+ PyErr_SetFromWindowsErr (0 );
1635
+ }
1636
+ return result ;
1637
+ }
1638
+
1554
1639
/*[clinic input]
1555
1640
_winapi.GetStdHandle -> HANDLE
1556
1641
@@ -2846,7 +2931,9 @@ static PyMethodDef winapi_functions[] = {
2846
2931
_WINAPI_GETCURRENTPROCESS_METHODDEF
2847
2932
_WINAPI_GETEXITCODEPROCESS_METHODDEF
2848
2933
_WINAPI_GETLASTERROR_METHODDEF
2934
+ _WINAPI_GETLONGPATHNAME_METHODDEF
2849
2935
_WINAPI_GETMODULEFILENAME_METHODDEF
2936
+ _WINAPI_GETSHORTPATHNAME_METHODDEF
2850
2937
_WINAPI_GETSTDHANDLE_METHODDEF
2851
2938
_WINAPI_GETVERSION_METHODDEF
2852
2939
_WINAPI_MAPVIEWOFFILE_METHODDEF
0 commit comments