@@ -7414,28 +7414,41 @@ If dir_fd is not None, it should be a file descriptor open to a directory,\n\
7414
7414
and path should be relative; path will then be relative to that directory.\n\
7415
7415
dir_fd may not be implemented on your platform.\n\
7416
7416
If it is unavailable, using it will raise a NotImplementedError." );
7417
- #endif
7418
-
7419
- #ifdef HAVE_READLINK
7420
7417
7421
- /* AC 3.5: merge win32 and not together */
7422
7418
static PyObject *
7423
7419
posix_readlink (PyObject * self , PyObject * args , PyObject * kwargs )
7424
7420
{
7425
7421
path_t path ;
7422
+ #if defined(HAVE_READLINK )
7426
7423
int dir_fd = DEFAULT_DIR_FD ;
7427
7424
char buffer [MAXPATHLEN + 1 ];
7428
7425
ssize_t length ;
7426
+ #elif defined(MS_WINDOWS )
7427
+ int dir_fd ;
7428
+ DWORD n_bytes_returned ;
7429
+ DWORD io_result ;
7430
+ HANDLE reparse_point_handle ;
7431
+
7432
+ char target_buffer [_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE ];
7433
+ _Py_REPARSE_DATA_BUFFER * rdb = (_Py_REPARSE_DATA_BUFFER * )target_buffer ;
7434
+ const wchar_t * print_name ;
7435
+ #endif
7429
7436
PyObject * return_value = NULL ;
7430
7437
static char * keywords [] = {"path" , "dir_fd" , NULL };
7431
7438
7432
7439
memset (& path , 0 , sizeof (path ));
7433
7440
path .function_name = "readlink" ;
7434
7441
if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&|$O&:readlink" , keywords ,
7435
7442
path_converter , & path ,
7436
- READLINKAT_DIR_FD_CONVERTER , & dir_fd ))
7443
+ #if defined(HAVE_READLINK )
7444
+ READLINKAT_DIR_FD_CONVERTER ,
7445
+ #elif defined(MS_WINDOWS )
7446
+ dir_fd_unavailable ,
7447
+ #endif
7448
+ & dir_fd ))
7437
7449
return NULL;
7438
7450
7451
+ #if defined(HAVE_READLINK )
7439
7452
Py_BEGIN_ALLOW_THREADS
7440
7453
#ifdef HAVE_READLINKAT
7441
7454
if (dir_fd != DEFAULT_DIR_FD )
@@ -7455,39 +7468,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
7455
7468
return_value = PyUnicode_DecodeFSDefaultAndSize (buffer , length );
7456
7469
else
7457
7470
return_value = PyBytes_FromStringAndSize (buffer , length );
7458
- exit :
7459
- path_cleanup (& path );
7460
- return return_value ;
7461
- }
7462
-
7463
- #endif /* HAVE_READLINK */
7464
-
7465
- #if !defined(HAVE_READLINK ) && defined(MS_WINDOWS )
7466
-
7467
- static PyObject *
7468
- win_readlink (PyObject * self , PyObject * args , PyObject * kwargs )
7469
- {
7470
- path_t path ;
7471
- DWORD n_bytes_returned ;
7472
- DWORD io_result ;
7473
- PyObject * result = NULL ;
7474
- int dir_fd ;
7475
- HANDLE reparse_point_handle ;
7476
-
7477
- char target_buffer [_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE ];
7478
- _Py_REPARSE_DATA_BUFFER * rdb = (_Py_REPARSE_DATA_BUFFER * )target_buffer ;
7479
- const wchar_t * print_name ;
7480
-
7481
- static char * keywords [] = {"path" , "dir_fd" , NULL };
7482
-
7483
- memset (& path , 0 , sizeof (path ));
7484
- path .function_name = "readlink" ;
7485
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&|$O&:readlink" , keywords ,
7486
- path_converter , & path ,
7487
- dir_fd_unavailable , & dir_fd
7488
- ))
7489
- goto exit ;
7490
-
7471
+ #elif defined(MS_WINDOWS )
7491
7472
/* First get a handle to the reparse point */
7492
7473
Py_BEGIN_ALLOW_THREADS
7493
7474
reparse_point_handle = CreateFileW (
@@ -7501,7 +7482,7 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
7501
7482
Py_END_ALLOW_THREADS
7502
7483
7503
7484
if (reparse_point_handle == INVALID_HANDLE_VALUE ) {
7504
- result = path_error (& path );
7485
+ return_value = path_error (& path );
7505
7486
goto exit ;
7506
7487
}
7507
7488
@@ -7519,7 +7500,7 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
7519
7500
Py_END_ALLOW_THREADS
7520
7501
7521
7502
if (io_result == 0 ) {
7522
- result = path_error (& path );
7503
+ return_value = path_error (& path );
7523
7504
goto exit ;
7524
7505
}
7525
7506
@@ -7532,22 +7513,20 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
7532
7513
print_name = (wchar_t * )((char * )rdb -> SymbolicLinkReparseBuffer .PathBuffer +
7533
7514
rdb -> SymbolicLinkReparseBuffer .PrintNameOffset );
7534
7515
7535
- result = PyUnicode_FromWideChar (print_name ,
7536
- rdb -> SymbolicLinkReparseBuffer .PrintNameLength / sizeof (wchar_t ));
7516
+ return_value = PyUnicode_FromWideChar (print_name ,
7517
+ rdb -> SymbolicLinkReparseBuffer .PrintNameLength / sizeof (wchar_t ));
7537
7518
if (path .narrow ) {
7538
- Py_SETREF (result , PyUnicode_EncodeFSDefault (result ));
7539
- if (!result ) {
7519
+ Py_SETREF (return_value , PyUnicode_EncodeFSDefault (return_value ));
7520
+ if (!return_value ) {
7540
7521
goto exit ;
7541
7522
}
7542
7523
}
7524
+ #endif
7543
7525
exit :
7544
7526
path_cleanup (& path );
7545
- return result ;
7527
+ return return_value ;
7546
7528
}
7547
-
7548
- #endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
7549
-
7550
-
7529
+ #endif /* defined(HAVE_READLINK) || defined(MS_WINDOWS) */
7551
7530
7552
7531
#ifdef HAVE_SYMLINK
7553
7532
@@ -12960,16 +12939,11 @@ static PyMethodDef posix_methods[] = {
12960
12939
OS_GETPRIORITY_METHODDEF
12961
12940
OS_SETPRIORITY_METHODDEF
12962
12941
OS_POSIX_SPAWN_METHODDEF
12963
- #ifdef HAVE_READLINK
12942
+ #if defined( HAVE_READLINK ) || defined ( MS_WINDOWS )
12964
12943
{"readlink" , (PyCFunction )posix_readlink ,
12965
12944
METH_VARARGS | METH_KEYWORDS ,
12966
12945
readlink__doc__ },
12967
- #endif /* HAVE_READLINK */
12968
- #if !defined (HAVE_READLINK ) && defined (MS_WINDOWS )
12969
- {"readlink" , (PyCFunction )win_readlink ,
12970
- METH_VARARGS | METH_KEYWORDS ,
12971
- readlink__doc__ },
12972
- #endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
12946
+ #endif /* defined(HAVE_READLINK) || defined(MS_WINDOWS) */
12973
12947
OS_RENAME_METHODDEF
12974
12948
OS_REPLACE_METHODDEF
12975
12949
OS_RMDIR_METHODDEF
0 commit comments