Ignore:
Timestamp:
07/18/09 14:10:36 (12 years ago)
Author:
Alaric Snell-Pym
Message:

C-Keen's patches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/ugarit/trunk/posixextras.scm

    r15241 r15242  
     1(import foreign)
    12
    23;; Things that the posix unit forgot
     
    1415#define C_mknod(fn, m, d) C_fix(mknod(C_data_pointer(fn), C_unfix(m), C_unfix(d)))
    1516#define C_utime(fn) C_fix((C_utime_buf.actime = C_utime_atime, C_utime_buf.modtime = C_utime_mtime, utime(C_data_pointer(fn), &C_utime_buf)))
     17#define C_ftell(p) C_fix(ftell(C_port_file(p)))
     18#define C_fseek(p, n, w) C_mk_nbool(fseek(C_port_file(p), C_unfix(n), C_unfix(w)))
     19#define C_lseek(fd, o, w) C_fix(lseek(C_unfix(fd), C_unfix(o), C_unfix(w)))
    1620EOF
    1721)
     
    8084      (posix-error #:file-error 'change-file-times "cannot change file times" fn atime mtime)))
    8185   
    82    
     86 
     87(define-foreign-variable _seek_set int "SEEK_SET")
     88(define-foreign-variable _seek_cur int "SEEK_CUR")
     89(define-foreign-variable _seek_end int "SEEK_END")
     90 
     91(define set-file-position!
     92   (lambda (port pos . whence)
     93     (let ([whence (if (pair? whence) (car whence) _seek_set)])
     94       (##sys#check-exact pos 'set-file-position!)
     95       (##sys#check-exact whence 'set-file-position!)
     96       (when (fx< pos 0) (##sys#signal-hook #:bounds-error 'set-file-position! "invalid negative port position" pos port))
     97       (unless (cond [(port? port)
     98     (and (eq? (##sys#slot port 7) 'stream)
     99       (##core#inline "C_fseek" port pos whence) ) ]
     100     [(fixnum? port) (##core#inline "C_lseek" port pos whence)]
     101     [else (##sys#signal-hook #:type-error 'set-file-position! "invalid file" port)] )
     102   (posix-error #:file-error 'set-file-position! "cannot set file position" port pos) ) ) ) )
     103
Note: See TracChangeset for help on using the changeset viewer.