/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that opens a file then closes it. */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int main() {
    int fildes;
    struct stat filestatus;
    int len;
    char buf[2048];
    
    /* open file for reading only */
    if((fildes = open("lockf.c",O_RDONLY)) == -1) { 
        printf("cannot open file");
        exit(1);
    }
    fstat(fildes,&filestatus);
    len = filestatus.st_size;
    read(fildes,buf,len);
    printf("%s\n",buf);
    lockf(fildes,F_LOCK,len/2);
    read(fildes,buf,len);
    printf("%s\n",buf);
    if(close(fildes)) printf("error in closing file\n");
}

