Question: You will use the C low level I/O functions to create our own xdir command in C. This program must not use bash, ls, sed,
You will use the C low level I/O functions to create our own xdir command in C. This program must not use bash, ls, sed, awk, and/or Perl. It must not use any of the exec functions.
Syntax of xdir:
xdir directory
xdir directory switches
Your source code must be named xdir.c
In each of the cases, we show the directory. The directory entries are then indented four spaces.
Without any switches
xdir will first print the directory name followed by a colon. xdir will not print any files that begin with "." xdir will print the filenames (unqualified) in the order they are provided by the readdir function.
> xdir Data
Data :
file5
file6
Program4
Program5
Program2
Program3
file4
With just the -l switch
xdir will first print the directory name followed by a colon. xdir will not print any files that begin with "." For each file, xdir will print (on one line):
file name (unqualified) file type (F - regular file, D - directory, L - link, P - Pipe) number of 512 byte blocks size in bytes
xdir will print the files in the order they are provided by the readdir function.
> xdir Data -l
Data :
file5 F 8 blks 167 bytes
file6 F 8 blks 121 bytes
Program4 D 8 blks 4096 bytes
Program5 D 8 blks 4096 bytes
Program2 D 8 blks 4096 bytes
Program3 D 8 blks 4096 bytes
file4 F 8 blks 87 bytes
With just the -a switch
xdir will first print the directory name followed by a colon. xdir will print any files in the directory including ones that begin with a "." xdir will print the filenames (unqualified) in the order they are provided by the readdir function.
> xdir Data -a
Data :
.
..
file5
file6
.mydot
Program4
Program5
Program2
Program3
file4
With both the -l and -a switches
xdir will first print the directory name followed by a colon. xdir will print any files in the directory including ones that begin with a "." For each file, xdir will print (on one line):
file name (unqualified) file type (F - regular file, D - directory, L - link, P - Pipe) number of 512 byte blocks size in bytes
xdir will print the files in the order they are provided by the readdir function.
> xdir Data -l -a
Data :
. D 8 blks 4096 bytes
.. D 8 blks 4096 bytes
file5 F 8 blks 167 bytes
file6 F 8 blks 121 bytes
.mydot F 8 blks 25 bytes
Program4 D 8 blks 4096 bytes
Program5 D 8 blks 4096 bytes
Program2 D 8 blks 4096 bytes
Program3 D 8 blks 4096 bytes
file4 F 8 blks 87 bytes
Notes:
Your code must be written according to my programming standards. The command switches can appear in any order. You may have to construct a file name (when you invoke the stat function):
You may assume that the length of the combination of the directory name and a file name will be less than 500 characters. Use snprintf(szFullFileNm, 500, "%s/%s", pszDirectoryNm, fileNm);
Each directory entry must be indented 4 spaces more than its directory. Larry provided sample data, a makefile, and errExit.c. copy them into your current directory (where your C source code will be located):
To compile and link your code:
make xdir For more information about the make utility, see http://www.cs.utsa.edu/~clark/setup/UnixMakeUtility.pdf
Turn in a zip file (named LastnameFirstname.zip using your name). It should contain
xdir.c - your source code xdir.h - (if you created one) makefile - your makefile to make the xdir executable. In the notes in BlackBoard, specify if extra credit was completed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
