home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / posix / fcntl / trunc.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-27  |  765 b   |  46 lines

  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <unistd.h>
  6.  
  7. static void
  8. die(const char *m)
  9. {
  10.   printf("Error: %s\n", m);
  11.   exit(1);
  12. }
  13.  
  14. int
  15. main(void)
  16. {
  17.   int fid;
  18.   char buf[512];
  19.   struct stat st;
  20.  
  21.   fid = open("trunc.dat", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  22.   if (!fid)
  23.     die("open o_creat");
  24.   write(fid, buf, 512);
  25.   close(fid);
  26.  
  27.   if (stat("trunc.dat", &st))
  28.     die("stat");
  29.   if (st.st_size == 0)
  30.     die("wrong size");
  31.  
  32.   fid = open("trunc.dat", O_WRONLY | O_TRUNC, 0666);
  33.   if (!fid)
  34.     die("open o_trunc");
  35.   close(fid);
  36.  
  37.   if (stat("trunc.dat", &st))
  38.     die("second stat");
  39.   if (st.st_size != 0)
  40.     die("wrong size");
  41.  
  42.   remove("trunc.dat");
  43.  
  44.   return 0;
  45. }
  46.