Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: djgpp-workers AT delorie DOT com Date: Fri, 20 Feb 1998 19:16:06 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: fopen patch for share flags Precedence: bulk Hi All: Here are the second try for 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. And follows the same mechanism used by other variables in libc. 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, my english is very bad. Eli: you too. SET P.S. The diffs are from the djgpp root, with -c3 and using /. ------------------> Start of dif cut here <---------------------------------- *** src/libc/posix/fcntl/~open.c Sun Nov 16 14:05:00 1997 --- src/libc/posix/fcntl/open.c Tue Feb 17 18:43:52 1998 *************** *** 16,22 **** 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)) --- 16,22 ---- 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); --- 39,60 ---- 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.txh Fri Apr 26 21:10:04 1996 --- src/libc/posix/fcntl/open.txh Tue Feb 17 18:42:44 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 + + 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.txh Sun Aug 31 16:13:18 1997 --- src/libc/ansi/stdio/fopen.txh Tue Feb 17 18:42:44 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.h Thu Sep 26 22:23:32 1996 --- include/fcntl.h Tue Feb 17 18:42:44 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 -------------------> End of diff cut here <---------------------------------- Here is the file with the variable, I don't know what's the rigth directory for it because even when is used by open is far from POSIX. ------------------> Start of djshare.c <------------------------------------- /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ /* Extra share flags that can be indicated by the user */ int __djgpp_share_flags = 0; ------------------> End of djshare.c <--------------------------------------- ------------------------------------ 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