Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6. #include <assert.h>
  7.  
  8. int truncate(const char *fn, off_t where)
  9. {
  10.   int fd = open(fn, O_WRONLY);
  11.   if (fd < 0)
  12.     return -1;
  13.   if (lseek(fd, where, 0) < 0)
  14.   {
  15.     close(fd);
  16.     return -1;
  17.   }
  18.   if (_write(fd, 0, 0) < 0)
  19.   {
  20.     close(fd);
  21.     return -1;
  22.   }
  23.   return close(fd);
  24. }
  25.