"Fossies" - the Fresh Open Source Software Archive

Member "afio-2.5.2/regtest/makesparse.c" (30 Nov 2018, 1108 Bytes) of package /linux/misc/afio-2.5.2.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "makesparse.c" see the Fossies "Dox" file reference documentation.

    1 
    2 /* test large file compile environment and make a large sparse file
    3 */
    4 
    5 #include <stdio.h>
    6 #include <string.h>
    7 #include <unistd.h>
    8 #include <sys/stat.h>
    9 #include <time.h>
   10 #include <sys/types.h>
   11 #include <sys/stat.h>
   12 #include <fcntl.h>
   13 #include <errno.h>
   14 
   15 
   16 void fatal(const char *s)
   17 {
   18   printf("makesparse: %s\n",s);
   19   exit(1);
   20 }
   21 
   22 
   23 int main(int argc, char ** argv)
   24 {
   25   struct stat s;
   26   int f;
   27   unsigned long long pos;
   28   char *bla="bla bla bla\n";
   29 
   30   printf("sizeof st_size = %d\n",sizeof(s.st_size));
   31 
   32   if(sizeof(s.st_size)<8) fatal("Large file compile environment not present!");
   33 
   34   if(argc!=2) fatal("Wrong number of args");
   35 
   36   f=open(argv[1],O_RDWR);
   37 
   38   if(!f) fatal("Open failed");
   39 
   40   pos=(unsigned long long)(4LL*1024LL*1024LL*1024LL);
   41 
   42   if(lseek(f,(off_t)pos,SEEK_SET)==((off_t)-1))
   43     { perror("lseek"); fatal("lseek failed"); }
   44 
   45   if(!write(f,bla,strlen(bla))) { perror("write"); fatal("write failed"); }
   46 
   47   close(f);
   48 
   49   if(lstat(argv[1],&s)) { perror("stat"); fatal("stat failed"); }
   50 
   51   if(s.st_size!=pos+strlen(bla))
   52     fatal("created file does not have the expected length");
   53 
   54   return 0;
   55 }
   56