Changeset 14554 in project for chicken


Ignore:
Timestamp:
05/07/09 11:59:34 (11 years ago)
Author:
felix winkelmann
Message:

fixed bug #16 (setter for file-position accepts list, now)

Location:
chicken/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chicken/trunk/manual/Unit posix

    r13740 r14554  
    406406
    407407<procedure>(file-position FILE)</procedure>
    408 
    409 Returns the current file position of {{FILE}}, which should be a
     408<procedure>(set! (file-position FILE) POSITION)</procedure>
     409
     410{{file-position}} Returns the current file position of {{FILE}}, which should be a
    410411port or a file-descriptor.
     412
     413{{(set! (file-position FILE) POSITION)}} Sets the current read/write position of {{FILE}} to
     414{{POSITION}}, which should be an exact integer or a list of two elements. {{FILE}}
     415should be a port or a file-descriptor. If {{POSITION}} is a list, it should
     416be of the form {{(POSITION WHENCE)}} where {{WHENCE}} specifies
     417how the position is to interpreted and should be one of the values
     418{{seek/set, seek/cur}} and {{seek/end}}. It defaults to
     419{{seek/set}}.
     420
     421Exceptions: {{(exn bounds)}}, {{(exn i/o file)}}
     422
    411423
    412424==== file-size
     
    482494{{OFFSET}} then nothing is done.  {{FILE}} should be a filename
    483495or a file-descriptor.
    484 
    485 ==== set-file-position!
    486 
    487 <procedure>(set-file-position! FILE POSITION [WHENCE])</procedure>
    488 <procedure>(set! (file-position FILE) POSITION)</procedure>
    489 
    490 Sets the current read/write position of {{FILE}} to
    491 {{POSITION}}, which should be an exact integer. {{FILE}}
    492 should be a port or a file-descriptor.  {{WHENCE}} specifies
    493 how the position is to interpreted and should be one of the values
    494 {{seek/set, seek/cur}} and {{seek/end}}. It defaults to
    495 {{seek/set}}.
    496 
    497 Exceptions: {{(exn bounds)}}, {{(exn i/o file)}}
    498496
    499497==== change-file-mode
  • chicken/trunk/posixunix.scm

    r13368 r14554  
    838838      pos) )
    839839   (lambda (port pos . whence)
    840      (let ([whence (if (pair? whence) (car whence) _seek_set)])
     840     (let ((whence (if (pair? whence) (car whence) _seek_set)))
     841       (when (and (list? pos) (fx= 2 (length pos)))
     842         (set! whence (cadr pos))
     843         (set! pos (car pos)))
    841844       (##sys#check-exact pos 'set-file-position!)
    842845       (##sys#check-exact whence 'set-file-position!)
  • chicken/trunk/posixwin.scm

    r13167 r14554  
    11211121
    11221122(define file-position
    1123   (lambda (port)
    1124     (let ([pos (cond [(port? port)
    1125                       (if (eq? (##sys#slot port 7) 'stream)
    1126                           (##core#inline "C_ftell" port)
    1127                           -1) ]
    1128                      [(fixnum? port) (##core#inline "C_lseek" port 0 _seek_cur)]
    1129                      [else (##sys#signal-hook #:type-error 'file-position "invalid file" port)] ) ] )
    1130       (when (fx< pos 0)
    1131         (##sys#update-errno)
    1132         (##sys#signal-hook #:file-error 'file-position "cannot retrieve file position of port" port) )
    1133       pos) ) )
    1134 
    1135 (define set-file-position!
    1136   (lambda (port pos . whence)
     1123  (getter-with-setter
     1124   (lambda (port)
     1125     (let ([pos (cond [(port? port)
     1126                       (if (eq? (##sys#slot port 7) 'stream)
     1127                           (##core#inline "C_ftell" port)
     1128                           -1) ]
     1129                      [(fixnum? port) (##core#inline "C_lseek" port 0 _seek_cur)]
     1130                      [else (##sys#signal-hook #:type-error 'file-position "invalid file" port)] ) ] )
     1131       (when (fx< pos 0)
     1132         (##sys#update-errno)
     1133         (##sys#signal-hook #:file-error 'file-position "cannot retrieve file position of port" port) )
     1134       pos) )
     1135   (lambda (port pos . whence)
    11371136    (let ([whence (if (pair? whence) (car whence) _seek_set)])
     1137      (when (and (list? pos) (fx= 2 (length pos)))
     1138        (set! whence (cadr pos))
     1139        (set! pos (car pos)))
    11381140      (##sys#check-exact pos 'set-file-position!)
    11391141      (##sys#check-exact whence 'set-file-position!)
     
    11451147                    [else (##sys#signal-hook #:type-error 'set-file-position! "invalid file" port)] )
    11461148        (##sys#update-errno)
    1147         (##sys#signal-hook #:file-error 'set-file-position! "cannot set file position" port pos) ) ) ) )
     1149        (##sys#signal-hook #:file-error 'set-file-position! "cannot set file position" port pos) ) ) ) ) )
    11481150
    11491151
Note: See TracChangeset for help on using the changeset viewer.