Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/mman.h> /* mmap() is defined in this header */
- #include <fcntl.h>
- #include<string.h>
- #include"apue.h"
- int main (int argc, char *argv[])
- {
- int fdin, fdout;
- char *src, *dst;
- struct stat statbuf;
- /* open the input file */
- if ((fdin = open (argv[1], O_RDONLY)) < 0)
- {printf("can't open %s for reading", argv[1]);return 1;}
- /* find size of input file */
- if (fstat (fdin,&statbuf) < 0)
- {printf("fstat error");return 1;}
- /* mmap the input file */
- if ((src = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0))
- == (caddr_t) -1)
- {printf("mmap error for input");return 1;}
- char* beg=src;
- long x;
- char* end=&src[statbuf.st_size-1];
- while(src<end)
- {
- beg=src;
- x = strtol (src,&src,10);
- if(!((x != 0) && ((x & (~x + 1)) == x)))
- fwrite(beg, 1, (int)(src-beg), stdout);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement