

#include <stdio.h>
#include <unistd.h>

#define USAGE "testlock <filename>\n\n\
  Program by Robert Soliday.  ("__DATE__")."

int main(int argc, char **argv) {
  FILE *fp;
  if (argc != 2) {
    fprintf(stderr, "USAGE: %s\n", USAGE);
    return (1);
  }
  if (!(fp = fopen(argv[1], "rb"))) {
    fprintf(stderr, "Unable to open file\n");
    return (1);
  }
  if (lockf(fileno(fp), F_TEST, 0) == -1) {
    fprintf(stdout, "File is locked\n");
  } else {
    fprintf(stdout, "File is not locked\n");
  }
  fclose(fp);

  return (0);
}
