Changeset 15892


Ignore:
Timestamp:
Sep 5, 2013, 12:46:21 AM (8 years ago)
Author:
gb
Message:

lisp_ftruncate: never change current file position.
Fixes ticket:1109 in the trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/windows-calls.c

    r14619 r15892  
    623623lisp_ftruncate(HANDLE hfile, off_t new_size)
    624624{
    625   __int64 oldpos;
    626 
    627 
    628   oldpos = lisp_lseek(hfile, 0, SEEK_END);
    629   if (oldpos == -1) {
     625  __int64 cureof,curpos;
     626  int e;
     627
     628  curpos = lisp_lseek(hfile, 0, SEEK_CUR);
     629  cureof = lisp_lseek(hfile, 0, SEEK_END);
     630  lisp_lseek(hfile, 0, SEEK_CUR);
     631  if (cureof == -1) {
    630632    return 0;
    631633  }
    632   if (oldpos < new_size) {
     634  if (cureof < new_size) {
    633635    char buf[4096];
    634     __int64 n = new_size-oldpos;
     636    __int64 n = new_size-cureof;
    635637    DWORD nwritten, to_write;
    636638
     639    lisp_lseek(hfile, cureof, SEEK_SET);
    637640    memset(buf,0,sizeof(buf));
    638641    while(n) {
     
    644647      if (!WriteFile(hfile,buf,to_write,&nwritten,NULL)) {
    645648        _dosmaperr(GetLastError());
     649        e = errno;
     650        lisp_lseek(hfile,curpos,SEEK_SET);
     651        errno = e;
    646652        return -1;
    647653      }
    648654      n -= nwritten;
    649655    }
     656    lisp_lseek(hfile,curpos,SEEK_SET);
    650657    return 0;
    651658  }
    652659  lisp_lseek(hfile, new_size, SEEK_SET);
    653660  if (SetEndOfFile(hfile)) {
     661    lisp_lseek(hfile,curpos,SEEK_SET);
    654662    return 0;
    655663  }
    656664  _dosmaperr(GetLastError());
     665  e = errno;
     666  lisp_lseek(hfile,curpos,SEEK_SET);
     667  errno = e;
    657668  return -1;
    658669}
Note: See TracChangeset for help on using the changeset viewer.