#include <pthread.h>
#include <stdio.h>
#include <errno.h>

#define FAILED do \
    { \
        fprintf (stderr, "FAIL: in <%s> %s\n", \
            __FILE__, strerror (errno)); \
        exit (1); \
    } while (0)

#define FAILED_ERRNO(code) do \
    { \
        fprintf (stderr, "FAIL: in <%s> %s\n", \
            __FILE__, strerror (code)); \
        exit (1); \
    } while (0)

#define PASSED do \
    { \
        fprintf (stderr, "PASS: %s\n", __FILE__); \
        exit (0); \
    } while (0)

void *
routine (void * arg)
{
	return arg;
}

/**
 Check that the argument are pass/return correctly.
*/
void
main ()
{
	pthread_t th1, th2;
	int n;
	int status;
	int * result;

	n = 1;
	status = pthread_create (&th1, NULL, routine, &n);
	if (status != 0)
		FAILED_ERRNO (status);

	status = pthread_join (th1, (void *)&result);
	if (status != 0)
		FAILED_ERRNO (status);

	if (*result != n)
		FAILED;

	PASSED;
}
