home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / GianuzziV / SO1 / fd2.c < prev    next >
C/C++ Source or Header  |  2001-11-07  |  507b  |  26 lines

  1. #include <fcntl.h>
  2.  
  3. /* File fd2.c
  4.    Lo stesso file letto anche dal un fd duplicato.
  5.    Non viene creata una seconda entry nella
  6.    kernel file table, quindi legge in sequenza.
  7. */
  8.  
  9. main (argc, argv)
  10. int     argc;
  11. char    *argv[];
  12. {  int   fd1, fd2, count, i;
  13.    char  buf[11], buf0[11];
  14.    fd1 = open(argv[1],O_RDONLY);
  15.    fd2 = dup(fd1);
  16.    buf[10]='\0';
  17.    buf0[10]='\0';
  18.    for(i=0;i<10;i++) {
  19.    read(fd1,buf,sizeof(buf)-1);
  20.    printf("%s", buf);
  21.    read(fd2,buf0,sizeof(buf0)-1);
  22.    printf("%s", buf0);
  23. }
  24. }
  25.  
  26.