"Fossies" - the Fresh Open Source Software Archive

Member "bonnie++-2.00a/getc_putc_helper.cpp" (3 Jul 2009, 1215 Bytes) of package /linux/privat/bonnie++-2.00a.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "getc_putc_helper.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "bonnie.h"
    2 
    3 #include <unistd.h>
    4 #include <stdlib.h>
    5 #include <cstring>
    6 #include "duration.h"
    7 #include <vector>
    8 #include "getc_putc.h"
    9 
   10 int main(int argc, char *argv[])
   11 {
   12   if(argc != 2)
   13   {
   14     fprintf(stderr, "Error - don't run this yourself, run getc_putc!\n");
   15     return 1;
   16   }
   17 
   18   int size = atoi(argv[1]);
   19   bool quiet = false;
   20 
   21   if(argv[1][strlen(argv[1]) - 1] == 'q')
   22     quiet = true;
   23 
   24   volatile char c;
   25   int i;
   26   Duration dur;
   27   double res[2];
   28 
   29   FILE *fp = fdopen(FILE_FD, "w+");
   30   if(!fp)
   31   {
   32     fprintf(stderr, "Can't reopen for putc.\n");
   33     return 1;
   34   }
   35   if(fseek(fp, 0, SEEK_SET) != 0)
   36   {
   37     fprintf(stderr, "Can't seek.\n");
   38     return 1;
   39   }
   40   fflush(NULL);
   41   TEST_FUNC_WRITE("putc(c, fp) no thread", if(putc(c, fp) == EOF), res[0]);
   42   if(fseek(fp, 0, SEEK_SET) != 0)
   43   {
   44     fprintf(stderr, "Can't seek.\n");
   45     return 1;
   46   }
   47   fflush(NULL);
   48   TEST_FUNC_READ("getc() no thread", if( (c = getc(fp)) == EOF), res[1]);
   49   if(fseek(fp, 0, SEEK_SET) != 0)
   50   {
   51     fprintf(stderr, "Can't seek.\n");
   52     return 1;
   53   }
   54   fflush(NULL);
   55 
   56   if(write(1, res, sizeof(res)) != sizeof(res))
   57   {
   58     fprintf(stderr, "Can't write results to parent process.\n");
   59     return 1;
   60   }
   61 
   62   return 0;
   63 }
   64