Ignore:
Timestamp:
Mar 19, 2000, 4:35:32 PM (25 years ago)
Author:
davidr
Message:

Ported changes from wine/corel sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/stg_stream.cpp

    r1033 r3167  
    1 /* $Id: stg_stream.cpp,v 1.1 1999-09-24 21:49:44 davidr Exp $ */
     1/* $Id: stg_stream.cpp,v 1.2 2000-03-19 15:33:07 davidr Exp $ */
    22/*
    33 * Compound Storage (32 bit version)
     
    6565StgStreamImpl* StgStreamImpl_Construct(
    6666                StorageBaseImpl* parentStorage,
     67                DWORD            grfMode,
    6768                ULONG              ownerProperty)
    6869{
     
    7677     * Set-up the virtual function table and reference count.
    7778     */
    78     newStream->lpvtbl = &StgStreamImpl_Vtbl;
     79    ICOM_VTBL(newStream) = &StgStreamImpl_Vtbl;
    7980    newStream->ref    = 0;
    8081   
     
    8687    IStorage_AddRef((IStorage*)newStream->parentStorage);
    8788   
     89    newStream->grfMode = grfMode;   
    8890    newStream->ownerProperty = ownerProperty;
    8991   
     
    431433  *pcbWritten = 0;
    432434
     435  /*
     436   * Do we have permission to write to this stream?
     437   */
     438  if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
     439    return STG_E_ACCESSDENIED;
     440
    433441  if (cb == 0)
    434442  {
     
    533541  }
    534542
    535   /*
    536    * We don't support files with offsets of 64 bits.
    537    */
    538   assert(dlibMove.HighPart == 0);
    539 
    540   /*
    541    * Check if we end-up before the beginning of the file. That should trigger an
    542    * error.
    543    */
    544   if ( (dlibMove.LowPart<0) && (plibNewPosition->LowPart < (ULONG)(-dlibMove.LowPart)) )
    545   {
     543#if SIZEOF_LONG_LONG >= 8
     544  plibNewPosition->QuadPart += dlibMove.QuadPart;
     545#else
     546  /*
     547   * do some multiword arithmetic:
     548   *    treat HighPart as a signed value
     549   *    treat LowPart as unsigned
     550   *  NOTE: this stuff is two's complement specific!
     551   */
     552  if (dlibMove.HighPart < 0) { /* dlibMove is < 0 */
     553      /* calculate the absolute value of dlibMove ... */
     554      dlibMove.HighPart = -dlibMove.HighPart;
     555      dlibMove.LowPart ^= -1;
     556      /* ... and subtract with carry */
     557      if (dlibMove.LowPart > plibNewPosition->LowPart) {
     558          /* carry needed, This accounts for any underflows at [1]*/
     559          plibNewPosition->HighPart -= 1;
     560      }
     561      plibNewPosition->LowPart -= dlibMove.LowPart; /* [1] */
     562      plibNewPosition->HighPart -= dlibMove.HighPart;
     563  } else {
     564      /* add directly */
     565      int initialLowPart = plibNewPosition->LowPart;
     566      plibNewPosition->LowPart += dlibMove.LowPart;
     567      if((plibNewPosition->LowPart < initialLowPart) ||
     568         (plibNewPosition->LowPart < dlibMove.LowPart)) {
     569          /* LowPart has rolled over => add the carry digit to HighPart */
     570          plibNewPosition->HighPart++;
     571      }
     572      plibNewPosition->HighPart += dlibMove.HighPart;
     573  }
     574  /*
     575   * Check if we end-up before the beginning of the file. That should
     576   * trigger an error.
     577   */
     578  if (plibNewPosition->HighPart < 0) {
     579      return STG_E_INVALIDPOINTER;
     580  }
     581
    546582    /*
    547      * I don't know what error to send there.
     583   * We currently don't support files with offsets of >32 bits. 
     584   * Note that we have checked for a negative offset already
    548585     */
    549     return E_FAIL;
    550   }
    551 
    552   /*
    553    * Move the actual file pointer
    554    * If the file pointer ends-up after the end of the stream, the next Write operation will
    555    * make the file larger. This is how it is documented.
    556    */
    557   plibNewPosition->LowPart += dlibMove.LowPart;
     586  assert(plibNewPosition->HighPart <= 0);
     587
     588#endif
     589
     590  /*
     591   * tell the caller what we calculated
     592   */
    558593  This->currentPosition = *plibNewPosition;
    559594 
     
    587622    return STG_E_INVALIDFUNCTION;
    588623 
     624  /*
     625   * Do we have permission?
     626   */
     627  if (!(This->grfMode & (STGM_WRITE | STGM_READWRITE)))
     628    return STG_E_ACCESSDENIED;
     629
    589630  if (This->streamSize.LowPart == libNewSize.LowPart)
    590631    return S_OK;
     
    828869                                     grfStatFlag);
    829870   
     871    pstatstg->grfMode = This->grfMode;
     872
    830873    return S_OK;
    831874  }
Note: See TracChangeset for help on using the changeset viewer.