lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LYNX-DEV Re: mkstemp source


From: Larry W. Virden, x2487
Subject: LYNX-DEV Re: mkstemp source
Date: Sat, 10 May 1997 04:09:47 -0400

Thanks for posting the modified version of mkstemp.  If you don't mind,
I've a few trivial changes to propose.

1. Add a couple of includes that in theory were missing.
2. Fix the comment to reflect the new functionaly.
3. Rename the function.  Since we changed the number of arguments, then
I propose we use a different name, to prevent confusion with the default
one.  While the linker would be fine with this, I believe it is best not
to confuse folk by using the same name for slightly different functional
entities if at all possible.
4. I had to remove the const so that gcc didn't complain.  I would rather
leave it there - I can't explain why gcc would say

mkstempx.c: In function `mkstempx':
mkstempx.c:42: warning: ANSI C forbids nested functions
mkstempx.c:42: syntax error before `char'
mkstempx.c:59: `letters' undeclared (first use this function)
mkstempx.c:59: (Each undeclared identifier is reported only once
mkstempx.c:59: for each function it appears in.)

when I left the const in there.

5.  I added a new edit that returns an error if xstart is passed as a
value that would clobber something outside the template.

6. I fixed a few references to n that needed to change to xstart.

7. I changed the open mode from rw-rw-rw- to rw------- .  Since this
is going to be a lynx specific function anyways, I wasn't aware of any
cases where we needed anyone other than the user to have write access to
any file being created by lynx.


--- /home/lwv26/pmk     Sat May 10 03:54:04 1997
+++ /home/lwv26/mkstempx.c      Sat May 10 03:56:52 1997
@@ -18,2 +18,7 @@
 
+/* LINTLIBRARY */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <stdlib.h>
@@ -21,8 +26,7 @@
 #include <errno.h>
-#include <stdio.h>
 #include <fcntl.h>
-#include <unistd.h>
+#include <stdio.h>
 
 /* Generate a unique temporary file name from TEMPLATE.
-   The last six characters of TEMPLATE must be "XXXXXX";
+   The six characters of TEMPLATE beginning at xstart must be "XXXXXX";
    they are replaced with a string that makes the filename unique.
@@ -30,3 +34,3 @@
 int
-mkstemp (template, xstart)
+mkstempx (template, xstart)
      char *template;
@@ -34,3 +38,5 @@
 {
-  static const char letters[]
+/*static const char letters[] */
+/* Why does gcc complain if I leave the const in? */
+  static char letters[] 
     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@ -40,3 +46,3 @@
   len = strlen (template);
-  if (len < 6 || strcmp (&template[n], "XXXXXX"))
+  if ((len < 6) || (xstart > (len-6)) || strcmp (&template[xstart], "XXXXXX"))
     {
@@ -46,3 +52,3 @@
 
-  if (sprintf (&template[n + 1], "%.5u",
+  if (sprintf (&template[xstart + 1], "%5.5u",
               (unsigned int) getpid () % 100000) != 5)
@@ -55,5 +61,5 @@
 
-      template[n] = letters[i];
+      template[xstart] = letters[i];
 
-      fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0666);
+      fd = open (template, O_RDWR|O_CREAT|O_EXCL, S_IRUSR+S_IWUSR);
       if (fd >= 0)
-- 
Larry W. Virden                 INET: address@hidden
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should 
be construed as representing my employer's opinions.
;
; To UNSUBSCRIBE:  Send a mail message to address@hidden
;                  with "unsubscribe lynx-dev" (without the
;                  quotation marks) on a line by itself.
;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]