Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <aio.h>
  9. #define MB 1024
  10.  
  11. int sukurti(char *name);
  12. int fill(const int d, struct aiocb *aiorp, void *buf, const int count);
  13.  
  14. int sukurti(char *name){
  15.    int dskr;
  16.    dskr = open( name, O_RDONLY );
  17.    if( dskr == -1 ){
  18.           printf("Failas sukurtas, nes jo nebuvo\n");
  19.           dskr = open( name, O_WRONLY | O_CREAT, 0644);
  20.  
  21.    }else{
  22.            printf("Jau yra toks failas!\n");
  23.            exit(1);
  24.    }
  25.    return dskr;
  26. }
  27.  
  28. int fill(const int d, struct aiocb *aiorp, void *buf, const int count){
  29.         int rv = 0;
  30.         memset( (void *)aiorp, 'A', sizeof( struct aiocb ) );
  31.         aiorp->aio_fildes = d;
  32.         aiorp->aio_buf = buf;
  33.         aiorp->aio_nbytes = count;
  34.         aiorp->aio_offset = 0;
  35.         rv = aio_write( aiorp );
  36.         return rv;
  37.  
  38. }
  39.  
  40. int main(int argc, char * argv[]){
  41.         int des;
  42.         int rv;
  43.         struct aiocb aior;
  44.         int x = atoi(argv[2]);
  45.         printf("%d\n", x);
  46.         int size = MB * MB * x;
  47.         char buffer[size];
  48.         if(argc == 3){
  49.                 printf("just %s\n", argv[1]);
  50.                 des = sukurti(argv[1]);
  51.                 rv = fill(des, &aior, buffer, sizeof(buffer));
  52.         }else{
  53.                 printf("Blogas\n");
  54.         }
  55.         return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement