Users and Files: cp and tail

Prof. Brian D. Davison

Computer Science & Engineering, Lehigh University

Announcements

cp (read and write)

Creating/truncating a file

Writing copy.c

Control flow in copying a file

alt text

Does the size of the buffer matter?

Efficiency

Can't the kernel do our buffering?

Consequences of buffering

Another example: tail

Reading arbitrary bytes from a file

Directories, File Info, etc.

Writing ls (using same approach)

Writing ls (using same approach)

Directories

Reading Directories

Reading Directories

Using Directory Functions

Writing first version of ls.c

main()
    opendir()
    while ( readdir() )
       print d_name

    closedir()
    return 0