File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed
Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -73,25 +73,30 @@ int load_handlers() {
7373 void * handle ;
7474 size_t len ;
7575
76- d = opendir (HANDLERS_DIR );
77-
78- if (!d ) {
79- print ( ERROR , "opendir: %s" , strerror (errno ) );
80- return -1 ;
76+ len = 50 ;
77+ cwd = malloc (len );
78+
79+ while (cwd && len < PATH_MAX ) {
80+ if (getcwd (cwd , len )) break ;
81+ if (errno != ERANGE ) {
82+ print ( ERROR , "getcwd: %s" , strerror (errno ));
83+ free (cwd );
84+ return -1 ;
85+ }
86+ len += 50 ;
87+ cwd = realloc (cwd , len );
8188 }
8289
83- cwd = malloc (PATH_MAX );
84-
8590 if (!cwd ) {
86- print ( ERROR , "malloc: %s" , strerror (errno ));
87- closedir (d );
91+ print ( ERROR , "malloc(%d): %s" , len , strerror (errno ));
8892 return -1 ;
8993 }
9094
91- if (!getcwd (cwd , PATH_MAX )) {
92- print ( ERROR , "getcwd: %s" , strerror (errno ));
95+ d = opendir (HANDLERS_DIR );
96+
97+ if (!d ) {
98+ print ( ERROR , "opendir: %s" , strerror (errno ) );
9399 free (cwd );
94- closedir (d );
95100 return -1 ;
96101 }
97102
You can’t perform that action at this time.
0 commit comments