Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: jt@toerring.de (Jens Thoms Toerring) Newsgroups: comp.os.linux.development.apps Subject: Re: reading a temp file in C++ Date: 28 Jun 2011 21:17:36 GMT Organization: Freie Universitaet Berlin Lines: 31 Message-ID: <96uungF471U1@mid.uni-berlin.de> References: X-Trace: news.uni-berlin.de F5bYC4GBPj7tB1Dt9PscBwHfNnSdFYgOPD9cywePrRUGFt X-Orig-Path: not-for-mail User-Agent: tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.30-1-amd64 (x86_64)) Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.development.apps:171 James Waldby wrote: > On Tue, 28 Jun 2011 08:33:43 +0000, Ruben Safir wrote: > > any clue why this isn't retrieving the contents of the temp file > It appears you create and open a temp file via fd = mkstemp(path);, > then invoke vi via system(editor);, and finally read and print > from fd. I presume that when user saves file and exits vi, that > in effect vi writes a new temp file, renames the original temp file, > and renames the new temp file. If so, fd contents don't change. It may even "delete" (unlink()) the old file, the file descriptor in the program that invoked vi (or any other editor) using system() will still be valid - while the original file then has no name in the file system anymore ot still exists (via its inodes(s)) until nothing uses it anymore and it only then finally gets removed com- pletely. So the whole way this is done won't work. Editors usually don't modify the file they were invoked on but create a new file with the old name (often renaming the original file to serve as a back- up file). So just create the temporary file, purely for getting the unique name, close it, invoke vi (or whatever editor) on it and, when vi is done, reopen the new file that vi created (but which has the old name). That way you also don't need this rather ugly '__gnu_cxx::stdio_filebuf' stuff;-) Regards, Jens -- \ Jens Thoms Toerring ___ jt@toerring.de \__________________________ http://toerring.de