Fix NetBSD build: Retire unneeded PAL_fpos_t and fgetpos() fsetpos()
authorKamil Rytarowski <n54@gmx.com>
Fri, 5 Feb 2016 03:34:06 +0000 (04:34 +0100)
committerKamil Rytarowski <n54@gmx.com>
Fri, 5 Feb 2016 03:48:47 +0000 (04:48 +0100)
commit9c91f14547a5f41f15b11d8bd0875260c0b7d8a6
tree35151cf7a221b7e05632cbec308f2a00586fd597
parente36834bdee7d14edc404428ec7c6eed661b78f5a
Fix NetBSD build: Retire unneeded PAL_fpos_t and fgetpos() fsetpos()

These functions are unused. Linux version was unimplemented.

Removal suggested by Jan Kotas (Microsoft) to get rid of these functions.

The current code resulted with the following errors with the recent Clang/LLVM
(3.9.0nb20160131 snapshot) on NetBSD-7.99.25:

/tmp/pkgsrc-tmp/wip/coreclr-git/work/coreclr/src/pal/src/cruntime/file.cpp:858:20: error: no viable overloaded '='
        native_pos = *pos;
        ~~~~~~~~~~ ^ ~~~~

/usr/include/stdio.h:67:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'PAL_fpos_t' (aka 'unsigned long') to 'const __sfpos' for 1st argument
typedef struct __sfpos {
               ^
/usr/include/stdio.h:67:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'PAL_fpos_t' (aka 'unsigned long') to '__sfpos' for 1st argument
/tmp/pkgsrc-tmp/wip/coreclr-git/work/coreclr/src/pal/src/cruntime/file.cpp:860:14: error: assigning to 'PAL_fpos_t' (aka 'unsigned long') from incompatible type 'fpos_t' (aka '__sfpos')
        *pos = native_pos;
             ^ ~~~~~~~~~~
/tmp/pkgsrc-tmp/wip/coreclr-git/work/coreclr/src/pal/src/cruntime/file.cpp:904:20: error: no viable overloaded '='
        native_pos = *pos;
        ~~~~~~~~~~ ^ ~~~~
/usr/include/stdio.h:67:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const PAL_fpos_t' (aka 'const unsigned long') to 'const __sfpos' for 1st argument
typedef struct __sfpos {
               ^
/usr/include/stdio.h:67:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'const PAL_fpos_t' (aka 'const unsigned long') to '__sfpos' for 1st argument
3 errors generated.

Possible implementation for NetBSD (attached here for historical references):
+--- src/pal/src/cruntime/file.cpp.orig 2016-01-28 19:04:13.000000000 +0000
++++ src/pal/src/cruntime/file.cpp
+@@ -844,6 +844,15 @@ PAL_fgetpos (
+     // TODO: implement for Linux if required
+     ASSERT(FALSE);
+     return -1;
++#elif defined(__NetBSD__)
++    off_t native_pos;
++
++    if ((native_pos = ftello(f->bsdFilePtr)) == -1)
++        return -1;
++
++    *pos = native_pos;
++
++    return 0;
+ #else
+     int    nRetVal = -1;
+     fpos_t native_pos;
+@@ -890,6 +899,14 @@ PAL_fsetpos (
+     // TODO: implement for Linux if required
+     ASSERT(FALSE);
+     return  -1;
++#elif defined(__NetBSD__)
++    off_t native_pos;
++
++    native_pos = *pos;
++    if (fseeko(f->bsdFilePtr, native_pos, SEEK_SET) == -1)
++        return -1;
++
++    return 0;
+ #else
+     int    nRetVal = -1;
+     fpos_t native_pos;

We cannot go better on NetBSD. This implementation might still have issues
with e.g. Unicode.

This closes #3029 "PAL fpos_t clash with NetBSD libraries"

Thanks Peter Jas (@jasonwilliams200OK) for hacking session on it.
src/pal/inc/pal.h
src/pal/src/cruntime/file.cpp
src/pal/src/include/pal/palinternal.h