Vivek Katakam wrote:
> I am facing Segementation violation in the following function.
This does not have anything to do with gcc. I suggest you post your
question on a basic C language forum like comp.lang.c. The compiler has
nothing to do with functions like mkstemp(), they are provided by
whatever C library you are using.
>
> Breakpoint 1, main (argc=1, argv=0x7fbfffd7f8) at dr_end.c:230
> 230 sprintf(detail_filename, "/tmp/%s", mkstemp(filename_template));
> (gdb) p detail_filename
The reason you get the SEGV is because this code is broken. mkstemp()
opens the file and returns a file descriptor (integer) not a string.
The whole point of using mkstemp() is that it avoids the potential
security hole caused by the race that can occur between generating the
filename and opening the file. The above code looks like somebody tried
to blindly substitute mkstemp() for mktemp() without actually
understanding the difference.
Read the fine manual:
http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html
http://www.freebsd.org/cgi/man.cgi?query=mkstemp
Brian