Ticket #2179: ed-0.2-mkstemp-2.patch

File ed-0.2-mkstemp-2.patch, 979 bytes (added by Tyler Berry, 18 years ago)
  • buf.c

    This is based on the following:
    ===
    Submitted By: LFS Book <lfs-book@linuxfromscratch.org>
    Date: 2003-10-05
    Initial Package Version: 0.2
    Origin: Slackware Source
    Description: Use mkstemp instead of mktemp.
    ===
    However the original patch contained an error.
    mkstemp returns a file description, so when fopen ran, the file was opened twice.
    The correct change is to use fdopen with mkstemp.
    See gentoo bug #73858.
    diff -Naur ed-0.2/buf.c ed-0.2-2/buf.c
    old new  
    200200int
    201201open_sbuf ()
    202202{
    203   char *mktemp ();
    204   int u;
     203  int u, sfd;
    205204
    206205  isbinary = newline_added = 0;
    207206  u = umask(077);
    208207  strcpy (sfn, "/tmp/ed.XXXXXX");
    209   if (mktemp (sfn) == NULL || (sfp = fopen (sfn, "w+")) == NULL)
     208  sfd = mkstemp(sfn);
     209  if ((sfd == -1) || (sfp = fdopen (sfd, "w+")) == NULL)
    210210    {
    211211      fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
    212212      sprintf (errmsg, "Cannot open temp file");