Beispiel #1
0
			::std::streampos seekpos(::std::streampos sp, ::std::ios_base::openmode which = ::std::ios_base::in | ::std::ios_base::out)
			{
				if ( which & ::std::ios_base::in )
				{
					int64_t const cur = symsread-(egptr()-gptr());
					int64_t const curlow = cur - static_cast<int64_t>(gptr()-eback());
					int64_t const curhigh = cur + static_cast<int64_t>(egptr()-gptr());
					
					// call relative seek, if target is in range
					if ( sp >= curlow && sp <= curhigh )
						return seekoff(static_cast<int64_t>(sp) - cur, ::std::ios_base::cur, which);

					// target is out of range, we really need to seek
					uint64_t tsymsread = (sp / buffersize)*buffersize;
					
					symsread = tsymsread;
					stream.clear();
					stream.seekg( (symsread * b) / 8 );
					setg(buffer.end(),buffer.end(),buffer.end());
					underflow();
					setg(eback(),gptr() + (static_cast<int64_t>(sp)-static_cast<int64_t>(tsymsread)), egptr());
				
					return sp;
				}
				
				return -1;
			}
Beispiel #2
0
void
_IO_unsave_markers (_IO_FILE *fp)
{
  struct _IO_marker *mark = fp->_markers;
  if (mark)
    {
#ifdef TODO
      streampos offset = seekoff (0, ios::cur, ios::in);
      if (offset != EOF)
	{
	  offset += eGptr () - Gbase ();
	  for ( ; mark != NULL; mark = mark->_next)
	    mark->set_streampos (mark->_pos + offset);
	}
    else
      {
	for ( ; mark != NULL; mark = mark->_next)
	  mark->set_streampos (EOF);
      }
#endif
      fp->_markers = 0;
    }

  if (_IO_have_backup (fp))
    _IO_free_backup_area (fp);
}
Beispiel #3
0
no_copy_membuf&
no_copy_membuf::seekg (std::ios::off_type off, std::ios::seekdir dir) {

    // Seek to the position supplied relatively.
    seekoff(off, dir, std::ios::in);
    return *this;
}
Beispiel #4
0
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
{
	poco_assert (_fd == -1);

	_pos = 0;
	_path = path;
	setMode(mode);
	resetBuffers();

	int flags(0);
	if (mode & std::ios::trunc)
		flags |= O_TRUNC;
	if (mode & std::ios::app)
		flags |= O_APPEND;
	if (mode & std::ios::out)
		flags |= O_CREAT;
	if ((mode & std::ios::in) && (mode & std::ios::out))
		flags |= O_RDWR;
	else if (mode & std::ios::in)
		flags |= O_RDONLY;
	else
		flags |= O_WRONLY;
			
	_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
	if (_fd == -1)
		File::handleLastError(_path);
		
	if ((mode & std::ios::app) || (mode & std::ios::ate))
		seekoff(0, std::ios::end, mode);
}
Beispiel #5
0
int parsebuf::pbackfail(int c)
{
    if (c == EOF)
	return 0;
    if (seekoff(-1, ios::cur) == EOF)
	return EOF;
    return (unsigned char)c;
}
Beispiel #6
0
int streambuf::pbackfail(int c)
{
    if (_gptr > _eback)
	_gptr--;
    else if (seekoff(-1, ios::cur, ios::in) == EOF)
	return EOF;
    if (c != EOF && *_gptr != c)
	*_gptr = c;
    return (unsigned char)c;
}
  int
  streambuf::sputn(const char* s, streamsize n)
  {
#if 0
    if (openedFor & ios_base::app)
      {
        seekoff(0, ios_base::end, ios_base::out);
      }
#endif
    return xsputn(s, n);
  }
Beispiel #8
0
int parsebuf::seek_in_line(int i)
{
#if 1
    abort();
    return 0; // Suppress warning.
#else
    if (i > 0) {
	size_t len = line_length();
	if ((unsigned)i > len) i = len;
    }
    else if (i < -1) i = -1;
    int new_pos = seekoff(pos_at_line_start + i, ios::beg);
    if (new_pos == EOF)
	return tell_in_line();
    else return new_pos - pos_at_line_start;
#endif
}
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
{
	poco_assert (_handle == INVALID_HANDLE_VALUE);

	_path = path;
	_pos = 0;
	setMode(mode);
	resetBuffers();

	DWORD access = 0;
	if (mode & std::ios::in)
		access |= GENERIC_READ;
	if (mode & std::ios::out)
		access |= GENERIC_WRITE;

	DWORD shareMode = FILE_SHARE_READ;
	if (!(mode & std::ios::out))
		shareMode |= FILE_SHARE_WRITE;
		
	DWORD creationDisp = OPEN_EXISTING;
	if (mode & std::ios::trunc)
		creationDisp = CREATE_ALWAYS;
	else if (mode & std::ios::out)
		creationDisp = OPEN_ALWAYS;

	DWORD flags = FILE_ATTRIBUTE_NORMAL;
	
#if defined (POCO_WIN32_UTF8)
	std::wstring utf16Path;
	UnicodeConverter::toUTF16(path, utf16Path);
	_handle = CreateFile2(utf16Path.c_str(), access, shareMode, creationDisp, NULL);
#else
	_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
#endif

	if (_handle == INVALID_HANDLE_VALUE)
		File::handleLastError(_path);
		
	if ((mode & std::ios::ate) || (mode & std::ios::app))
		seekoff(0, std::ios::end, mode);
}
Beispiel #10
0
filebuf* filebuf::open(const char *filename, const char *mode)
{
    if (is_open())
	return NULL;
    int oflags = 0, omode;
    int read_write;
    int oprot = 0666;
    switch (*mode++) {
      case 'r':
	omode = O_RDONLY;
	read_write = _S_NO_WRITES;
	break;
      case 'w':
	omode = O_WRONLY;
	oflags = O_CREAT|O_TRUNC;
	read_write = _S_NO_READS;
	break;
      case 'a':
	omode = O_WRONLY;
	oflags = O_CREAT|O_APPEND;
	read_write = _S_NO_READS|_S_IS_APPENDING;
	break;
      default:
	errno = EINVAL;
	return NULL;
    }
    if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) {
	omode = O_RDWR;
	read_write = 0;
    }
    int fdesc = ::open(filename, omode|oflags, oprot);
    if (fdesc < 0)
	return NULL;
    _fb._fileno = fdesc;
    xsetflags(read_write, _S_NO_READS+_S_NO_WRITES+_S_IS_APPENDING);
    if (read_write & _S_IS_APPENDING)
	if (seekoff(0, ios::end) == EOF)
	    return NULL;
    _link_in();
    return this;
}
			/**
			 * seek to absolute position
			 **/
			::std::streampos seekpos(::std::streampos sp, ::std::ios_base::openmode which = ::std::ios_base::in | ::std::ios_base::out)
			{
				if ( which & ::std::ios_base::in )
				{
					// current position
					int64_t const cur = symsread-(egptr()-gptr());
					// current start of buffer (relative)
					int64_t const curlow = cur - static_cast<int64_t>(gptr()-eback());
					// current end of buffer (relative)
					int64_t const curhigh = cur + static_cast<int64_t>(egptr()-gptr());
					
					// call relative seek, if target is in range
					if ( sp >= curlow && sp <= curhigh )
						return seekoff(static_cast<int64_t>(sp) - cur, ::std::ios_base::cur, which);

					// target is out of range, we really need to seek
					uint64_t tsymsread = (sp / blocksize)*blocksize;

					// set symsread					
					symsread = tsymsread;

					// reinit
					init(true);

					// read next block
					underflow();
					
					// skip bytes in block to get to final position
					setg(
						eback(),
						gptr() + (static_cast<int64_t>(sp)-static_cast<int64_t>(tsymsread)), 
						egptr()
					);
				
					return sp;
				}
				
				return -1;
			}
Beispiel #12
0
filebuf* filebuf::open(const char *filename, ios::openmode mode, int prot)
{
    if (is_open())
	return NULL;
    int posix_mode;
    int read_write;
    if (mode & ios::app)
	mode |= ios::out;
    if ((mode & (ios::in|ios::out)) == (ios::in|ios::out)) {
	posix_mode = O_RDWR;
	read_write = 0;
    }
    else if (mode & ios::out)
	posix_mode = O_WRONLY, read_write = _S_NO_READS;
    else if (mode & (int)ios::in)
	posix_mode = O_RDONLY, read_write = _S_NO_WRITES;
    else
	posix_mode = 0, read_write = _S_NO_READS+_S_NO_WRITES;
    if ((mode & (int)ios::trunc) || mode == (int)ios::out)
	posix_mode |= O_TRUNC;
    if (mode & ios::app)
	posix_mode |= O_APPEND, read_write |= _S_IS_APPENDING;
    if (!(mode & (int)ios::nocreate) && mode != ios::in)
	posix_mode |= O_CREAT;
    if (mode & (int)ios::noreplace)
	posix_mode |= O_EXCL;
    int fd = ::open(filename, posix_mode, prot);
    if (fd < 0)
	return NULL;
    _fb._fileno = fd;
    xsetflags(read_write, _S_NO_READS+_S_NO_WRITES+_S_IS_APPENDING);
    if (mode & (ios::ate|ios::app)) {
	if (seekoff(0, ios::end) == EOF)
	    return NULL;
    }
    _link_in();
    return this;
}
  int
  streambuf::sputc(char c)
  {
#if 0
    if (openedFor & ios_base::app)
      {
        seekoff(0, ios_base::end, ios_base::out);
      }
    if (mpnext < mpend)
      {
        *mpnext = c;
        ++mpnext;
      }
    else
      {
        return overflow(traits::to_int(c));
      }
    return traits::to_int(c);

#else

    return overflow(traits::to_int(c));
#endif
  }
Beispiel #14
0
std::streambuf::pos_type membuf::seekpos(pos_type sp,
	std::ios_base::openmode which)
{	// change to specified position, according to mode
	return seekoff(sp, std::ios_base::beg, which);
}
Beispiel #15
0
std::streampos iconvstreambuf::seekpos(std::streampos sp,
  std::ios_base::openmode which)
{
  return seekoff(sp, std::ios_base::beg, which);
}
streampos streambuf::seekpos(streampos pos, int mode)
{
    return seekoff(streamoff(pos), ios::beg, mode);
}
Beispiel #17
0
	std::streampos streambuf::seekpos(std::streampos off,std::ios_base::openmode m)
	{
		return seekoff(std::streamoff(off),std::ios_base::beg,m);
	}
Beispiel #18
0
FileStreamBuf::pos_type FileStreamBuf::seekpos(pos_type pos, std::ios_base::openmode mode)
{
    if(pos != pos_type(off_type(pos)))
        return traits_type::eof();
    return seekoff(off_type(pos), std::ios_base::beg, mode);
}
Beispiel #19
0
base_streambuf::pos_type
base_streambuf::seekpos( pos_type pos, std::ios_base::openmode which )
{
	return seekoff( pos, std::ios_base::beg, which );
}
Beispiel #20
0
filebuf* filebuf::open(const char *filename, const char *mode)
{
    // fdopen in stdio need this.
    if (is_open()) {
	// file is open. we cannot open a new file
	if (filename) {
	    errno = EINVAL;
	    return NULL;
	}
    }
    else {
	// file is not open. we have to open a new file
	if (filename == NULL) {
	    errno = EINVAL;
	    return NULL;
	}
    }

    int oflags = 0, omode;
    int read_write;
    int oprot = 0666;
    switch (*mode++) {
      case 'r':
	omode = O_RDONLY;
	read_write = _S_NO_WRITES;
	break;
      case 'w':
	omode = O_WRONLY;
	oflags = O_CREAT|O_TRUNC;
	read_write = _S_NO_READS;
	break;
      case 'a':
	omode = O_WRONLY;
	oflags = O_CREAT|O_APPEND;
	read_write = _S_NO_READS|_S_IS_APPENDING;
	break;
      default:
	errno = EINVAL;
	return NULL;
    }
    if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) {
	omode = O_RDWR;
	read_write &= _S_IS_APPENDING;
    }
    xsetflags(read_write, _S_NO_READS+_S_NO_WRITES+_S_IS_APPENDING);
    if (filename) {
	int fdesc = ::open(filename, omode|oflags, oprot);
	if (fdesc < 0) return NULL;
	_fb._fileno = fdesc;
	if (read_write & _S_IS_APPENDING)
	    if (seekoff(0, ios::end) == EOF && errno != ESPIPE)
		return NULL;
    }
    else {
	// Get old status flag.
	int status_flag = ::fcntl (_fb._fileno, F_GETFL);
	if (status_flag < 0) return NULL;
// We should only do O_APPEND.
#if  0
	// We cannot change the access mode for an open file descriptor.
	if ((status_flag & O_ACCMODE) != omode) {
	    errno = EINVAL;
	    return NULL;
	}
#endif
	// Get new status flag.
	oflags &= O_APPEND;
	// check if we need to change the status flag.
	if ((status_flag & O_APPEND) != oflags) {
	    // Set new status flag.
	    status_flag = (status_flag & ~O_APPEND) | oflags;
	    if (::fcntl (_fb._fileno, F_SETFL, status_flag) < 0)
		return NULL;
	}
	// Seek off to the current file position.
	_fb._offset = -1;
	if (seekoff(0, ios::cur) == EOF)
	    if (errno != ESPIPE) return NULL;
	    else _fb._offset = 0;
    }
    _link_in();
    return this;
}
Beispiel #21
0
std::streambuf::pos_type IOBuffer::seekpos(std::streambuf::pos_type p, std::ios::openmode mode)
{ 
    return seekoff(p, std::ios::beg, mode); 
}
Beispiel #22
0
std::streampos CInputStreamBuffer::seekpos(std::streampos sp, std::ios_base::openmode which)
{
    return seekoff(off_type(sp), std::ios_base::beg, which);
}
Beispiel #23
0
 bool filebuf::truncate()
 {
    return truncate( seekoff(0, std::ios_base::cur, std::ios_base::out) );
 }
Beispiel #24
0
streamfilter::pos_type streamfilter::seekpos(streamfilter::pos_type pos, std::ios_base::openmode mode) {
  return seekoff(pos, std::ios::beg, mode);
}
Beispiel #25
0
strstreambuf::pos_type
strstreambuf::seekpos(pos_type pos, ios_base::openmode mode) {
  return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode);
}
Beispiel #26
0
/***
*olebuf* olebuf::open(const char* name, int mode, int share) - olebuf open
*
*Purpose:
*       olebuf open() member function.  Open a file and attach to olebuf
*       object.
*
*Entry:
*       name  = file name string.
*       mode  = open mode: Combination of ios:: in, out, binary, nocreate, app,
*               ate, noreplace and trunc.  See spec. for details on behavior.
*       share = share mode (optional).  sh_compat, sh_none, sh_read, sh_write.
*
*Exit:
*       Returns this pointer or NULL if error.
*
*Exceptions:
*       Returns NULL if olebuf is already attached to an open file, or if
*       invalid mode options, or if call to _sopen or olebuf::seekoff() fails.
*
*******************************************************************************/
olebuf* olebuf::open(IStorage *pIStg, const wchar_t* name, int mode, int share)
{
    DWORD ole_mode = 0;
    if (x_pIStrm!=NULL)
        return NULL;    // error if already open

// translate mode argument
    if (!(mode & ios::nocreate))
        ole_mode |= STGM_CREATE;
    if (mode & ios::noreplace)
        ole_mode |= STGM_FAILIFTHERE;
    if (mode & ios::app)
        {
        mode |= ios::out;
//        ole_mode |= O_APPEND;
        }
    if (mode & ios::trunc)
        {
        mode |= ios::out;  // IMPLIED
//        ole_mode |= O_TRUNC;
        }
    if (mode & ios::out)
        {
        if (mode & ios::in)
            {
            ole_mode |= STGM_READWRITE;
            }
        else
            {
            ole_mode |= STGM_WRITE;
            }
        if (!(mode & (ios::in|ios::app|ios::ate|ios::noreplace)))
            {
            mode |= ios::trunc; // IMPLIED
//            ole_mode |= O_TRUNC;
            }
        }
    else if (mode & ios::in)
        ole_mode |= STGM_READ;
    else
        return NULL;    // error if not ios:in or ios::out

    share &= (sh_read|sh_write|sh_none); // ignore other bits
    if (share)  // optimization  openprot serves as default
        {
        switch (share)
            {
/*          case 03000 : Reserved for sh_compat  */

//          case sh_none :
            case 04000 :
                ole_mode |= STGM_SHARE_EXCLUSIVE;
                break;
//          case sh_read :
            case 05000 :
                ole_mode |= STGM_SHARE_DENY_WRITE;
                break;
//          case sh_write :
            case 06000 :
                ole_mode |= STGM_SHARE_DENY_READ;
                break;
//          case (sh_read|sh_write) :
            case 07000 :
                ole_mode |= STGM_SHARE_DENY_NONE;
                break;
            default :   // unrecognized value same as default
                break;
            };
        }

HRESULT hr;

	if (ole_mode & STGM_CREATE)		// create new substream
		hr = pIStg -> CreateStream (name, ole_mode, 0L, 0L, &x_pIStrm);
	else							// open existing stream
		hr = pIStg -> OpenStream (name, NULL, ole_mode, 0L, &x_pIStrm);
	if (FAILED(hr)) {
		SetLastError (hr);
		return NULL;
	}

    lock();
    x_fOpened = 1;
    if ((!unbuffered()) && (!ebuf()))
        {
        char * sbuf = new char[BUFSIZ];
        if (!sbuf)
            {
            unbuffered(1);
            }
        else
            {
            streambuf::setb(sbuf,sbuf+BUFSIZ,1);
            }
        }
    if (mode & ios::ate)
        if (seekoff(0,ios::end,mode)==EOF)
            {
            close();
            unlock();
            return NULL;
            }
    unlock();
    return this;
}
Beispiel #27
0
 virtual pos_type seekpos(pos_type pos, std::ios_base::openmode mode 
                               = std::ios_base::in | std::ios_base::out)
 {  return seekoff(pos - pos_type(off_type(0)), std::ios_base::beg, mode);  }
Beispiel #28
0
/* virtual */ strstreambuf::pos_type
strstreambuf::seekoff (off_type off, ios::seekdir way, ios::openmode which)
{
    _RWSTD_ASSERT (_C_is_valid ());

    // should implicitly hold as long as ios::seekdir is an enum
    _RWSTD_ASSERT (ios::beg == way || ios::cur == way || ios::end == way);
    _RWSTD_ASSERT (_C_is_valid ());

    // determine seekable area - D.7.1, p4
    char* const seeklo = eback ();
    char* const seekhi = epptr () ? epptr () : egptr ();

    const char* const xnext = which & ios::in ? gptr () : pptr ();
    const char* const xbeg  = which & ios::in ? eback () : pbase ();

    // D.7.1.3, p13
    if (!xnext)
        return pos_type (off_type (-1));

    off_type saved_off = off;

    // compute new offset - D.7.1.3, p13, table 105
    if (ios::cur == way)
        off += off_type (xnext - xbeg);
    else if (ios::end == way)
        off += off_type (seekhi - xbeg);

    // test conditions in D.7.1.3, p13, table 105, row 4
    if (off < seeklo - xbeg || off > seekhi - xbeg)
        off = -1;   // failure
    else if (which & ios::in) {   // position input sequence

        // fail if `way' is `cur', otherwise position output sequence first
        if (   which & ios::out
            && (   way == ios::cur
                || pos_type (-1) == seekoff (saved_off, way, ios::out)))
            return pos_type (off_type (-1));

        // adjust input sequence as necessary to maintain invariant
        if (off <= egptr () - eback ())
            setg (eback (), eback () + off, egptr ());
        else if (off <= pptr () - egptr ())   // advance egptr()
            setg (eback (), eback () + off, pptr ());
        else   // advance egptr() even further
            setg (eback (), eback () + off, epptr ());
    }
    else if (which & ios::out) {   // position output sequence
        if (seeklo + off < pbase ()) {
            // adjust beginning of output sequence, then increment pptr()
            setp (seeklo, epptr ());
            pbump (off);
        }
        else {
            // reset pptr() first, then increment it by offset
            setp (pbase (), epptr ());
            pbump (off - (pbase () - seeklo));
        }
    }
    else
        off = -1;   // failure

    _RWSTD_ASSERT (_C_is_valid ());

    return pos_type (off);
}
Beispiel #29
0
PRfilebuf*	
PRfilebuf::open(const char *name, int mode, int flags)
{
     if (_fd != 0)
        return 0;    // error if already open
     PRIntn PRmode = 0;
    // translate mode argument
    if (!(mode & ios::nocreate))
        PRmode |= PR_CREATE_FILE;
    //if (mode & ios::noreplace)
    //    PRmode |= O_EXCL;
    if (mode & ios::app){
        mode |= ios::out;
        PRmode |= PR_APPEND;
    }
    if (mode & ios::trunc){
        mode |= ios::out;  // IMPLIED
        PRmode |= PR_TRUNCATE;
    }
    if (mode & ios::out){
        if (mode & ios::in)
            PRmode |= PR_RDWR;
        else
            PRmode |= PR_WRONLY;
        if (!(mode & (ios::in|ios::app|ios::ate|ios::noreplace))){
            mode |= ios::trunc; // IMPLIED
            PRmode |= PR_TRUNCATE;
        }
    }else if (mode & ios::in)
        PRmode |= PR_RDONLY;
    else
        return 0;    // error if not ios:in or ios::out


    //
    // The usual portable across unix crap...
    // NT gets a hokey piece of junk layer that prevents
    // access to the API.
#ifdef WIN32
    _fd = PR_Open(name, PRmode, PRmode);
#else
    _fd = PR_Open(name, PRmode, flags);
#endif
    if (_fd == 0)
        return 0;
    _opened = PR_TRUE;
    if ((!unbuffered()) && (!ebuf())){
        char * sbuf = new char[STRM_BUFSIZ];
        if (!sbuf)
            unbuffered(1);
        else{
			_allocated = PR_TRUE;
            streambuf::setb(sbuf,sbuf+STRM_BUFSIZ,0);
		}
    }
    if (mode & ios::ate){
        if (seekoff(0,ios::end,mode)==EOF){
            close();
            return 0;
        }
    }
    return this;
}
Beispiel #30
0
mem_streambuf::pos_type mem_streambuf::seekpos( pos_type pos,
                                                ios_base::openmode mode ) {
  return seekoff( pos, ios_base::beg, mode );
}