Index: fhandler.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v retrieving revision 1.239 diff -u -p -d -r1.239 fhandler.cc --- fhandler.cc 6 Jul 2005 20:05:00 -0000 1.239 +++ fhandler.cc 21 Jul 2005 23:27:57 -0000 @@ -639,7 +639,10 @@ fhandler_base::open (int flags, mode_t m if (flags & O_CREAT && get_device () == FH_FS) { - file_attributes = FILE_ATTRIBUTE_NORMAL; + if (pc.file_attributes () == INVALID_FILE_ATTRIBUTES) + file_attributes = FILE_ATTRIBUTE_NORMAL; + else + file_attributes = pc.file_attributes (); /* If mode has no write bits set, we set the R/O attribute. */ if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH))) file_attributes |= FILE_ATTRIBUTE_READONLY; Index: mktemp.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/mktemp.cc,v retrieving revision 1.2 diff -u -p -d -r1.2 mktemp.cc --- mktemp.cc 25 May 2005 03:43:58 -0000 1.2 +++ mktemp.cc 21 Jul 2005 23:27:57 -0000 @@ -101,11 +101,15 @@ _gettemp(char *path, int *doopen, int do } } + DWORD const fileattr = wincap.is_winnt () ? + FILE_ATTRIBUTE_TEMPORARY : FILE_ATTRIBUTE_NORMAL; for (;;) { if (doopen) { - if ((*doopen = open (path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0) + extern int open_with_attributes (const char *, int, mode_t, DWORD); + if ((*doopen = open_with_attributes (path, O_CREAT | O_EXCL | O_RDWR, + 0600, fileattr)) >= 0) return 1; if (errno != EEXIST) return 0; Index: syscalls.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v retrieving revision 1.386 diff -u -p -d -r1.386 syscalls.cc --- syscalls.cc 6 Jul 2005 20:05:03 -0000 1.386 +++ syscalls.cc 21 Jul 2005 23:27:59 -0000 @@ -539,18 +539,15 @@ done: return res; } -/* _open */ -/* newlib's fcntl.h defines _open as taking variable args so we must - correspond. The third arg if it exists is: mode_t mode. */ -extern "C" int -open (const char *unix_path, int flags, ...) + +extern int +open_with_attributes (const char *unix_path, int flags, mode_t mode, + DWORD fileattr) { int res = -1; - va_list ap; - mode_t mode = 0; sig_dispatch_pending (); - syscall_printf ("open (%s, %p)", unix_path, flags); + syscall_printf ("open (%s, %p, %p, %p)", unix_path, flags, mode, fileattr); myfault efault; if (efault.faulted (EFAULT)) /* errno already set */; @@ -558,30 +555,36 @@ open (const char *unix_path, int flags, set_errno (ENOENT); else { - /* check for optional mode argument */ - va_start (ap, flags); - mode = va_arg (ap, mode_t); - va_end (ap); - fhandler_base *fh; cygheap_fdnew fd; if (fd >= 0) { if (!(fh = build_fh_name (unix_path, NULL, PC_SYM_FOLLOW))) - res = -1; // errno already set - else if (((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) && fh->exists ()) + { + res = -1; // errno already set + goto out; + } + else if (((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + && fh->exists ()) { delete fh; res = -1; set_errno (EEXIST); + goto out; } else if (fh->is_fs_special () && fh->device_access_denied (flags)) { delete fh; res = -1; + goto out; } - else if (!fh->open (flags, (mode & 07777) & ~cygheap->umask)) + + if (static_cast(*fh) == INVALID_FILE_ATTRIBUTES) + static_cast(*fh) = fileattr; + else + static_cast(*fh) = static_cast(*fh) | fileattr; + if (!fh->open (flags, (mode & 07777) & ~cygheap->umask)) { delete fh; res = -1; @@ -595,10 +598,31 @@ open (const char *unix_path, int flags, } } - syscall_printf ("%d = open (%s, %p)", res, unix_path, flags); + out: + syscall_printf ("%d = open (%s, %p, %p, %p)", res, unix_path, flags, mode, + fileattr); return res; } + +/* _open */ +/* newlib's fcntl.h defines _open as taking variable args so we must + correspond. The third arg if it exists is: mode_t mode. */ +extern "C" int +open (const char *unix_path, int flags, ...) +{ + va_list ap; + int ret; + mode_t mode; + + va_start (ap, flags); + mode = flags & O_CREAT ? va_arg (ap, mode_t) : 0; + ret = open_with_attributes (unix_path, flags, mode, FILE_ATTRIBUTE_NORMAL); + va_end (ap); + + return ret; +} + EXPORT_ALIAS (open, _open ) EXPORT_ALIAS (open, _open64 )