Mail Archives: djgpp-workers/2001/03/04/11:29:46
Hi guys,
I'd really like to wrap this up and get this committed. I've gone back to my
original plan call __set_fd_properties only in open. If Eli or anyone else
definitely thinks I should include it in other places, say so. Or if it turns
out adding calls to __set... is neccessary, the change is just a 'cvs commit'
away.
Current patch (fdprops.c removed so message isn't filtered):
Index: djgpp/src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.55
diff -c -p -r1.55 wc204.txi
*** wc204.txi 2001/02/28 20:55:11 1.55
--- wc204.txi 2001/03/04 16:19:58
*************** as FreeDOS.
*** 331,333 ****
--- 331,340 ----
Functions which convert numeric strings to the corresponding integer
values no longer return non-zero values for strings which begin with
8-bit characters.
+
+ @findex O_TEMPORARY AT r{, 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/03/04 16:20:02
***************
*** 18,23 ****
--- 18,24 ----
#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, ..
*** 148,153 ****
--- 149,155 ----
__file_handle_set(fd, bintext ^ (O_BINARY|O_TEXT));
/* this will do cooked/raw ioctl() on character devices */
setmode(fd, bintext);
+ __set_fd_properties(fd, real_name, oflag);
if(oflag & O_APPEND)
lseek(fd, 0, SEEK_END);
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/03/04 16:20:06
*************** 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}, @code{_creat}, or @code{_creatnew}.
+ 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
Index: djgpp/src/libc/posix/unistd/dup.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup.c,v
retrieving revision 1.1
diff -c -p -r1.1 dup.c
*** dup.c 1995/02/27 00:43:08 1.1
--- dup.c 2001/03/04 16:20:20
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
***************
*** 5,10 ****
--- 6,12 ----
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
+ #include <libc/fdprops.h>
int
dup(int fd)
*************** dup(int fd)
*** 19,23 ****
--- 21,29 ----
return -1;
}
setmode(r.x.ax, __file_handle_modes[fd]);
+
+ if (__has_fd_properties(fd))
+ __dup_fd_properties(fd, r.x.ax);
+
return r.x.ax;
}
Index: djgpp/src/libc/posix/unistd/dup2.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup2.c,v
retrieving revision 1.3
diff -c -p -r1.3 dup2.c
*** dup2.c 1996/09/29 10:20:56 1.3
--- dup2.c 2001/03/04 16:20:23
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
***************
*** 7,12 ****
--- 8,14 ----
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
+ #include <libc/fdprops.h>
int
dup2(int fd, int newfd)
*************** dup2(int fd, int newfd)
*** 25,29 ****
--- 27,37 ----
return -1;
}
setmode(newfd, __file_handle_modes[fd]);
+
+ if (__has_fd_properties(newfd))
+ __set_fd_properties(newfd, NULL, 0);
+ if (__has_fd_properties(fd))
+ __dup_fd_properties(fd, newfd);
+
return newfd;
}
*** /dev/null Sun Mar 4 11:20:46 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 Sun Mar 4 11:20:46 2001
--- djgpp/src/libc/dos/io/fdprops.txh Thu Mar 1 11:33:18 2001
***************
*** 0 ****
--- 1,93 ----
+ @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
+
+ For more information, see @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.
+
+ For more information, see @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}.
+
+ For more information, see @ref{__set_fd_properties} and
+ @ref{__clear_fd_properties}.
+
+ @subheading Return Value
+
+ None.
+
+ @subheading Portability
+
+ @portability !ansi, !posix
+
Index: djgpp/include/fcntl.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/fcntl.h,v
retrieving revision 1.5
diff -c -p -r1.5 fcntl.h
*** fcntl.h 2001/02/01 19:17:17 1.5
--- fcntl.h 2001/03/04 16:20:26
*************** int fcntl(int _fildes, int _cmd, ...);
*** 77,82 ****
--- 77,84 ----
#define O_NOLINK 0x4000
#define O_NOFOLLOW 0x8000
+ #define O_TEMPORARY 0x10000 /* Delete file after closing. */
+
#define SH_COMPAT 0x0000
#define SH_DENYRW 0x0010
#define SH_DENYWR 0x0020
- Raw text -