Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #59882

Re: How to use a temporary file in a portable way

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: How to use a temporary file in a portable way
Date 2015-04-10 08:29 -0700
Organization None to speak of
Message-ID <87d23cuhle.fsf@kst-u.example.com> (permalink)
References <mg527d$f4p$1@dont-email.me> <UFHVw.245921$bk5.66224@fx06.iad>

Show all headers | View raw


Richard Damon <Richard@Damon-Family.org> writes:
> On 4/9/15 1:22 AM, pozz wrote:
>> How to choose the temporary file name?  How to face the situation when
>> the temporary file name already exist?
>
> Call tmpnam(). From the standard:
> The tmpnam function generates a string that is a valid file name and
> that is not the same as the name of an existing file.

tmpnam() has potential problems.  The Linux man page says:

    Although tmpnam() generates names that are difficult to guess,
    it is nevertheless possible that between the time that tmpnam()
    returns a pathname, and the time that the program opens it,
    another program might create that pathname using open(2), or
    create it as a symbolic link.  This can lead to security holes.
    To avoid such possibilities, use the open(2) O_EXCL flag to
    open the pathname.  Or better yet, use mkstemp(3) or tmpfile(3).

    ...

    BUGS

       Never use this function.  Use mkstemp(3) or tmpfile(3) instead.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to use a temporary file in a portable way pozz <pozzugno@gmail.com> - 2015-04-09 07:22 +0200
  Re: How to use a temporary file in a portable way Robert Wessel <robertwessel2@yahoo.com> - 2015-04-09 02:15 -0500
  Re: How to use a temporary file in a portable way Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-09 11:00 +0100
  Re: How to use a temporary file in a portable way James Kuyper <jameskuyper@verizon.net> - 2015-04-09 08:42 -0400
  Re: How to use a temporary file in a portable way Greg Martin <greg.at.softsprocket@dot.com> - 2015-04-09 15:47 +0000
    Re: How to use a temporary file in a portable way Michael Angelo Ravera <maravera@prodigy.net> - 2015-04-09 14:52 -0700
  Re: How to use a temporary file in a portable way Richard Damon <Richard@Damon-Family.org> - 2015-04-09 23:43 -0400
    Re: How to use a temporary file in a portable way Keith Thompson <kst-u@mib.org> - 2015-04-10 08:29 -0700
      Re: How to use a temporary file in a portable way Richard Damon <Richard@Damon-Family.org> - 2015-04-10 22:31 -0400
  Re: How to use a temporary file in a portable way Nobody <nobody@nowhere.invalid> - 2015-04-10 14:48 +0100

csiph-web