Today, I sorted out my previous knowledge and homework. I posted my previous jobs in the "advanced programming in UNIX environment" class and shared them with you.
# Include <unistd. h> <br/> # include <time. h> <br/> # include <fcntl. h> <br/> # include <sys/types. h> <br/> # include <sys/STAT. h> <br/> # include <dirent. h> <br/> # include <stdlib. h> <br/> # include <stdio. h> <br/> # include <PWD. h> <br/> # include <GRP. h> </P> <p> int main (INT argc, char * argv []) <br/> {<br/> int I, FD; <br/> dir * DP; <br/> struct stat statbuf; <br/> struct dirent * dirp; <br/> struct passwd * Pwd; <br/> struct gr OUP * GRP; <br/> struct TM * time; <br/> If (argc! = 2) {<br/> printf ("Usage: ls directory_name"); <br/> exit (1 ); <br/>}< br/> If (dp = opendir (argv [1]) = NULL) {<br/> printf ("can't open % s", argv [1]); <br/> exit (1 ); <br/>}< br/> while (dirp = readdir (DP ))! = NULL) {<br/> If (STAT (dirp-> d_name, & statbuf) <0) {<br/> printf ("% s: stat error/N ", argv [I]); <br/> exit (1); <br/>}< br/> If (s_isdir (statbuf. st_mode) // mode <br/> printf ("D"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_irusr) <br/> printf ("R"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_iwusr) <br/> printf ("W"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_ixusr) <br/> printf ("X"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_irgrp) <br/> printf ("R"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_iwgrp) <br/> printf ("W"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_ixgrp) <br/> printf ("X"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_iroth) <br/> printf ("R"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_iwoth) <br/> printf ("W"); <br/> else printf ("-"); <br/> If (statbuf. st_mode & s_ixoth) <br/> printf ("X"); <br/> else printf ("-"); <br/> printf ("% 2D", statbuf. st_nlink); <br/> Pwd = getpwuid (statbuf. st_uid); // user <br/> printf ("% 8 s", PWD-> pw_name); <br/> GRP = getgrgid (statbuf. st_gid); <br/> printf ("% 8 s", GRP-> gr_name); // group <br/> printf ("% 7D", statbuf. st_size); // size <br/> time = localtime (& statbuf. st_mtime); // time <br/> printf ("% 02d-% 02d % 02d: % 02d", time-> tm_mon + 1, time-> tm_mday, time-> tm_hour, time-> tm_min); <br/> printf ("%-15 s/n", dirp-> d_name ); // name <br/>}< br/> closedir (DP); <br/> exit (0); <br/>}< br/>