From 4093600811041957913
X-Google-Thread: f78e5,a3e3a55c5c3611c7
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 06 Dec 2006 12:22:24 -0600
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
From: "Greg Herlihy" <greghe@pacbell.net>
Newsgroups: comp.std.c++
Subject: Re: atomically opening a file for writing that doesn't already exist?
Organization: http://groups.google.com
Message-ID: <1165429122.808500.223310@l12g2000cwl.googlegroups.com>
References: <ekpk7k$br4$1@usenet02.sei.cmu.edu>
   <1165254139.347580.314450@l12g2000cwl.googlegroups.com>
   <slrnenc793.bst.ben-public-nospam@decadent.org.uk>
   <1165417423.638927.208290@79g2000cws.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: l12g2000cwl.googlegroups.com; posting-host=71.141.228.239;
   posting-account=JdllFQ0AAAC-QghphnHMZz5q0GHnzGUJ
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Date: Wed,  6 Dec 2006 12:20:50 CST
Lines: 47
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-y6ZbdApucHcU82Dmfr1a4PLdShrWpb3FU+d1bHNQ6degQmSitMgmv1nxSI/Ubx7M39+UDkKaDoTenxb!q66FwMX/gSbn7KbuRPzsjjLXqe3cLuOrwMwTePRKsIxPt0CEF+yIDI4MCQtZvQeiqLAXnPieWsm6!zBkVK525ObG9+cKidRqHv0hoRcVdfKFOvWzrrudUZ4w=
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: g2news2.google.com comp.std.c++:4948


James Kanze wrote:
> Ben Hutchings wrote:
>
> >                                                              I would
> > like to see mktemp() go the same way but as yet there is no alternative
> > in the standard library.
>
> Just a nit, but there is no function mktemp() in standard C++,
> standard C or in Posix.  The only place I could find it was in
> the Open Systems standard, where it is marked as legacy (which
> if I understand correctly, is the same thing as deprecated).

The function's name is "mkstemp" and can be found in the POSIX 2001
standard.

> The C standard (and the C++ standard, by inclusion) has two
> functions involving temporary files: tmpfile() (which presumably
> is atomic, if the OS permits it, and can be implemented to be
> perfectly secure, even if this isn't normally the case), and
> tmpnam(), which is what I use, but which does require some
> system specific code behind it to be safe.

Neither tmpfile() nor tempnam() are considered to be safe nor to be
free of race conditions. Furhermore, neither routine offers the ability
to set permissions on the created file, so the effective security
provided by either is close to none. For these reasons, mkstemp() was
added to POSIX as a more secure routine to create temporary files
securely and free of any race condition.

 (Generally speaking,
> the best solution is to use the results of tmpnam() to create a
> directory, with access rights positionned so that it is not
> accessible to other users.  The lack of any standard support for
> directories and access rights is probably something that should
> be addressed.)

It was addressed five years ago.

Greg

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



