>> Looking into the avc failure, I find >> >> $ ogrinfo ogr/data/avc/testavc/testavc/ >> INFO: Open of `ogr/data/avc/testavc/testavc/' >> using driver `AVCBin' successful. >> 1: ARC (Line String) >> 2: LAB (Point) >> >> But if I leave off the trailing / I get a failure to find a driver. A >> trailing slash on a directrory name seems odd to me, and usually the >> result of completion. > > Hum, I suspect you might hit a similar issue as the one for FreeBSD in > https://github.com/OSGeo/gdal/blob/a95e796f65b26379b0e5c699bacef29f7684f79f/gdal/gcore/gdalopeninfo.cpp#L216 > where fopen("/some/dir", "rb") succeeds. > > Can you test changing that with whatever define is appropriate to test > for your OS and submit the resulting patch ?
The comment about FreeBSD being odd seems strange to me, as POSIX has no notion that fopen must fail when opening a directory for reading. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html As I read the spec, it is a violation to return NULL when the first argument is a directory and the second is r or rb. A test program succeeds in calling fopen on . with rb, on both NetBSD and macOS 10.13. Perhaps I am misreading the POSIX spec. I applied a patch to always do the directory check, and now ogrinfo works with or without the trailing /. Patch looks more complicated than it is.... --- gcore/gdalopeninfo.cpp.orig 2021-09-01 09:48:45.000000000 +0000 +++ gcore/gdalopeninfo.cpp @@ -213,12 +213,8 @@ retry: // TODO(schwehr): Stop using got #endif // HAVE_READLINK -#ifdef __FreeBSD__ - /* FreeBSD 8 oddity: fopen(a_directory, "rb") returns non NULL */ + /* fopen(dir, "r") is required to succeed, per POSIX */ bool bPotentialDirectory = (eAccess == GA_ReadOnly); -#else - bool bPotentialDirectory = false; -#endif // __FreeBDS__ /* Check if the filename might be a directory of a special virtual file system */ if( STARTS_WITH(pszFilename, "/vsizip/") || A test run with this fix and GDAL_DATA unset got to only 20 failures.
/* * https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html */ #include <errno.h> #include <stdio.h> int main() { FILE *fp; errno = 0; fp = fopen(".", "rb"); printf("fopen returns %p errno %d\n", fp, errno); return 0; }
signature.asc
Description: PGP signature
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev