[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C stuff





	Ok. Thanks.
	That program looks like something that should be a good study
program.


	Bill Dunn

> 
> ----- starts here -----
> 
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <time.h>
> #include <sys/param.h>
> #include <dirent.h>
> #include <unistd.h>
> #include <pwd.h>
> #include <grp.h>
> 
> 
> void main()
> {
> 
> struct dirent *dirent_struct_ptr; /* struct for readdir */
> struct group *grp_struct_ptr;  /*struct for getgrgid */
> struct passwd *pwd_struct_ptr; /*struct for getpwuid */
> struct stat *stat_struct_ptr; /* struct for stat */
> struct tm *time_struct_ptr; /*struct for localtime */
> FILE * fp;
> DIR * dp;  /* for opendir */
> char *path_ptr, *time_string_ptr; /* for getcwd */
> time_t cal_time;
> uid_t uids, gids;
> uid_t i=15;
> int j=0;
> uid_t getuid(void);
> char temp[MAXPATHLEN+1];
> char slash[]="/";
> 
> 
> /* S_IREAD S_IWRITE S_IEXEC */
> 
> 
> tzset();
> uids=getuid();
> 
> 
> 
> if ((stat_struct_ptr=(struct stat *) malloc(sizeof(stat))) != NULL)
> 
>   if ((path_ptr=getcwd(NULL,MAXPATHLEN+1)) != NULL)
>   
>   if ((dp=opendir(path_ptr)) != NULL)
>    {
>    printf("\n<html>\n<head>\n<title>Mike Connor's 
> phase2.c</title>\n</head>\n");
>    printf("<body>");
>    printf("<table>");
>    printf("<tr><td>file name </td><td> size </td><td> owners name 
> </td><td> grou
> p's name </td><td> last accessed </td><td> last modified </td></tr>");
> 
>    while((dirent_struct_ptr=readdir(dp)) != NULL)
>    { 
>    if (((*dirent_struct_ptr).d_ino !=0) && (*(*dirent_struct_ptr).d_name 
> != '.')
> )
>      {
>      strcpy(temp, path_ptr);
>      strcat(temp, slash);
>      strcat(temp, (*dirent_struct_ptr).d_name);
> 
>      if ((stat(temp, stat_struct_ptr) != -1))
>      
>        if  ((*(*dirent_struct_ptr).d_name) != '.')       
>        { 
> 
>        printf("<tr><td>");
> 
>        if ( (((*stat_struct_ptr).st_mode & S_IREAD) && (uids == 
> (*stat_struct_pt
> r).st_uid)) || ((*stat_struct_ptr).st_mode & S_IREAD>>3) || 
> ((*stat_struct_ptr).
> st_mode & S_IREAD>>6))
>           printf("<a href=\"%s\"> %s </a> ",  
> (*dirent_struct_ptr).d_name, (*dir
> ent_struct_ptr).d_name);
> 
>        else
>           printf(" %s ", (*dirent_struct_ptr).d_name);
> 
>        printf("</td><td>");
>        printf(" %u ", (*stat_struct_ptr).st_size);
>        printf("</td><td>");
> 
>        pwd_struct_ptr=getpwuid((*stat_struct_ptr).st_uid);
>        printf(" %s ", (*pwd_struct_ptr).pw_name);
>        free(pwd_struct_ptr);
> 
>        printf("</td><td>");
> 
>        grp_struct_ptr=getgrgid((*stat_struct_ptr).st_gid);
>        printf(" %s ", (*grp_struct_ptr).gr_name);
>        free(grp_struct_ptr);
> 
>        printf("</td><td>");
> 
>        time_struct_ptr=localtime(&(*stat_struct_ptr).st_atime);
>        printf(" %s ", asctime(time_struct_ptr));
>        
>        printf("</td><td>");
> 
>        time_struct_ptr=localtime(&(*stat_struct_ptr).st_mtime);
>        printf(" %s ", asctime(time_struct_ptr));
>        free(time_struct_ptr);
> 
>        printf("</td></tr>"); 
>        } 
>       
>      }
>    } /*while end*/
> 
> printf("</table>");
> printf("</body></html>\n");
> 
> 
> } /* if ends */
> 
> }/*prog end*/


--
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.