Advertisement
Guest User

Untitled Masterpiece

a guest
Nov 28th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <sys/mman.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/mman.h> /* mmap() is defined in this header */
  10. #include <fcntl.h>
  11. #include<string.h>
  12. #include"apue.h"
  13. int main (int argc, char *argv[])
  14. {
  15.  int fdin, fdout;
  16.  char *src, *dst;
  17.  struct stat statbuf;
  18.  
  19.  
  20.  /* open the input file */
  21.  if ((fdin = open (argv[1], O_RDONLY)) < 0)
  22.    {printf("can't open %s for reading", argv[1]);return 1;}
  23.  
  24.  
  25.  
  26.  /* find size of input file */
  27.  if (fstat (fdin,&statbuf) < 0)
  28.     {printf("fstat error");return 1;}
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  /* mmap the input file */
  35.  if ((src = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0))
  36.    == (caddr_t) -1)
  37.    {printf("mmap error for input");return 1;}
  38.  
  39.   char* beg=src;
  40.   long x;
  41.   char* end=&src[statbuf.st_size-1];
  42.   while(src<end)
  43.   {    
  44.         beg=src;
  45.         x = strtol (src,&src,10);
  46.         if(!((x != 0) && ((x & (~x + 1)) == x)))
  47.             fwrite(beg, 1, (int)(src-beg), stdout);    
  48.   }
  49.   return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement