#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <errno.h>

int main(int argc, char * argv[]) {
    int fd;
    off_t filelength;
    if (argc !=2) {
        printf ("Usage: flength pathname\n");
        return (-1); }
    fd = open(argv[1], O_RDONLY );
    if (fd < 0) {
        printf("Error Number : %d\n", errno); 
        perror("Error Description"); }
    filelength = lseek (fd, 0, SEEK_END);  
    if (filelength < 0) {
        printf("Error Number : %d\n", errno); 
        perror("Error Description"); }
    else printf ("Size of file %s is %d bytes\n", 
                 argv[1], (int)filelength);
    close (fd); 
    return (0); }
