#include <stdio.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>

int
main (void)
{
  char buf[1024];
  char *b;
  int r;
  struct stat st;
  st.st_ino = 0;
  pid_t pid;

  b = getcwd (buf, sizeof (buf));
  if (!b)
    perror ("getcwd");
  if (!b)
    b = "NULL";
  printf ("getcwd() = %s\n", b);

  r = stat (".", &st);
  printf ("stat(\".\") = %d, ino=%u\n", r, (unsigned) st.st_ino);
  if (r)
    perror ("stat");

  r = stat (b, &st);
  printf ("stat(\"%s\") = %d, ino=%u\n", b, r, (unsigned) st.st_ino);
  if (r)
    perror ("stat");

  pid = fork ();
  if (pid < 0)
    {
      perror ("fork error");
    }
  else if (pid == 0)
    {
      // child
      r = stat (".", &st);
      printf ("child: stat(\".\") = %d, ino=%u\n", r, (unsigned) st.st_ino);
      if (r)
	perror ("child: stat");
      return;
    }

  // parent
  r = stat (".", &st);
  printf ("parent: stat(\".\") = %d, ino=%u\n", r, (unsigned) st.st_ino);
  if (r)
    perror ("parent: stat");

  wait (NULL);
  return;
}

