delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/02/16/12:17:58

Message-Id: <m0y4OUB-000S2WC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: djgpp-workers AT delorie DOT com
Date: Mon, 16 Feb 1998 14:21:57 +0000
MIME-Version: 1.0
Subject: open patch for share flags

Hi All:

  Here are the needed patchs to open.c, fcntl.h, open.txh and fopen.txh to
add the __djgpp_share_flags feature.
  As we discussed with Eli the new feature doesn't change anything if you
don't indicate a value in __djgpp_share_flags.
  Even if you indicate a value in __djgpp_share_flags and you call open with
some share flag the values passed in the call will be used.

  DJ: Please check my additions to the docs, me english is very bad.

SET

P.S. The diffs are from the djgpp root, with -c3 and using /.

*** src/libc/posix/fcntl/open.old	Sun Nov 16 14:05:00 1997
--- src/libc/posix/fcntl/open.c	Sun Feb 15 19:53:50 1998
***************
*** 13,22 ****
  
  #include <libc/dosio.h>
  
  int
  open(const char* filename, int oflag, ...)
  {
!   int fd, dmode, bintext;
  
    /* Check this up front, to reduce cost and minimize effect */
    if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
--- 13,25 ----
  
  #include <libc/dosio.h>
  
+ /* Extra share flags that can be indicated by the user */
+ int __djgpp_share_flags = 0;
+ 
  int
  open(const char* filename, int oflag, ...)
  {
!   int fd, dmode, bintext, dont_have_share;
  
    /* Check this up front, to reduce cost and minimize effect */
    if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
***************
*** 39,52 ****
  
    dmode = (*((&oflag)+1) & S_IWUSR) ? 0 : 1;
  
    fd = _open(filename, oflag);
  
    /* Under multi-taskers, such as Windows, our file might be open
       by some other program with DENY-NONE sharing bit, which fails
       the `_open' call above.  Try again with DENY-NONE bit set,
       unless some sharing bits were already set in the initial call.  */
!   if (fd == -1
!       && ((oflag & (SH_DENYNO | SH_DENYRW | SH_DENYRD | SH_DENYWR)) == 0))
      fd = _open(filename, oflag | SH_DENYNO);
    if (fd == -1 && oflag & O_CREAT)
      fd = _creat(filename, dmode);
--- 42,63 ----
  
    dmode = (*((&oflag)+1) & S_IWUSR) ? 0 : 1;
  
+   /* Merge the share flags if they are specified */
+   dont_have_share = ((oflag &
+                      (SH_DENYNO | SH_DENYRW | SH_DENYRD | SH_DENYWR)) == 0);
+   if (dont_have_share && __djgpp_share_flags)
+     {
+      dont_have_share=0;
+      oflag|=__djgpp_share_flags;
+     }
+ 
    fd = _open(filename, oflag);
  
    /* Under multi-taskers, such as Windows, our file might be open
       by some other program with DENY-NONE sharing bit, which fails
       the `_open' call above.  Try again with DENY-NONE bit set,
       unless some sharing bits were already set in the initial call.  */
!   if (fd == -1 && dont_have_share)
      fd = _open(filename, oflag | SH_DENYNO);
    if (fd == -1 && oflag & O_CREAT)
      fd = _creat(filename, dmode);
*** src/libc/posix/fcntl/open.tx~	Fri Apr 26 21:10:04 1996
--- src/libc/posix/fcntl/open.txh	Sun Feb 15 20:53:24 1998
***************
*** 82,87 ****
--- 82,91 ----
  
  Other @code{S_I*} values may be included, but they will be ignored.
  
+ You can specify the share flags (a DOS specific feature) in @var{mode}.
+ And you can indicate default values for the share flags in
+ @code{__djgpp_share_flags}. @xref{__djgpp_share_flags}.
+ 
  @subheading Return Value
  
  If successful, the file descriptor is returned.  On error, a negative
***************
*** 92,95 ****
--- 96,161 ----
  @example
  int q = open("/tmp/foo.dat", O_RDONLY|O_BINARY);
  @end example
+ 
+ @c 
---------------------------------------------------------------------------
+ @node __djgpp_share_flags, io
+ 
+ @subheading Syntax
+ 
+ @example
+ #include <fcntl.h>
+ 
+ int __djgpp_share_flags = ...;
+ @end example
+ 
+ @subheading Description
+ 
+ This variable controls the share flags used by @code{open} (and hence
+ @code{fopen}) when opening a file.
+ 
+ If you assign any value different than 0 to this variable libc will
+ merge this value with the flags passed to @code{open}. But if you specify
+ any share flag in the @code{open} call then these flags will remain
+ untouched. In this way @code{__djgpp_share_flags} acts just like a default
+ and by default is 0 ensuring maximun compatibility with older versions of
+ djgpp.
+ 
+ If you don't know how the share flags act consult any DOS reference. They
+ allow to share or protect a file when it's opened more than ones by the
+ same task or by two or more tasks. The exact behavior depends on the exact
+ case. One interesting thing is that when the file is openen by two tasks
+ under Windows the results are different if you use Windows 3.1 or Windows 95.
+ To add even more complexity Windows 3.1 is affected by @code{SHARE.EXE}.
+ 
+ The available flags are:
+ 
+ @table @code
+ 
+ @item SH_COMPAT	0x0000
+ 
+ That's the compatible mode.
+ 
+ @item SH_DENYRW	0x0010
+ 
+ Deny read and deny write.
+ 
+ @item SH_DENYWR	0x0020
+ 
+ Deny write.
+ 
+ @item SH_DENYRD	0x0030
+ 
+ Deny read.
+ 
+ @item SH_DENYNO	0x0040
+ 
+ No deny.
+ 
+ @end table
+ 
+ Of course these flags are DOS specific and doesn't exist under other OSs;
+ and as you can imagine @code{__djgpp_share_flags} is djgpp specific.
+ 
+ @xref{open}.
+ @xref{fopen}.
  
*** src/libc/ansi/stdio/fopen.tx~	Sun Aug 31 16:13:18 1997
--- src/libc/ansi/stdio/fopen.txh	Sun Feb 15 20:25:00 1998
***************
*** 68,73 ****
--- 68,76 ----
  If @code{b} or @code{t} is not specified in @var{mode}, the file type is
  chosen by the value of @code{fmode} (@pxref{_fmode}). 
  
+ If you need to specify the DOS share flags use the 
@code{__djgpp_share_flags}.
+ @xref{__djgpp_share_flags}.
+ 
  @subheading Return Value
  
  A pointer to the @code{FILE} object, or @code{NULL} if there was an
*** include/fcntl.old	Thu Sep 26 22:23:32 1996
--- include/fcntl.h	Sun Feb 15 20:01:16 1998
***************
*** 71,76 ****
--- 71,78 ----
  #define _SH_DENYRD	SH_DENYRD
  #define _SH_DENYNO	SH_DENYNO
  
+ extern int __djgpp_share_flags;
+ 
  #define S_IREAD		S_IRUSR
  #define S_IWRITE	S_IWUSR
  #define S_IEXEC		S_IXUSR


------------------------------------ 0 --------------------------------
Visit my home page: http://set-soft.home.ml.org/
or
http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-sot AT usa DOT net - ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019