[M3devel] Suspicious code in Cstdio.i3 for FreeBSD
Mika Nystrom
mika at async.caltech.edu
Sat Apr 25 00:20:00 CEST 2009
This code looks a bit suspicious:
FILE = RECORD
p : unsigned_char_star; (* current position in (some) buffer *)
r : int; (* read space left for getc() *)
w : int; (* write space left for putc() *)
flags : short_int; (* flags, below; this FILE is free if 0 *)
file : short_int; (* fileno, if Unix descriptor, else -1 *)
bf : SBUF; (* the buffer (at least 1 byte, if !NULL) *)
lbfsize : int; (* 0 or -_bf._size, for inline putc *)
(* operations *)
cookie : void_star; (* cookie passed to io functions *)
xxclose: void_star;
xxread : void_star;
xxseek : void_star;
xxwrite: void_star;
(* separate buffer for long sequences of ungetc() *)
ub : SBUF; (* ungetc buffer *)
up : unsigned_char_star; (* saved _p when _p is doing ungetc data *)
ur : int; (* saved _r when _r is counting ungetc data *)
(* tricks to meet minimum requirements even when malloc() fails *)
ubuf : ARRAY[0..2] OF unsigned_char; (* guarantee an ungetc() buffer *)
nbuf : ARRAY[0..0] OF unsigned_char; (* guarantee a getc() buffer *)
(* separate buffer for fgetln() when line crosses buffer boundary *)
lb : SBUF; (* buffer for fgetln() *)
(* Unix stdio files get aligned to block boundaries on fseek() *)
blksize : int; (* stat.st_blksize (may be != _bf._size) *)
offset : off_t; (* current lseek offset *)
pad1 : int; (* assume high 4 bytes of offset are 0 *)
END;
Note the "offset" and "pad1".
Now...
off_t = int64_t;
int64_t = BITS 64 FOR Ctypes.long_long;
Is this right or is there a bit too much padding here?
Is the padding also assuming little-endianness? Hmm...
Mika
More information about the M3devel
mailing list