gcc. mkstemp works but I can't write to the new files.

M

Martin McCormick

I am obviously confused about how to write to the file created
by the mkstemp function.

The manual says that it returns a pointer to a file descripter
when successful and I think that the function is working right because
I get the randomized name in the text string and the function does
return an integer value as well as leaving a new file of the same
name.

What I haven't been able to do is write to it.

I have tried capturing that number in an int variable which
works fine, but putting that variable name in the fprintf statement
causes a segmentation fault.

I tried capturing the value with a FILE pointer. That also
works, but you can't write to that either for the same reason.

I am familiar with writing to files created by fopen where one
fprintf's to the named file pointer, but I must be confused as to what
to put in the fprintf(fd,""); statement.

Any ideas are greatly appreciated. Thank you.
 
B

Ben Pfaff

I am obviously confused about how to write to the file created
by the mkstemp function.

mkstemp is not a standard C function. Please discuss it in a
newsgroup devoted to whatever standard it is in (if there is
one). In comp.lang.c, we discuss only the standard C programming
language.
 
T

Tom Zych

Ben said:
(e-mail address removed) (Martin McCormick) writes:
mkstemp is not a standard C function. Please discuss it in a
newsgroup devoted to whatever standard it is in (if there is
one). In comp.lang.c, we discuss only the standard C programming
language.

man 3 mkstemp on my Debian system advises:

Don't use this function, use tmpfile(3) instead. It is better
defined and more portable.
 
D

Default User

Martin said:
I am obviously confused about how to write to the file created
by the mkstemp function.


Not a standard C function. I believe it is POSIX, so I advise posting to
comp.unix.programmer or a newsgroup specifically for your
implementation.




Brian Rodenborn
 
M

Micah Cowan

Tom Zych said:
man 3 mkstemp on my Debian system advises:

Don't use this function, use tmpfile(3) instead. It is better
defined and more portable.

And even better, on-topic for this NG.

-Micah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,082
Messages
2,570,588
Members
47,209
Latest member
Ingeborg61

Latest Threads

Top