Guest User

Untitled

a guest
Feb 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. let mb x = x * 1024 * 1024
  2.  
  3. open Unix
  4.  
  5. let _ =
  6. let filename = Sys.argv.(1) in
  7. let filesize = (stat filename).st_size in
  8. Printf.printf "%d\n" filesize;
  9.  
  10. let restbytes = ref filesize in
  11.  
  12. let strlen = mb 100 in
  13. let string = String.make strlen ' ' in
  14. let writesize = ref strlen in
  15.  
  16. let fd = openfile filename [O_RDWR] 0o640 in
  17. while !restbytes > 0
  18. do
  19. writesize := (min !restbytes strlen);
  20.  
  21. Printf.printf "restbytes: %d, writesize: %d\n" !restbytes !writesize;
  22. flush Pervasives.stdout;
  23.  
  24. let num = write fd string 0 !writesize in
  25. restbytes := max 0 (!restbytes - num );
  26.  
  27. Printf.printf "(just written: %d)\n" num;
  28. Printf.printf "restbytes: %d\n-----------\n" (* HERE I STHE ERROR! *)
  29.  
  30. done;
  31. close fd
Add Comment
Please, Sign In to add comment