Skip to content

Commit a3c5fa6

Browse files
author
thomas.wouters
committed
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. git-svn-id: http://svn.python.org/projects/python/trunk@45715 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 7760bb6 commit a3c5fa6

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
@@ -262,7 +262,11 @@ extern int lstat(const char *, struct stat *);
262262
#endif /* OS2 */
263263

264264
#ifndef MAXPATHLEN
265+
#if defined(PATH_MAX) && PATH_MAX > 1024
266+
#define MAXPATHLEN PATH_MAX
267+
#else
265268
#define MAXPATHLEN 1024
269+
#endif
266270
#endif /* MAXPATHLEN */
267271

268272
#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)