Example #1
0
int
asm_errno (void)
{
  int result;

  /* If we have not yet initialized the buffer do it now.  */
  once_execute (once, init);

  if (threaded)
    {
      /* We have a key.  Use it to get the thread-specific buffer.  */
      int *buffer = getspecific (key);
      if (buffer == NULL)
	{
	  /* No buffer allocated so far.  */
	  buffer = (int *) malloc (sizeof (int));
	  if (buffer == NULL)
	    /* No more memory available.  We use the static buffer.  */
	    buffer = &global_error;

	  setspecific (key, buffer);

	  *buffer = 0;
	}

      result = *buffer;
      *buffer = ASM_E_NOERROR;
      return result;
    }

  result = global_error;
  global_error = ASM_E_NOERROR;
  return result;
}
Example #2
0
int
elf_errno (void)
{
  int result;

#ifndef USE_TLS
  /* If we have not yet initialized the buffer do it now.  */
  once_execute (once, init);

  if (threaded)
    {
    /* We do not allocate memory for the data.  It is only a word.
       We can store it in place of the pointer.  */
      result = (intptr_t) getspecific (key);

      setspecific (key, (void *) (intptr_t) ELF_E_NOERROR);
      return result;
    }
#endif	/* TLS */

  result = global_error;
  global_error = ELF_E_NOERROR;
  return result;
}