#include <stdio.h>
#include <stdlib.h>

#include <apr.h>
#include <apr_general.h>
#include <apr_pools.h>
#include <apr_file_io.h>

static void x(const char *op, apr_status_t status)
{
  char buf[256];

  if (!APR_STATUS_IS_SUCCESS(status))
    {
      fprintf(stderr, "%s: %s\n", op, apr_strerror(status, buf, sizeof(buf)));
      exit(1);
    }
}

int main(int argc, char **argv)
{
  const char *name = argv[1];
  apr_pool_t *pool;
  apr_file_t *file;

  x("init", apr_initialize());
  x("pool", apr_pool_create(&pool, NULL));
  x("open", apr_file_open(&file, name, APR_CREATE|APR_WRITE, APR_OS_DEFAULT,
			  pool));
  printf("Getting the lock\n");
  x("lock", apr_file_lock(file, APR_FLOCK_EXCLUSIVE));
  printf("Have the lock\n");
  getchar();
  x("close", apr_file_close(file));
  printf("Released the lock\n");
  apr_terminate();
  return 0;
}
