www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/02/28/15:03:48

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Wed, 28 Feb 2001 14:53:34 -0500
MIME-Version: 1.0
Subject: O_TEMPORARY v3
Message-ID: <3A9D10EE.3225.494F82@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

I made some minor tweaks and added documentation for the support functions and
wc204.txi. I incorporated Eli's suggestion to move the __set_fd_properties call
into _open and _creatnew, however I'm not sure about one change I made:

*************** open(const char* filename, int oflag, .. *** 107,113 ****
}  

    if (should_create)
!     fd = _creatnew(real_name, dmode, oflag & 0xff);
    else
    {
      fd = _open(real_name, oflag);
--- 109,115 ----
      }

    if (should_create)
!     fd = _creatnew(real_name, dmode, oflag);
    else
    {
      fd = _open(real_name, oflag);


If the masking with 0xff is neccessary, I can rework that part.

I had to leavet out chunks of the patch because it triggered DJ's filter. However, it's basically the same 
except that the code that decrements
the reference count was split off into a separate function.  

The complete patch is at <http://members.nbci.com/snowball3/djgpp/djgpp.dif>.

Mark

Index: djgpp/src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.54
diff -c -p -r1.54 wc204.txi
*** wc204.txi	2001/02/25 18:10:25	1.54
--- wc204.txi	2001/02/28 17:52:51
*************** the C AT t{++} standard, and also recommend
*** 322,324 ****
--- 322,330 ----
  @code{_get_dos_version} now recognises @acronym{OEM} number @code{0xfd}
  as FreeDOS.
  
+ @findex O_TEMPORARYr{, new flag accepted by @code{open}}
+ @findex open AT r{, supports temporary files}
+ @code{open} now honors @code{O_TEMPORARY}.  A file opened with
+ @code{O_TEMPORARY} will be deleted when all file descriptors that refer
+ to it are closed.
+ 
Index: djgpp/src/libc/posix/fcntl/open.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/fcntl/open.c,v
retrieving revision 1.7
diff -c -p -r1.7 open.c
*** open.c	2000/08/28 14:22:33	1.7
--- open.c	2001/02/28 17:52:54
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
***************
*** 18,23 ****
--- 19,25 ----
  #include <io.h>
  
  #include <libc/dosio.h>
+ #include <libc/fdprops.h>
  
  /* Extra share flags that can be indicated by the user */
  int __djgpp_share_flags;
*************** open(const char* filename, int oflag, ..
*** 107,113 ****
      }
  
    if (should_create)
!     fd = _creatnew(real_name, dmode, oflag & 0xff);
    else
    {
      fd = _open(real_name, oflag);
--- 109,115 ----
      }
  
    if (should_create)
!     fd = _creatnew(real_name, dmode, oflag);
    else
    {
      fd = _open(real_name, oflag);
*************** open(const char* filename, int oflag, ..
*** 132,138 ****
        /* Don't call _creat on existing files for which _open fails,
           since the file could be truncated as a result.  */
        else if ((oflag & O_CREAT))
! 	fd = _creat(real_name, dmode);
      }
    }
  
--- 134,144 ----
        /* Don't call _creat on existing files for which _open fails,
           since the file could be truncated as a result.  */
        else if ((oflag & O_CREAT))
!       {
!         fd = _creat(real_name, dmode);
!         if (fd != -1)
!           __set_fd_properties(fd, real_name, oflag);
!       }
      }
    }
  
Index: djgpp/src/libc/posix/fcntl/open.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/fcntl/open.txh,v
retrieving revision 1.6
diff -c -p -r1.6 open.txh
*** open.txh	2001/01/01 17:52:03	1.6
--- open.txh	2001/02/28 17:52:58
*************** component in @var{file} is symlink.
*** 78,83 ****
--- 78,91 ----
  If @var{file} is a symlink, @code{open} will open symlink file itself instead 
  of referred file.
  
+ @item O_TEMPORARY
+ 
+ Delete @var{file} when all file descriptors that refer to it are closed.
+ 
+ Note that @var{file} should not also be opened with
+ @code{_dos_creat}, @code{_dos_creatnew}, @code{_dos_open}, or @code{_creat}.  
+ Otherwise @var{file} may not be deleted as expected.
+ 
  @end table
  
  If the file is created by this call, it will be given the read/write
*** /dev/null	Wed Feb 28 12:53:37 2001
--- djgpp/include/libc/fdprops.h	Mon Feb 26 18:44:18 2001
***************
*** 0 ****
--- 1,48 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
+ #ifndef __dj_include_libc_fdprops_h__
+ #define __dj_include_libc_fdprops_h__
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
+ #ifndef __dj_ENFORCE_ANSI_FREESTANDING
+ 
+ #ifndef __STRICT_ANSI__
+ 
+ #ifndef _POSIX_SOURCE
+ 
+ /* Delete file when the last descriptor referencing it is closed.  */
+ #define FILE_DESC_TEMPORARY 1
+ 
+ typedef struct fd_properties fd_properties;
+ 
+ struct fd_properties
+ {
+   unsigned char ref_count;
+   char *filename;
+   unsigned long flags;
+   fd_properties *prev;
+   fd_properties *next;
+ };
+ 
+ extern fd_properties ** __fd_properties;
+ 
+ int __set_fd_properties(int _fd, const char * _file, int _oflags);
+ void __dup_fd_properties(int _from, int _to);
+ int __clear_fd_properties(int _fd);
+ 
+ static __inline__ int __has_fd_properties(int _fd)
+ {
+   return __fd_properties && __fd_properties[_fd];
+ }
+ 
+ #endif /* !_POSIX_SOURCE */
+ #endif /* !__STRICT_ANSI__ */
+ #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+ 
+ #ifdef __cplusplus
+ }
+ #endif
+ 
+ #endif /* __dj_include_libc_fdprops_h__  */
*** /dev/null	Wed Feb 28 12:53:37 2001
--- djgpp/src/libc/dos/io/fdprops.txh	Wed Feb 28 00:56:04 2001
***************
*** 0 ****
--- 1,90 ----
+ @node __set_fd_properties, io
+ @subheading Syntax
+ 
+ @example
+ #include <libc/fdprops.h>
+ 
+ int __set_fd_properties(int fd, const char *filename, int open_flags);
+ 
+ @end example
+ 
+ @subheading Description
+ 
+ This is an internal function that stores information about the file descriptor
+ @var{fd} in a @code{fd_properties} struct.  It is called by @code{open} and
+ its helper functions.
+ 
+ @example
+ struct fd_properties
+ @{
+   unsigned char ref_count;
+   char *filename;
+   unsigned long flags;
+   fd_properties *prev;
+   fd_properties *next;
+ @};
+ @end example
+ 
+ See also @ref{__clear_fd_properties} and @ref{__dup_fd_properties}.
+ 
+ @subheading Return Value
+ 
+ Returns 0 on success. Returns -1 when unable to store the information.
+ 
+ @subheading Portability
+ 
+ @portability !ansi, !posix
+ 
+ @node __clear_fd_properties, io
+ @subheading Syntax
+ 
+ @example
+ #include <libc/fdprops.h>
+ 
+ int __clear_fd_properties(int fd);
+ 
+ @end example
+ 
+ @subheading Description
+ 
+ This internal function is called when the file descriptor @var{fd} is
+ no longer valid.  The usage count of the associated @code{fd_properties} struct
+ is decremented.  And if it becomes zero, this function performs cleanup
+ and releases the memory used by the @code{fd_properties} struct.
+ 
+ See also @ref{__set_fd_properties} and @ref{__dup_fd_properties}.
+ 
+ @subheading Return Value
+ 
+ Always returns 0 for success.
+ 
+ @subheading Portability
+ 
+ @portability !ansi, !posix
+ 
+ @node __dup_fd_properties, io
+ @subheading Syntax
+ 
+ @example
+ #include <libc/fdprops.h>
+ 
+ void __dup_fd_properties(int existing_handle, int new_handle);
+ 
+ @end example
+ 
+ @subheading Description
+ 
+ Causes the new file descriptor @var{new_handle} to refer to the same
+ @code{fd_properties} struct as @var{existing_handle}.  
+ This internal function is called by @code{dup} and @code{dup2}.
+ 
+ See also @ref{__set_fd_properties} and @ref{__clear_fd_properties}.
+ 
+ @subheading Return Value
+ 
+ None.
+ 
+ @subheading Portability
+ 
+ @portability !ansi, !posix
+ 

- Raw text -


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