Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. sopen() function in filehandling - "C"

sopen() function in filehandling - "C"

Scheduled Pinned Locked Moved Managed C++/CLI
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amrit Agr
    wrote on last edited by
    #1

    Hi Developers, I have read about sopen() function to open a file in shared mode. Here is the code.

    #include <stdio.h>
    #include <fcntl.h>
    #include <sys\stat.h>
    #include <io.h>
    #include <share.h>
    void main(void);
    void main(void)
    {
    int file_handle;
    /* Note that sopen() is not ANSI compliant */
    file_handle = sopen"D:\\Study\\file.txt", O_RDWR, SH_DENYNO);
    close(file_handle);
    }

    I am getting "-1" on file_handle and program is also getting crash. Can u please help me out.

    J R 2 Replies Last reply
    0
    • A Amrit Agr

      Hi Developers, I have read about sopen() function to open a file in shared mode. Here is the code.

      #include <stdio.h>
      #include <fcntl.h>
      #include <sys\stat.h>
      #include <io.h>
      #include <share.h>
      void main(void);
      void main(void)
      {
      int file_handle;
      /* Note that sopen() is not ANSI compliant */
      file_handle = sopen"D:\\Study\\file.txt", O_RDWR, SH_DENYNO);
      close(file_handle);
      }

      I am getting "-1" on file_handle and program is also getting crash. Can u please help me out.

      J Offline
      J Offline
      John Schroedl
      wrote on last edited by
      #2

      Check the documentation. A hint: You need to check errno to get the reason for the failure. Compare that result to the items in errno.h (ex. EACCES, EEXIST, etc..).

      1 Reply Last reply
      0
      • A Amrit Agr

        Hi Developers, I have read about sopen() function to open a file in shared mode. Here is the code.

        #include <stdio.h>
        #include <fcntl.h>
        #include <sys\stat.h>
        #include <io.h>
        #include <share.h>
        void main(void);
        void main(void)
        {
        int file_handle;
        /* Note that sopen() is not ANSI compliant */
        file_handle = sopen"D:\\Study\\file.txt", O_RDWR, SH_DENYNO);
        close(file_handle);
        }

        I am getting "-1" on file_handle and program is also getting crash. Can u please help me out.

        R Offline
        R Offline
        ramrooney
        wrote on last edited by
        #3

        Hi, This is possible, when the file mentioned is not present in the corresponding path or the file name is wrong you get the file handle as -1. And its crashing because, you are trying to close a invalid file handle in close() api.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups