FrankPfattheicher / RevolutionPi

.NET support libraries for data exchange with RevPi I/O-Modules and Gateways
GNU General Public License v3.0
9 stars 3 forks source link

Wrong return value for lseek interop on 32 bit RevPi builds #3

Closed chowi closed 2 years ago

chowi commented 3 years ago

The return value of the lseek function is off_t, which is 32 bit on 32 bit builds (as currently all RevPis are running under) and 64 bit ONLY on 64 bit builds. Hence, the long return value in the Interop.cs file is wrong- especially in combination with the PiControl code Read(...), where the check of lseek is just < 0 (better would be a check if it is equal to -1 which is the return value when lseek fails). So after each start of the program it depends on the memory location where the variables are being located and it is pure luck if the 32 bit above the real value are set to 0 or not. If not, each call to Read returns null.

FrankPfattheicher commented 2 years ago

Fixed.

using off_t = System.Int32;

internal static extern off_t lseek(int file, int offset, int whence);