Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6672d0c

Browse files
author
Victor Stinner
committed
fileutils.c: document which encodings are used
1 parent 41c8b37 commit 6672d0c

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

Python/fileutils.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ _Py_wchar2char(const wchar_t *text)
194194
perhaps for cygwin/mingw builds?
195195
*/
196196
#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
197+
198+
/* Get file status. Encode the path to the locale encoding. */
199+
197200
int
198201
_Py_wstat(const wchar_t* path, struct stat *buf)
199202
{
@@ -210,9 +213,11 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
210213
}
211214
#endif
212215

213-
/* Call _wstat() on Windows, or stat() otherwise. Only fill st_mode
214-
attribute on Windows. Return 0 on success, -1 on stat error or (if
215-
PyErr_Occurred()) unicode error. */
216+
/* Call _wstat() on Windows, or encode the path to the filesystem encoding and
217+
call stat() otherwise. Only fill st_mode attribute on Windows.
218+
219+
Return 0 on success, -1 on _wstat() / stat() error or (if PyErr_Occurred())
220+
unicode error. */
216221

217222
int
218223
_Py_stat(PyObject *path, struct stat *statbuf)
@@ -236,6 +241,9 @@ _Py_stat(PyObject *path, struct stat *statbuf)
236241
#endif
237242
}
238243

244+
/* Open a file. Use _wfopen() on Windows, encode the path to the locale
245+
encoding and use fopen() otherwise. */
246+
239247
FILE *
240248
_Py_wfopen(const wchar_t *path, const wchar_t *mode)
241249
{
@@ -260,9 +268,11 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
260268
#endif
261269
}
262270

263-
/* Call _wfopen() on Windows, or fopen() otherwise. Return the new file
264-
object on success, or NULL if the file cannot be open or (if
265-
PyErr_Occurred()) on unicode error */
271+
/* Call _wfopen() on Windows, or encode the path to the filesystem encoding and
272+
call fopen() otherwise.
273+
274+
Return the new file object on success, or NULL if the file cannot be open or
275+
(if PyErr_Occurred()) on unicode error */
266276

267277
FILE*
268278
_Py_fopen(PyObject *path, const char *mode)
@@ -288,6 +298,10 @@ _Py_fopen(PyObject *path, const char *mode)
288298
}
289299

290300
#ifdef HAVE_READLINK
301+
302+
/* Read value of symbolic link. Encode the path to the locale encoding, decode
303+
the result from the locale encoding. */
304+
291305
int
292306
_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
293307
{
@@ -320,6 +334,10 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
320334
#endif
321335

322336
#ifdef HAVE_REALPATH
337+
338+
/* Return the canonicalized absolute pathname. Encode path to the locale
339+
encoding, decode the result from the locale encoding. */
340+
323341
wchar_t*
324342
_Py_wrealpath(const wchar_t *path,
325343
wchar_t *resolved_path, size_t resolved_path_size)
@@ -346,6 +364,8 @@ _Py_wrealpath(const wchar_t *path,
346364
}
347365
#endif
348366

367+
/* Get the current directory. Decode the path from the locale encoding. */
368+
349369
wchar_t*
350370
_Py_wgetcwd(wchar_t *buf, size_t size)
351371
{

0 commit comments

Comments
 (0)