Solved

Shareing Files in C++

Posted on 1997-03-25
2
1,053 Views
Last Modified: 2012-06-27
how can i make file share in c++ fstream?
and not be the _FSOPEN or SOPEN.
0
Comment
Question by:orenw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:mrosen
ID: 1162456
In the third parameter to either the constructor or the open() function, you specify one of the following:

filebuf::openprot, which is equivalent to the operating system default, filebuf::sh_compat, under MS-DOS. The possible nProt values are as follows:
filebuf::sh_compat   Compatibility share mode (MS-DOS only).
filebuf::sh_none   Exclusive mode — no sharing.
filebuf::sh_read   Read sharing allowed.
filebuf::sh_write   Write sharing allowed.

let me know if this solves what you're asking
0
 
LVL 1

Accepted Solution

by:
jmmougeolle earned 200 total points
ID: 1162457
This is the way the stream buf use sopen inside the CRT source:

***************************************************************************
****CALLING TO FILEBUFF::OPEN INSIDE FSTREAM::OPEN
***************************************************************************

void fstream::open(const char * name, int mode, int prot)
{
    if (is_open() || !(rdbuf()->open(name, mode, prot)))
        {
        istream::clear(istream::state | istream::failbit);
        ostream::clear(ostream::state | ostream::failbit);
        }
}

***************************************************************************
****USING SOPEN INSIDE FILEBUFF::OPEN
****where share is equalt to the prot param used upper
**** as an arg for  fstream::open
***************************************************************************

    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 :
                smode = _SH_DENYRW;
                break;
//          case sh_read :
            case 05000 :
                smode = _SH_DENYWR;
                break;
//          case sh_write :
            case 06000 :
                smode = _SH_DENYRD;
                break;
//          case (sh_read|sh_write) :
            case 07000 :
                smode = _SH_DENYNO;
                break;
            default :   // unrecognized value same as default
                break;
            };
        }

    x_fd = _sopen(name, dos_mode, smode, S_IREAD|S_IWRITE);

***************************************************************************

So using:
filebuf::sh_none is equal to SOPEN _SH_DENYRW;
filebuf::sh_read is equal to SOPEN  _SH_DENYWR;
filebuf::sh_write is equal to SOPEN _SH_DENYRW;
filebuf::sh_read|filebuf::sh_write is equal to SOPEN  _SH_DENYNO;

I think that's all the information you need to know!


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question