Question on using /tmp

From: Shi Jin (jinzishuai_at_hotmail.com)
Date: 06/20/05

  • Next message: Floyd L. Davidson: "Re: Question on using /tmp"
    Date: Sun, 19 Jun 2005 23:39:18 -0400
    
    

    Hi there,

    In my C code, I need to make a system call to a command to generate a
    temporary file and my code is going to read something out of it.
    I cannot use the pipes to redirect the output to stdout since it varies
    from machine to machine. Only when I call the command in the form
    tsm -Loutput.file
    The command "tsm" will give me a well formated file output.file.

    I want to make output.file a temporary file so that I can use the function
    tmpnam or tmpfile.
    I guess using tmpfile is better in the sense it generates a unique
    filename in the same time creates the file. But I have to use tmpnam since
    I need to create the file in another way. Now my code looks like
    filename=tmpnam(tmpname);
    system(command);
    fp=fopen(filename,"r");

    When I compile it, I get the following warnings:
    warning: the use of `tmpnam' is dangerous, better use `mkstemp'

    For the same reason above, I cannot use mkstemp either. I could use mktemp
    which makes to difference to me compared to tmpnam.

    But still, as the warning said, there is some danger in using tmpnam
    although it seldom happens.
    I wonder if there is a perfect solution to this.
    Thank you very much

    Shi


  • Next message: Floyd L. Davidson: "Re: Question on using /tmp"

    Relevant Pages

    • Re: Question on using /tmp
      ... >temporary file and my code is going to read something out of it. ... Only when I call the command in the form ... But I have to use tmpnam since ... It depends on what kind of security you are trying to implement, ...
      (comp.os.linux.development.apps)
    • Re: unresolved external error
      ... Command Lines Creating temporary file ... Build Log Rebuild started: Project: SimAPI, Configuration: Release|Win32 ...
      (microsoft.public.vc.mfc)
    • Re: unresolved external error
      ... Command Lines Creating temporary file ... Build Log Rebuild started: Project: SimAPI, Configuration: Release|Win32 ...
      (microsoft.public.vc.mfc)
    • Re: IPC::Open2::open2() -- How to pass strings stdin, stdout?
      ... That's what I'm doing now -- writing my stdin to a ... temporary file and getting stdout using backticks. ... Execute a given external program (command). ... print TEMP $stdin; ...
      (comp.lang.perl.misc)
    • Re: Visual Studio 2003 MFC wizard code fails to run
      ... Did you look at your Resource View? ... The phrase "specified image file" implies to me that an image file is ... Creating temporary file "d:\Profiles\shbridges.REST\My Documents ...
      (microsoft.public.vc.mfc)