Skip to content

Commit eba5280

Browse files
committed
Backport trunk's r45715:
Define MAXPATHLEN to be at least PATH_MAX, if that's defined. Python uses MAXPATHLEN-sized buffers for various output-buffers (like to realpath()), and that's correct on BSD platforms, but not Linux (which uses PATH_MAX, and does not define MAXPATHLEN.) Cursory googling suggests Linux is following a newer standard than BSD, but in cases like this, who knows. Using the greater of PATH_MAX and 1024 as a fallback for MAXPATHLEN seems to be the most portable solution.
1 parent 87cc7a0 commit eba5280

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Include/osdefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ extern "C" {
3737

3838
/* Max pathname length */
3939
#ifndef MAXPATHLEN
40+
#if defined(PATH_MAX) && PATH_MAX > 1024
41+
#define MAXPATHLEN PATH_MAX
42+
#else
4043
#define MAXPATHLEN 1024
4144
#endif
45+
#endif
4246

4347
/* Search path entry delimiter */
4448
#ifndef DELIM

Modules/posixmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ extern int lstat(const char *, struct stat *);
244244
#endif /* OS2 */
245245

246246
#ifndef MAXPATHLEN
247+
#if defined(PATH_MAX) && PATH_MAX > 1024
248+
#define MAXPATHLEN PATH_MAX
249+
#else
247250
#define MAXPATHLEN 1024
251+
#endif
248252
#endif /* MAXPATHLEN */
249253

250254
#ifdef UNION_WAIT

Python/getcwd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
#endif
1515

1616
#ifndef MAXPATHLEN
17+
#if defined(PATH_MAX) && PATH_MAX > 1024
18+
#define MAXPATHLEN PATH_MAX
19+
#else
1720
#define MAXPATHLEN 1024
1821
#endif
22+
#endif
1923

2024
extern char *getwd(char *);
2125

0 commit comments

Comments
 (0)