pic32/libraries/SD/utility/SdFile.cpp
//------------------------------------------------------------------------------
/**
 * Sets a file's position.
 *
 * \param[in] pos The new position in bytes from the beginning of the file.
 *
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
Sets a file's position.
\param[in] pos The new position in bytes from the beginning of the file.

\return The value one, true, is returned for success and
the value zero, false, is returned for failure.
Sets a file ' s position . \ param [ in ] pos The new position in bytes from the beginning of the file . \ return The value one true is returned for success and the value zero false is returned for failure .
uint8_t SdFile::seekSet(uint32_t pos) {
  if (!isOpen() || pos > fileSize_) return false;
  if (type_ == FAT_FILE_TYPE_ROOT16) {
    curPosition_ = pos;
    return true;
  }
  if (pos == 0) {
    curCluster_ = 0;
    curPosition_ = 0;
    return true;
  }
  uint32_t nCur = (curPosition_ - 1) >> (vol_->clusterSizeShift_ + 9);
  uint32_t nNew = (pos - 1) >> (vol_->clusterSizeShift_ + 9);
  if (nNew < nCur || curPosition_ == 0) {
    curCluster_ = firstCluster_;
  } else {
    nNew -= nCur;
  }
  while (nNew--) {
    if (!vol_->fatGet(curCluster_, &curCluster_)) return false;
  }
  curPosition_ = pos;
  return true;
}
uint8_t SdFile :: seekSet ( uint32_t pos ) { if ( ! isOpen ( ) || pos > fileSize_ ) return false ; if ( type_ == FAT_FILE_TYPE_ROOT16 ) { curPosition_ = pos ; return true ; } if ( pos == 0 ) { curCluster_ = 0 ; curPosition_ = 0 ; return true ; } uint32_t nCur = ( curPosition_ - 1 ) >> ( vol_ -> clusterSizeShift_ + 9 ) ; uint32_t nNew = ( pos - 1 ) >> ( vol_ -> clusterSizeShift_ + 9 ) ; if ( nNew < nCur || curPosition_ == 0 ) { curCluster_ = firstCluster_ ; } else { nNew -= nCur ; } while ( nNew -- ) { if ( ! vol_ -> fatGet ( curCluster_ , & curCluster_ ) ) return false ; } curPosition_ = pos ; return true ; }
Sets a file's position.
Sets a file ' s position .
// error if file not open or seek past end of file // set position to start of file // calculate cluster index for cur and new position // must follow chain from first cluster // advance from curPosition