Advertisement
Guest User

asd

a guest
Dec 1st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/syslimits.h>
  6. #include <dirent.h>
  7. #include <sys/dir.h>
  8. #include <sys/stat.h>
  9. #include <time.h>
  10. #include <pwd.h>
  11. #include <grp.h>
  12. #include <fcntl.h>
  13.  
  14. int main (int argc, char* argv[]) {
  15. if (argc != 3) {
  16. printf("usage: %s [source file] [destination path]\n", argv[0]);
  17. return -1;
  18. }
  19.  
  20. int fd_src, fd_dst;
  21. if ((fd_src = open(argv[1], O_RDONLY)) < 0) {
  22. perror(argv[0]);
  23. return -1;
  24. }
  25.  
  26. if ((fd_dst = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
  27. perror(argv[0]);
  28. return -1;
  29. }
  30.  
  31. int bytes, i;
  32. unsigned char buff[1];
  33. unsigned char aux;
  34. while ((bytes = read(fd_src, buff, sizeof(char))) > 0) {
  35. unsigned char c = buff[0];
  36. aux = 0;
  37. for (i = 0; i < 4; i++) {
  38. if (c & (1<<i)) {
  39. aux |= (1 << (i+4));
  40. }
  41. }
  42. for (i = 4; i < 8; i++) {
  43. if (c & (1<<i)) {
  44. aux |= (1 << (i-4));
  45. }
  46. }
  47. buff[0] = aux;
  48. write(fd_dst, buff, bytes);
  49. }
  50. close(fd_src); close(fd_dst);
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement