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


Groups > comp.os.linux.development.apps > #171

Re: reading a temp file in C++

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.os.linux.development.apps
Subject Re: reading a temp file in C++
Date 2011-06-28 21:17 +0000
Organization Freie Universitaet Berlin
Message-ID <96uungF471U1@mid.uni-berlin.de> (permalink)
References <iuc3l7$nam$1@reader1.panix.com> <iuctn2$h6o$2@dont-email.me>

Show all headers | View raw


James Waldby <not@valid.invalid> 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

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

reading a temp file in C++ Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 08:33 +0000
  Re: reading a temp file in C++ Richard Kettlewell <rjk@greenend.org.uk> - 2011-06-28 09:46 +0100
  Re: reading a temp file in C++ James Waldby <not@valid.invalid> - 2011-06-28 15:58 +0000
    Re: reading a temp file in C++ jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 21:17 +0000
      Re: reading a temp file in C++ ruben safir <ruben@mrbrklyn.com> - 2011-06-30 03:06 +0000

csiph-web