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

#define BUFSIZE 100

int main (int argc, char *argv[]) {   
    int fd, nread, total=0;   
    char buf[BUFSIZE];
    if (argc !=2) {
    printf ("Usage: flength pathname\n");
    return (-1); }
    fd = open(argv[1], O_RDONLY);
    while (1) {
          nread = read(fd,buf,BUFSIZE-1);     
          if (nread == 0){ 
              break; }
         /* buf[nread] = '\0';*/
          total += nread; }
    printf("%d bytes total\n",total);
    close(fd);
    return 0; }
