Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/syslimits.h>
- #include <dirent.h>
- #include <sys/dir.h>
- #include <sys/stat.h>
- #include <time.h>
- #include <pwd.h>
- #include <grp.h>
- #include <fcntl.h>
- int main (int argc, char* argv[]) {
- if (argc != 3) {
- printf("usage: %s [source file] [destination path]\n", argv[0]);
- return -1;
- }
- int fd_src, fd_dst;
- if ((fd_src = open(argv[1], O_RDONLY)) < 0) {
- perror(argv[0]);
- return -1;
- }
- if ((fd_dst = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
- perror(argv[0]);
- return -1;
- }
- int bytes, i;
- unsigned char buff[1];
- unsigned char aux;
- while ((bytes = read(fd_src, buff, sizeof(char))) > 0) {
- unsigned char c = buff[0];
- aux = 0;
- for (i = 0; i < 4; i++) {
- if (c & (1<<i)) {
- aux |= (1 << (i+4));
- }
- }
- for (i = 4; i < 8; i++) {
- if (c & (1<<i)) {
- aux |= (1 << (i-4));
- }
- }
- buff[0] = aux;
- write(fd_dst, buff, bytes);
- }
- close(fd_src); close(fd_dst);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement