Advertisement
Guest User

Untitled

a guest
May 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <ftw.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include <dlfcn.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <errno.h>
  10. #include <aio.h>
  11.  
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.  
  16.     if (argc != 3)
  17.     {
  18.         printf("netinkamas argumentu kiekis");
  19.         exit(255);
  20.     }
  21.     int number = atoi(argv[2]);
  22.     if (number < 0)
  23.     {
  24.         printf("Skaicius turi buti teigiamas\n");
  25.         exit(254);
  26.     }
  27.    
  28.     int fd = open(argv[1], O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  29.     if (fd < 0) {
  30.       if (errno == EEXIST)
  31.       {
  32.         printf("Failas jau yra.\n");
  33.         exit(254);
  34.       }
  35.     }
  36.     else
  37.     {
  38.         #define BUF_SIZE number*1024*1024
  39.         char buf[BUF_SIZE];
  40.         struct aiocb aiocb;
  41.         memset(buf, 0xAA, BUF_SIZE);
  42.         memset(&aiocb, 0, sizeof(struct aiocb));
  43.         aiocb.aio_fildes = fd;
  44.         aiocb.aio_buf = buf;
  45.         aiocb.aio_nbytes = BUF_SIZE;
  46.         aio_write(&aiocb);
  47.         while (aio_error (&aiocb) == EINPROGRESS);
  48.         close(fd);
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement