test_lab_7.cc
void
checkread(const char *d, const char *f, int start, int n, char c)
{
  int fd;
  char name[512];

  sleep(1);

  sprintf(name, "%s/%s", d, f);
  fd = open(name, 0);
  if(fd < 0){
    fprintf(stderr, "test-lab-4-a: open(%s): %s\n",
            name, strerror(errno));
    exit(1);
  }
  if(lseek(fd, start, 0) != (off_t) start){
    fprintf(stderr, "test-lab-4-a: lseek(%s, %d): %s\n",
            name, start, strerror(errno));
    exit(1);
  }
  for(int i = 0; i < n; i++){
    char xc;
    if(read(fd, &xc, 1) != 1){
      fprintf(stderr, "test-lab-4-a: read(%s): %s\n",
              name, strerror(errno));
      exit(1);
    }
    if(xc != c){
      fprintf(stderr, "test-lab-4-a: checkread off %d %02x != %02x\n",
              start + i, xc, c);
      exit(1);
    }
  }
  close(fd);
}
// check that the n bytes at offset start are all c.
check that the n bytes at offset start are all c.
check that the n bytes at offset start are all c .
void
checkread(const char *d, const char *f, int start, int n, char c)
{
  int fd;
  char name[512];
  sleep(1);
  sprintf(name, "%s/%s", d, f);
  fd = open(name, 0);
  if(fd < 0){
    fprintf(stderr, "test-lab-4-a: open(%s): %s\n",
            name, strerror(errno));
    exit(1);
  }
  if(lseek(fd, start, 0) != (off_t) start){
    fprintf(stderr, "test-lab-4-a: lseek(%s, %d): %s\n",
            name, start, strerror(errno));
    exit(1);
  }
  for(int i = 0; i < n; i++){
    char xc;
    if(read(fd, &xc, 1) != 1){
      fprintf(stderr, "test-lab-4-a: read(%s): %s\n",
              name, strerror(errno));
      exit(1);
    }
    if(xc != c){
      fprintf(stderr, "test-lab-4-a: checkread off %d %02x != %02x\n",
              start + i, xc, c);
      exit(1);
    }
  }
  close(fd);
}
void checkread ( const char * d , const char * f , int start , int n , char c ) { int fd ; char name [ 512 ] ; sleep ( 1 ) ; sprintf ( name , " " , d , f ) ; fd = open ( name , 0 ) ; if ( fd < 0 ) { fprintf ( stderr , " \n " , name , strerror ( errno ) ) ; exit ( 1 ) ; } if ( lseek ( fd , start , 0 ) != ( off_t ) start ) { fprintf ( stderr , " \n " , name , start , strerror ( errno ) ) ; exit ( 1 ) ; } for ( int i = 0 ; i < n ; i ++ ) { char xc ; if ( read ( fd , & xc , 1 ) != 1 ) { fprintf ( stderr , " \n " , name , strerror ( errno ) ) ; exit ( 1 ) ; } if ( xc != c ) { fprintf ( stderr , " \n " , start + i , xc , c ) ; exit ( 1 ) ; } } close ( fd ) ; }
check that the n bytes at offset start are all c.
check that the n bytes at offset start are all c .