Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion warnings on compile
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Sweet  
View profile  
 More options Dec 15 2000, 1:08 pm
Newsgroups: mailing.unix.samba-technical
From: m...@easysw.com (Michael Sweet)
Date: 16 Dec 2000 02:08:16 +0800
Local: Fri, Dec 15 2000 1:08 pm
Subject: Re: warnings on compile

Jeremy Allison wrote:
> ...
> That's a good idea, we should look into grabbing the
> code from glibc or something and modifying it for our
> own use. Any volenteers ? :-).

Here's the code from CUPS that replaces the mkstemp() functionality
with something that is fairly portable; feel free to rip out the
Windows code... :)

/*
 * 'cupsTempFile()' - Generate a temporary filename.
 */

char *                                  /* O - Filename */
cupsTempFile(char *filename,            /* I - Pointer to buffer */
             int  len)                  /* I - Size of buffer */
{
  int           fd;                     /* File descriptor for temp file */
#ifdef WIN32
  char          tmpdir[1024];           /* Windows temporary directory */
#else
  char          *tmpdir;                /* TMPDIR environment var */
#endif /* WIN32 */
  struct timeval curtime;               /* Current time */
  static char   buf[1024] = "";               /* Buffer if you pass in NULL and 0 */

 /*
  * See if a filename was specified...
  */

  if (filename == NULL)
  {
    filename = buf;
    len      = sizeof(buf);
  }

 /*
  * See if TMPDIR is defined...
  */

#ifdef WIN32
  GetTempPath(sizeof(tmpdir), tmpdir);
#else
  if ((tmpdir = getenv("TMPDIR")) == NULL)
  {
   /*
    * Put root temp files in restricted temp directory...
    */

    if (getuid() == 0)
      tmpdir = CUPS_REQUESTS "/tmp";
    else
      tmpdir = "/var/tmp";
  }
#endif /* WIN32 */

 /*
  * Make the temporary name using the specified directory...
  */

  do
  {
   /*
    * Get the current time of day...
    */

    gettimeofday(&curtime, NULL);

   /*
    * Format a string using the hex time values...
    */

    snprintf(filename, len - 1, "%s/%08x%05x", tmpdir,
             curtime.tv_sec, curtime.tv_usec);

   /*
    * Open the file in "exclusive" mode, making sure that we don't
    * stomp on an existing file or someone's symlink crack...
    */

#ifdef O_NOFOLLOW
    fd = open(filename, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
#else
    fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
#endif /* O_NOFOLLOW */
  }
  while (fd < 0);

 /*
  * Close the temp file - it'll be reopened later as needed...
  */

  close(fd);

 /*
  * Return the temp filename...
  */

  return (filename);

}

--
______________________________________________________________________
Michael Sweet, Easy Software Products                  m...@easysw.com
Printing Software for UNIX                       http://www.easysw.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.