@@ -72,11 +72,23 @@ static_fn bool path_chkpaths(Shell_t *, Pathcomp_t *, Pathcomp_t *, Pathcomp_t *
72
72
static_fn void path_checkdup (Shell_t * shp , Pathcomp_t * );
73
73
static_fn Pathcomp_t * defpath_init (Shell_t * shp );
74
74
75
- static const char * std_path = NULL ;
75
+ static_fn const char * std_path (void ) {
76
+ static const char * path = NULL ;
77
+ if (!path ) {
78
+ path = cs_path ();
79
+ if (path ) {
80
+ // Value returned by cs_path() is short lived, duplicate the string.
81
+ // https://github.com/att/ast/issues/959
82
+ path = strdup (path );
83
+ } else {
84
+ path = e_defpath ;
85
+ }
86
+ }
87
+ return path ;
88
+ }
76
89
77
- static_fn bool onstdpath (Shell_t * shp , const char * name ) {
78
- if (!std_path ) defpath_init (shp );
79
- const char * cp = std_path , * sp ;
90
+ static_fn bool onstdpath (const char * name ) {
91
+ const char * cp = std_path (), * sp ;
80
92
if (cp ) {
81
93
while (* cp ) {
82
94
for (sp = name ; * sp && (* cp == * sp ); sp ++ , cp ++ ) {
@@ -375,7 +387,7 @@ static_fn void path_checkdup(Shell_t *shp, Pathcomp_t *pp) {
375
387
pp -> mtime = statb .st_mtime ;
376
388
pp -> ino = statb .st_ino ;
377
389
pp -> dev = statb .st_dev ;
378
- if (* name == '/' && onstdpath (shp , name )) flag = PATH_STD_DIR ;
390
+ if (* name == '/' && onstdpath (name )) flag = PATH_STD_DIR ;
379
391
first = (pp -> flags & PATH_CDPATH ) ? shp -> cdpathlist : path_get (shp , "" );
380
392
for (oldpp = first ; oldpp && oldpp != pp ; oldpp = oldpp -> next ) {
381
393
if (pp -> ino == oldpp -> ino && pp -> dev == oldpp -> dev && pp -> mtime == oldpp -> mtime ) {
@@ -429,17 +441,7 @@ Pathcomp_t *path_nextcomp(Shell_t *shp, Pathcomp_t *pp, const char *name, Pathco
429
441
}
430
442
431
443
static_fn Pathcomp_t * defpath_init (Shell_t * shp ) {
432
- if (!std_path ) {
433
- std_path = cs_path ();
434
- if (std_path ) {
435
- // Value returned by cs_path() is short lived, duplicate the string.
436
- // https://github.com/att/ast/issues/959
437
- std_path = strdup (std_path );
438
- } else {
439
- std_path = e_defpath ;
440
- }
441
- }
442
- return path_addpath (shp , NULL , std_path , PATH_PATH );
444
+ return path_addpath (shp , NULL , std_path (), PATH_PATH );
443
445
}
444
446
445
447
static_fn void path_init (Shell_t * shp ) {
0 commit comments