@@ -7414,28 +7414,41 @@ If dir_fd is not None, it should be a file descriptor open to a directory,\n\
74147414 and path should be relative; path will then be relative to that directory.\n\
74157415dir_fd may not be implemented on your platform.\n\
74167416 If it is unavailable, using it will raise a NotImplementedError." );
7417- #endif
7418-
7419- #ifdef HAVE_READLINK
74207417
7421- /* AC 3.5: merge win32 and not together */
74227418static PyObject *
74237419posix_readlink (PyObject * self , PyObject * args , PyObject * kwargs )
74247420{
74257421 path_t path ;
7422+ #if defined(HAVE_READLINK )
74267423 int dir_fd = DEFAULT_DIR_FD ;
74277424 char buffer [MAXPATHLEN + 1 ];
74287425 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
74297436 PyObject * return_value = NULL ;
74307437 static char * keywords [] = {"path" , "dir_fd" , NULL };
74317438
74327439 memset (& path , 0 , sizeof (path ));
74337440 path .function_name = "readlink" ;
74347441 if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O&|$O&:readlink" , keywords ,
74357442 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 ))
74377449 return NULL;
74387450
7451+ #if defined(HAVE_READLINK )
74397452 Py_BEGIN_ALLOW_THREADS
74407453#ifdef HAVE_READLINKAT
74417454 if (dir_fd != DEFAULT_DIR_FD )
@@ -7455,39 +7468,7 @@ posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
74557468 return_value = PyUnicode_DecodeFSDefaultAndSize (buffer , length );
74567469 else
74577470 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 )
74917472 /* First get a handle to the reparse point */
74927473 Py_BEGIN_ALLOW_THREADS
74937474 reparse_point_handle = CreateFileW (
@@ -7501,7 +7482,7 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
75017482 Py_END_ALLOW_THREADS
75027483
75037484 if (reparse_point_handle == INVALID_HANDLE_VALUE ) {
7504- result = path_error (& path );
7485+ return_value = path_error (& path );
75057486 goto exit ;
75067487 }
75077488
@@ -7519,7 +7500,7 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
75197500 Py_END_ALLOW_THREADS
75207501
75217502 if (io_result == 0 ) {
7522- result = path_error (& path );
7503+ return_value = path_error (& path );
75237504 goto exit ;
75247505 }
75257506
@@ -7532,22 +7513,20 @@ win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
75327513 print_name = (wchar_t * )((char * )rdb -> SymbolicLinkReparseBuffer .PathBuffer +
75337514 rdb -> SymbolicLinkReparseBuffer .PrintNameOffset );
75347515
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 ));
75377518 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 ) {
75407521 goto exit ;
75417522 }
75427523 }
7524+ #endif
75437525exit :
75447526 path_cleanup (& path );
7545- return result ;
7527+ return return_value ;
75467528}
7547-
7548- #endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
7549-
7550-
7529+ #endif /* defined(HAVE_READLINK) || defined(MS_WINDOWS) */
75517530
75527531#ifdef HAVE_SYMLINK
75537532
@@ -12960,16 +12939,11 @@ static PyMethodDef posix_methods[] = {
1296012939 OS_GETPRIORITY_METHODDEF
1296112940 OS_SETPRIORITY_METHODDEF
1296212941 OS_POSIX_SPAWN_METHODDEF
12963- #ifdef HAVE_READLINK
12942+ #if defined( HAVE_READLINK ) || defined ( MS_WINDOWS )
1296412943 {"readlink" , (PyCFunction )posix_readlink ,
1296512944 METH_VARARGS | METH_KEYWORDS ,
1296612945 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) */
1297312947 OS_RENAME_METHODDEF
1297412948 OS_REPLACE_METHODDEF
1297512949 OS_RMDIR_METHODDEF
0 commit comments