home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / unistd / truncate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-28  |  429 b   |  25 lines

  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.  
  7. int
  8. 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.