
Hi. I'm copying below a question i sent to another list about hsc2hs
(and for which i got no response), in the hopes that it will be not be
OT here. My apologies if it is!
I'm trying to write a simple C binding for statfs(2). Simplifying,
writing an hsc file that contains the following snippet:
#include

On Tue, Feb 02, 2010 at 03:51:18PM +0100, Jose A. Ortega Ruiz wrote:
[...] The problem is that the size and some of the offsets of the C struct statfs computed by hsc2c are wrong: i'm in a 32bit linux system, and i've checked, using a C program, that sizeof(struct statfs) is 64 (hsc2 is giving 84 -- although perhaps Haskell needs additional space for housekeeping?), and that the offsets of f_bfree and f_bavail are, respectively, 12 and 16 (not 16 and 24). Also, i know that 12 and 16 are the right values because putting them by hand gives me the correct statfs values.
If you compile your C program with -D_FILE_OFFSET_BITS=64 you'll get the same numbers that hsc2hs does.

Ross Paterson
On Tue, Feb 02, 2010 at 03:51:18PM +0100, Jose A. Ortega Ruiz wrote:
[...] The problem is that the size and some of the offsets of the C struct statfs computed by hsc2c are wrong: i'm in a 32bit linux system, and i've checked, using a C program, that sizeof(struct statfs) is 64 (hsc2 is giving 84 -- although perhaps Haskell needs additional space for housekeeping?), and that the offsets of f_bfree and f_bavail are, respectively, 12 and 16 (not 16 and 24). Also, i know that 12 and 16 are the right values because putting them by hand gives me the correct statfs values.
If you compile your C program with -D_FILE_OFFSET_BITS=64 you'll get the same numbers that hsc2hs does.
But when i use those offsets (16, 24) in my Haskell program (generated by hsc2hs), i get the wrong values when i inspect the struct filled by statfs() (via the call performed by Haskell's FFI), while if i put (by hand this time) the ones (12, 16) given by the C program without _FILE_OFFSET_BITS defined, the results are correct. So it looks like the C library, or the generated code, is not using that value for _FILE_OFFSET_BITS. Do i need to compile my Haskell code using a similar flag? (Sorry if i'm missing something obvious.) Thanks! jao

Ross Paterson
If you compile your C program with -D_FILE_OFFSET_BITS=64 you'll get the same numbers that hsc2hs does.
Aha, that was the key to solve my problem: programs or libraries compiled with that flag must use statfs64() instead of statfs(). Binding to the former in my .hsc produces correct results. Thanks for the hint, Ross. Cheers, jao
participants (2)
-
Jose A. Ortega Ruiz
-
Ross Paterson