|
- # cat -n 8.17.c
- 1 #include <sys/types.h>
- 2 #include <sys/acct.h>
- 3 #include "ourhdr.h"
- 4 #define ACCTFILE "/var/adm/pacct"
- 5 static unsigned long compt2ulong(comp_t);
- 6 int
- 7 main(void)
- 8 {
- 9 struct acct acdata;
- 10 FILE *fp;
- 11 if((fp=fopen(ACCTFILE,"r"))==NULL)
- 12 err_sys("cat not open %s",ACCTFILE);
- 13 while(fread(&acdata,sizeof(acdata),1,fp)==1) {
- 14 printf("%-*.*s e= %61d , chars = %71d,"
- 15 "stat= %3u: %c %c %c %c\n",sizeof(acdata.ac_comm),
- 16 sizeof(acdata.ac_comm),acdata.ac_comm,
- 17 compt2ulong(acdata.ac_etime),compt2ulong(acdata.ac_io),
- 18 (unsigned char) acdata.ac_stat,
- 19 #ifdef ACORE /* SVR4 does not define ACORE */
- 20 acdata.ac_flag & ACORE ? 'D' : ' ',
- 21 #else
- 22 ' ',
- 23 #endif
- 24 #ifdef AXSIG /* SVR4 does not define AXSIG */
- 25 acdata.ac_flag & AXSIG ? 'X' : ' ',
- 26 #else
- 27 ' ',
- 28 #endif
- 29 acdata.ac_flag & AFORK ? 'F' : ' ',
- 30 acdata.ac_flag & ASU ? 'S' : ' ');
- 31 }
- 32 if(ferror(fp))
- 33 err_sys("read error");
- 34 exit(0);
- 35 }
- 36 static unsigned long
- 37 compt2ulong(comp_t comptime) /* conert comp_t to unsigned long */
- 38 {
- 39 unsigned long val;
- 40 int exp;
- 41 val=comptime & 01777; /* 13-bit fraction */
- 42 exp=(comptime >> 13 ) & 7 ; /* 3-bit exponent (0-7) */
- 43 while(exp--> 0)
- 44 val *=8;
- 45 return(val);
- 46 }
- 47
复制代码
#gcc -c 8.17.c
8.17.c: In function `main':
8.17.c:18: structure has no member named `ac_stat'
:help :help :thank |
|