This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mkstemps


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Corinna Vinschen on 6/28/2009 4:32 AM:
>> I'm not sure whether the changes are
>> trivial enough for me to do for cygwin (where I don't have copyright on
>> file), so I'm floating this out there to see if anyone else is willing to
>> write the patch.
> 
> Well, if your patch is accepted in newlib, it should be not much of a
> problem to tweak it slightly for inclusion into Cygwin, even if you're
> doing the tweak...

With that vote of confidence, here's the patch (the changes to mktemp.cc,
modulo a changed variable name, mirror newlib):

2009-07-03  Eric Blake  <ebb9@byu.net>

	Add fpurge, mkstemps.
	* cygwin.din (fpurge, mkstemps): New exports.
	* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
	* mktemp.cc (_gettemp): Add parameter.
	(mkstemps): New function.
	(mkstemp, mkdtemp, mktemp): Adjust clients.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpN+j4ACgkQ84KuGfSFAYAyDQCeKPVVyrgagHMp2K567i4+w6MG
tDcAoNZcS42SAHofdZDt/23Q6XyrmTnb
=0Uss
-----END PGP SIGNATURE-----
Index: cygwin.din
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/cygwin.din,v
retrieving revision 1.212
diff -u -p -r1.212 cygwin.din
--- cygwin.din	28 Jun 2009 18:23:35 -0000	1.212
+++ cygwin.din	3 Jul 2009 12:28:42 -0000
@@ -505,6 +505,7 @@ __fpclassifyd NOSIGFE
 __fpclassifyf NOSIGFE
 fprintf SIGFE
 _fprintf = fprintf SIGFE
+fpurge SIGFE
 fputc SIGFE
 _fputc = fputc SIGFE
 fputs SIGFE
@@ -984,6 +985,7 @@ _mknod32 = mknod32 SIGFE
 mknodat SIGFE
 mkstemp SIGFE
 _mkstemp = mkstemp SIGFE
+mkstemps SIGFE
 mktemp SIGFE
 _mktemp = mktemp SIGFE
 mktime SIGFE
Index: mktemp.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mktemp.cc,v
retrieving revision 1.5
diff -u -p -r1.5 mktemp.cc
--- mktemp.cc	13 Mar 2009 20:49:42 -0000	1.5
+++ mktemp.cc	3 Jul 2009 12:28:42 -0000
@@ -1,15 +1,16 @@
 /* mktemp.cc: mktemp functions
 
-This file is adapted for Cygwin from FreeBSD.
+This file is adapted for Cygwin from FreeBSD and newlib.
 
 See the copyright at the bottom of this file. */
 
 #include "winsup.h"
 #include "cygerrno.h"
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
-static int _gettemp(char *, int *, int);
+static int _gettemp(char *, int *, int, size_t);
 static uint32_t arc4random ();
 
 static const char padchar[] =
@@ -19,23 +20,30 @@ extern "C" int
 mkstemp(char *path)
 {
   int fd;
-  return _gettemp(path, &fd, 0) ? fd : -1;
+  return _gettemp(path, &fd, 0, 0) ? fd : -1;
 }
 
 extern "C" char *
 mkdtemp(char *path)
 {
-  return _gettemp(path, NULL, 1) ? path : NULL;
+  return _gettemp(path, NULL, 1, 0) ? path : NULL;
+}
+
+extern "C" int
+mkstemps(char *path, int len)
+{
+  int fd;
+  return _gettemp(path, &fd, 0, len) ? fd : -1;
 }
 
 extern "C" char *
 mktemp(char *path)
 {
-  return _gettemp(path, NULL, 0) ? path : (char *) NULL;
+  return _gettemp(path, NULL, 0, 0) ? path : (char *) NULL;
 }
 
 static int
-_gettemp(char *path, int *doopen, int domkdir)
+_gettemp(char *path, int *doopen, int domkdir, size_t suffixlen)
 {
   char *start, *trv, *suffp;
   char *pad;
@@ -46,12 +54,14 @@ _gettemp(char *path, int *doopen, int do
       return 0;
     }
 
-  suffp = trv = strchr (path, '\0');
-  if (--trv < path)
+  trv = strchr (path, '\0');
+  if (trv - path < suffixlen)
     {
       set_errno (EINVAL);
       return 0;
     }
+  trv -= suffixlen;
+  suffp = trv--;
 
   /* Fill space with random characters */
   while (trv >= path && *trv == 'X')
@@ -59,6 +69,11 @@ _gettemp(char *path, int *doopen, int do
       uint32_t rand = arc4random () % (sizeof (padchar) - 1);
       *trv-- = padchar[rand];
     }
+  if (suffp - trv < 6)
+    {
+      set_errno (EINVAL);
+      return 0;
+    }
   start = trv + 1;
 
   /*
Index: include/cygwin/version.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/cygwin/version.h,v
retrieving revision 1.295
diff -u -p -r1.295 version.h
--- include/cygwin/version.h	9 May 2009 20:16:06 -0000	1.295
+++ include/cygwin/version.h	3 Jul 2009 12:28:42 -0000
@@ -364,12 +364,13 @@ details. */
       208: Export log2, log2f.
       209: Export wordexp, wordfree.
       210: New ctype layout using variable ctype pointer.  Export __ctype_ptr__.
+      211: Export fpurge, mkstemps.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 210
+#define CYGWIN_VERSION_API_MINOR 211
 
      /* There is also a compatibity version number associated with the
 	shared memory regions.  It is incremented when incompatible

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]