fd = open (fname, O_TRUNC | O_WRONLY | O_CREAT);
fd = open (fname, O_TRUNC | O_WRONLY | O_CREAT, 0666);
catch_segfault (int signal, SIGCONTEXT ctx){  struct layout *current;  void *top_frame;  void *top_stack;  const char *fname;  int fd;  void **arr;  size_t cnt;  struct sigaction sa;  const char *sigstring;  /* This is the name of the file we are writing to.  If none is given     or we cannot write to this file write to stderr.  */  fd = 2;  fname = getenv ("SEGFAULT_OUTPUT_NAME");  if (fname != NULL && fname[0] != '\0')    {      fd = open (fname, O_TRUNC | O_WRONLY | O_CREAT);      if (fd == -1)	fd = 2;    }#define WRITE_STRING(s) write (fd, s, strlen (s))  WRITE_STRING ("*** ");  sigstring = strsignal (signal);  WRITE_STRING (sigstring);  WRITE_STRING ("\n");#ifdef REGISTER_DUMP  REGISTER_DUMP;#endif  WRITE_STRING ("\nBacktrace:\n");  top_frame = GET_FRAME (ctx);  top_stack = GET_STACK (ctx);  /* First count how many entries we'll have.  */  cnt = 1;  current = (struct layout *) top_frame;  while (!((void *) current INNER_THAN top_stack	   || !((void *) current INNER_THAN __libc_stack_end)))    {      ++cnt;      current = current->next;    }  arr = alloca (cnt * sizeof (void *));  /* First handle the program counter from the structure.  */  arr[0] = GET_PC (ctx);  current = (struct layout *) top_frame;  cnt = 1;  while (!((void *) current INNER_THAN top_stack	   || !((void *) current INNER_THAN __libc_stack_end)))    {      arr[cnt++] = current->return_address;      current = current->next;    }  /* If the last return address was NULL, assume that it doesn't count.  */  if (arr[cnt-1] == NULL)    cnt--;  /* Now generate nicely formatted output.  */  __backtrace_symbols_fd (arr, cnt, fd);  /* Pass on the signal (so that a core file is produced).  */  sa.sa_handler = SIG_DFL;  sigemptyset (&sa.sa_mask);  sa.sa_flags = 0;  sigaction (signal, &sa, NULL);  raise (signal);}