X-Debbugs-Cc: debian-h...@lists.debian.org Hello John,
On Sat, Apr 19, 2025 at 11:20:11PM -0500, John Goerzen wrote: > Every reference I have seen says it's not part of POSIX. However, Linux > and the BSDs seem to support it, so might as well just assume it will > work. If you have a patch to just go that direction, I'll take it. Please see attached my second attempt at patching gopher. Best regards, João
diff -ruNd gopher-3.0.17.4/gopher/download.c gopher-3.0.17.4_mod/gopher/download.c --- gopher-3.0.17.4/gopher/download.c 2025-04-24 16:28:29.100204200 +0200 +++ gopher-3.0.17.4_mod/gopher/download.c 2025-04-24 16:13:30.507748321 +0200 @@ -198,14 +198,6 @@ int start, end; struct stat buf; -#if defined(HAVE_GETCWD) && !defined(HAVE_GET_CURRENT_DIR_NAME) - curcwd = (char *) malloc(MAXPATHLEN + 2); - if (!curcwd) { - CursesErrorMsg("Out of memory."); - return; - } -#endif - switch (GSgetType(gs)) { case A_DIRECTORY: case A_CSO: @@ -256,14 +248,20 @@ } #ifdef HAVE_GETCWD - getcwd(curcwd, MAXPATHLEN); + curcwd = getcwd(NULL, 0); #else #ifdef HAVE_GET_CURRENT_DIR_NAME - curcwd = get_current_dir_name(); + curcwd = get_current_dir_name(); #else + curcwd = (char *) malloc(MAXPATHLEN + 2); + if (!curcwd) { + CursesErrorMsg("Out of memory."); + return; + } + getwd(curcwd); -#endif -#endif /* HAVE_GET_CURRENT_DIR_NAME */ +#endif /* HAVE_GET_CURRENT_DIR_NAME */ +#endif #ifdef VMS if (chdir("SYS$SCRATCH")!=0) { @@ -343,9 +341,7 @@ fflush(stdout); getchar(); CURenter(CursesScreen); -#if defined(HAVE_GETCWD) || !defined(HAVE_GET_CURRENT_DIR_NAME) free(curcwd); -#endif } @@ -363,15 +359,6 @@ char *tmppath; GopherObj *gs; - -#if defined(HAVE_GETCWD) && !defined(HAVE_GET_CURRENT_DIR_NAME) - tmppath = (char*)malloc(MAXPATHLEN * 3 + 2); - if ( !tmppath ) { - CursesErrorMsg("Cannot allocate memory"); - return; - } -#endif - thedir = opendir(dirname); chdir(dirname); @@ -400,22 +387,32 @@ GSplusnew(gs); GSsetPath(gs, names[choice]); - + #ifdef HAVE_GETCWD - getcwd(tmppath,MAXPATHLEN); + tmppath = getcwd(NULL, 0); #else #ifdef HAVE_GET_CURRENT_DIR_NAME - tmppath = get_current_dir_name(); - if ( sizeof(tmppath) <= (strlen(tmppath) + strlen(names[choice]) + 1) ) - tmppath = realloc(tmppath,sizeof(tmppath) + strlen(names[choice] + 1)); + tmppath = get_current_dir_name(); +#else + tmppath = (char*)malloc(MAXPATHLEN * 3 + 2); if ( !tmppath ) { - CursesErrorMsg("Out of memory"); - return; + CursesErrorMsg("Cannot allocate memory"); + return; } -#else + getwd(tmppath); #endif -#endif +#endif + +#if defined(HAVE_GETCWD) || defined(HAVE_GET_CURRENT_DIR_NAME) + if ( sizeof(tmppath) <= (strlen(tmppath) + strlen(names[choice]) + 1) ) + tmppath = realloc(tmppath,sizeof(tmppath) + strlen(names[choice] + 1)); + if ( !tmppath ) { + CursesErrorMsg("Out of memory"); + return; + } +#endif + strcat(tmppath, "/"); strcat(tmppath, names[choice]); @@ -429,9 +426,8 @@ for (fcount = 0; names[fcount] != NULL;) { free(names[fcount++]); } -#if defined(HAVE_GETCWD) || !defined(HAVE_GET_CURRENT_DIR_NAME) + free(tmppath); -#endif } #else void