⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileops.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 2 页
字号:
      if (_IO_in_backup (fp))	delta -= eGptr () - Gbase ();#endif      _IO_off_t new_pos = _IO_SYSSEEK (fp, delta, 1);      if (new_pos != (_IO_off_t) EOF)	fp->_IO_read_end = fp->_IO_read_ptr;#ifdef ESPIPE      else if (errno == ESPIPE)	; /* Ignore error from unseekable devices. */#endif      else	retval = EOF;    }  if (retval != EOF)    fp->_offset = _IO_pos_BAD;  /* FIXME: Cleanup - can this be shared? */  /*    setg(base(), ptr, ptr); */#ifdef _IO_VXW_THREADS  _IO_funlockfile (fp);#endif /* _IO_VXW_THREADS */  _IO_cleanup_region_end (1);  return retval;}_IO_pos_t_IO_file_seekoff (fp, offset, dir, mode)     _IO_FILE *fp;     _IO_off_t offset;     int dir;     int mode;{  _IO_pos_t result;  _IO_off_t delta, new_offset;  long count;  /* POSIX.1 8.2.3.7 says that after a call the fflush() the file     offset of the underlying file must be exact.  */  int must_be_exact = (fp->_IO_read_base == fp->_IO_read_end		       && fp->_IO_write_base == fp->_IO_write_ptr);  if (mode == 0)    dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */  /* Flush unwritten characters.     (This may do an unneeded write if we seek within the buffer.     But to be able to switch to reading, we would need to set     egptr to ptr.  That can't be done in the current design,     which assumes file_ptr() is eGptr.  Anyway, since we probably     end up flushing when we close(), it doesn't make much difference.)     FIXME: simulate mem-papped files. */  if (fp->_IO_write_ptr > fp->_IO_write_base || _IO_in_put_mode (fp))    if (_IO_switch_to_get_mode (fp))      return EOF;  if (fp->_IO_buf_base == NULL)    {      _IO_doallocbuf (fp);      _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);      _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);    }  switch (dir)    {    case _IO_seek_cur:      /* Adjust for read-ahead (bytes is buffer). */      offset -= fp->_IO_read_end - fp->_IO_read_ptr;      if (fp->_offset == _IO_pos_BAD)	goto dumb;      /* Make offset absolute, assuming current pointer is file_ptr(). */      offset += _IO_pos_as_off (fp->_offset);      dir = _IO_seek_set;      break;    case _IO_seek_set:      break;    case _IO_seek_end:      {	struct stat st;	if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))	  {	    offset += st.st_size;	    dir = _IO_seek_set;	  }	else	  goto dumb;      }    }  /* At this point, dir==_IO_seek_set. */  /* If destination is within current buffer, optimize: */  if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL      && !_IO_in_backup (fp))    {      /* Offset relative to start of main get area. */      _IO_pos_t rel_offset = (offset - fp->_offset			      + (fp->_IO_read_end - fp->_IO_read_base));      if (rel_offset >= 0)	{#if 0	  if (_IO_in_backup (fp))	    _IO_switch_to_main_get_area (fp);#endif	  if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)	    {	      _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,			fp->_IO_read_end);	      _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);	      return offset;	    }#ifdef TODO	    /* If we have streammarkers, seek forward by reading ahead. */	    if (_IO_have_markers (fp))	      {		int to_skip = rel_offset		  - (fp->_IO_read_ptr - fp->_IO_read_base);		if (ignore (to_skip) != to_skip)		  goto dumb;		return offset;	      }#endif	}#ifdef TODO      if (rel_offset < 0 && rel_offset >= Bbase () - Bptr ())	{	  if (!_IO_in_backup (fp))	    _IO_switch_to_backup_area (fp);	  gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);	  return offset;	}#endif    }#ifdef TODO  _IO_unsave_markers (fp);#endif  if (fp->_flags & _IO_NO_READS)    goto dumb;  /* Try to seek to a block boundary, to improve kernel page management. */  new_offset = offset & ~(fp->_IO_buf_end - fp->_IO_buf_base - 1);  delta = offset - new_offset;  if (delta > fp->_IO_buf_end - fp->_IO_buf_base)    {      new_offset = offset;      delta = 0;    }  result = _IO_SYSSEEK (fp, new_offset, 0);  if (result < 0)    return EOF;  if (delta == 0)    count = 0;  else    {      count = _IO_SYSREAD (fp, fp->_IO_buf_base,			   (must_be_exact			    ? delta : fp->_IO_buf_end - fp->_IO_buf_base));      if (count < delta)	{	  /* We weren't allowed to read, but try to seek the remainder. */	  offset = count == EOF ? delta : delta-count;	  dir = _IO_seek_cur;	  goto dumb;	}    }  _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta,	    fp->_IO_buf_base + count);  _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);  fp->_offset = result + count;  _IO_mask_flags (fp, 0, _IO_EOF_SEEN);  return offset; dumb:  _IO_unsave_markers (fp);  result = _IO_SYSSEEK (fp, offset, dir);  if (result != EOF)    _IO_mask_flags (fp, 0, _IO_EOF_SEEN);  fp->_offset = result;  _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);  _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);  return result;}_IO_ssize_t_IO_file_read (fp, buf, size)     _IO_FILE *fp;     void *buf;     _IO_ssize_t size;{  return read (fp->_fileno, buf, size);}_IO_pos_t_IO_file_seek (fp, offset, dir)     _IO_FILE *fp;     _IO_off_t offset;     int dir;{  return lseek (fp->_fileno, offset, dir);}int_IO_file_stat (fp, st)     _IO_FILE *fp;     void *st;{  return fstat (fp->_fileno, (struct stat *) st);}int_IO_file_close (fp)     _IO_FILE *fp;{  return close (fp->_fileno);}_IO_ssize_t_IO_file_write (f, data, n)     _IO_FILE *f;     const void *data;     _IO_ssize_t n;{  _IO_ssize_t to_do = n;  while (to_do > 0)    {      _IO_ssize_t count = write (f->_fileno, data, to_do);      if (count == EOF)	{	  f->_flags |= _IO_ERR_SEEN;	  break;        }      to_do -= count;      data = (void *) ((char *) data + count);    }  n -= to_do;  if (f->_offset >= 0)    f->_offset += n;  return n;}_IO_size_t_IO_file_xsputn (f, data, n)     _IO_FILE *f;     const void *data;     _IO_size_t n;{  register const char *s = (char *) data;  _IO_size_t to_do = n;  int must_flush = 0;  _IO_size_t count;  if (n <= 0)    return 0;  /* This is an optimized implementation.     If the amount to be written straddles a block boundary     (or the filebuf is unbuffered), use sys_write directly. */  /* First figure out how much space is available in the buffer. */  count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */  if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING))    {      count = f->_IO_buf_end - f->_IO_write_ptr;      if (count >= n)	{	  register const char *p;	  for (p = s + n; p > s; )	    {	      if (*--p == '\n')		{		  count = p - s + 1;		  must_flush = 1;		  break;		}	    }	}    }  /* Then fill the buffer. */  if (count > 0)    {      if (count > to_do)	count = to_do;      if (count > 20)	{	  memcpy (f->_IO_write_ptr, s, count);	  s += count;	}      else	{	  register char *p = f->_IO_write_ptr;	  register int i = (int) count;	  while (--i >= 0)	    *p++ = *s++;	}      f->_IO_write_ptr += count;      to_do -= count;    }  if (to_do + must_flush > 0)    {      _IO_size_t block_size, dont_write;      /* Next flush the (full) buffer. */      if (__overflow (f, EOF) == EOF)	return n - to_do;      /* Try to maintain alignment: write a whole number of blocks.	 dont_write is what gets left over. */      block_size = f->_IO_buf_end - f->_IO_buf_base;      dont_write = block_size >= 128 ? to_do % block_size : 0;      count = to_do - dont_write;      if (_IO_do_write (f, s, count) == EOF)	return n - to_do;      to_do = dont_write;      /* Now write out the remainder.  Normally, this will fit in the	 buffer, but it's somewhat messier for line-buffered files,	 so we let _IO_default_xsputn handle the general case. */      if (dont_write)	to_do -= _IO_default_xsputn (f, s+count, dont_write);    }  return n - to_do;}#if 0/* Work in progress */_IO_size_t_IO_file_xsgetn (fp, data, n)     _IO_FILE *fp;     void *data;     _IO_size_t n;{  register _IO_size_t more = n;  register char *s = data;  for (;;)    {      /* Data available. */      _IO_ssize_t count = fp->_IO_read_end - fp->_IO_read_ptr;      if (count > 0)	{	  if (count > more)	    count = more;	  if (count > 20)	    {	      memcpy (s, fp->_IO_read_ptr, count);	      s += count;	      fp->_IO_read_ptr += count;	    }	  else if (count <= 0)	    count = 0;	  else	    {	      register char *p = fp->_IO_read_ptr;	      register int i = (int) count;	      while (--i >= 0)		*s++ = *p++;	      fp->_IO_read_ptr = p;            }            more -= count;        }#if 0      if (! _IO_in put_mode (fp)	  && ! _IO_have_markers (fp) && ! IO_have_backup (fp))	{	  /* This is an optimization of _IO_file_underflow */	  if (fp->_flags & _IO_NO_READS)	    break;	  /* If we're reading a lot of data, don't bother allocating	     a buffer.  But if we're only reading a bit, perhaps we should ??*/	  if (count <= 512 && fp->_IO_buf_base == NULL)	    _IO_doallocbuf (fp);	  if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))	    _IO_flush_all_linebuffered ();	  _IO_switch_to_get_mode (fp); ???;	  count = _IO_SYSREAD (fp, s, more);	  if (count <= 0)	     {	       if (count == 0)		 fp->_flags |= _IO_EOF_SEEN;	       else		 fp->_flags |= _IO_ERR_SEEN, count = 0;	     }	  s += count;	  more -= count;	}#endif      if (more == 0 || __underflow (fp) == EOF)	break;    }  return n - more;}#endifstruct _IO_jump_t _IO_file_jumps ={  JUMP_INIT_DUMMY,  JUMP_INIT(finish, _IO_file_finish),  JUMP_INIT(overflow, _IO_file_overflow),  JUMP_INIT(underflow, _IO_file_underflow),  JUMP_INIT(uflow, _IO_default_uflow),  JUMP_INIT(pbackfail, _IO_default_pbackfail),  JUMP_INIT(xsputn, _IO_file_xsputn),  JUMP_INIT(xsgetn, _IO_default_xsgetn),  JUMP_INIT(seekoff, _IO_file_seekoff),  JUMP_INIT(seekpos, _IO_default_seekpos),  JUMP_INIT(setbuf, _IO_file_setbuf),  JUMP_INIT(sync, _IO_file_sync),  JUMP_INIT(doallocate, _IO_file_doallocate),  JUMP_INIT(read, _IO_file_read),  JUMP_INIT(write, _IO_file_write),  JUMP_INIT(seek, _IO_file_seek),  JUMP_INIT(close, _IO_file_close),  JUMP_INIT(stat, _IO_file_stat)};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -