home *** CD-ROM | disk | FTP | other *** search
- # ifndef lint
- static char SccsId[] = "@(#)filecount.c 1.3\t8/22/91" ;
- # endif
-
- # include "sps.h"
-
- /* FILECOUNT - Counts the # open files for the current process */
- filecount ( p )
-
- struct process *p ;
-
- {
- register int i ;
- register struct file **f ;
- register int count ;
- extern union userstate User ;
- # ifdef SUNOS41
- /*
- * The open file list is in User.u_us.u_ofile_arr
- * if User.u_us.u_ofile points to it; otherwise we'll have
- * do it the hard way by reading the list from kmem.
- *
- * Read the comment to u_ofile in /usr/include/sys/user.h.
- */
-
- int len ;
- static char *files = 0 ;
- static int files_len = 0 ;
- extern char *getcore () ;
- # endif SUNOS41
-
-
- # ifdef SUNOS41
-
- # ifndef offsetof
- # define offsetof(type,member) ((long) &(((type *) 0)->member))
- # endif offsetof
-
- if ( (long) User.u_us.u_ofile ==
- (long) p->pr_p.p_uarea + offsetof(struct user, u_ofile_arr[0]) )
- f = &User.u_us.u_ofile_arr[ 0 ] ;
- else
- {
- len = User.u_us.u_lastfile * sizeof (struct file *) ;
- if (len <= 0)
- return 0;
- if (files == 0 || len > files_len)
- {
- if (files != 0)
- free (files) ;
- files = (char *) getcore(len) ;
- files_len = len ;
- }
- if ( getkmem( (long)User.u_us.u_ofile, (char *)files, len)
- != len )
- return 0 ;
- f = (struct file **)files ;
- }
- count = 0 ;
- for ( i = 0 ; i < User.u_us.u_lastfile ; i++ )
- if ( *f++ )
- count++ ;
- return ( count ) ;
- # else SUNOS41
- count = 0 ;
- for ( i = 0, f = User.u_us.u_ofile ; i < NOFILE ; i++ )
- if ( *f++ )
- count++ ;
- return ( count ) ;
- # endif SUNOS41
- }
-