Home | History | Annotate | Download | only in ltrace.minor
      1 /* Ltrace Test : count-record.c.
      2    Objectives  : Verify that Ltrace can count all the system calls in
      3    execution and report a summary on exit.
      4 
      5    This file was written by Yao Qi <qiyao (at) cn.ibm.com>.  */
      6 
      7 #include <stdio.h>
      8 #include <unistd.h>
      9 #include <sys/syscall.h>
     10 #include <sys/stat.h>
     11 #include <errno.h>
     12 
     13 void exit (int);
     14 
     15 #define	BUF_SIZE	100
     16 
     17 /*  Do as many operations as possible to record these calls.  */
     18 int
     19 main ()
     20 {
     21   FILE* fp;
     22   char s[]="system_calls";
     23   char buffer[BUF_SIZE];
     24   struct stat state;
     25 
     26   fp = fopen ("system_calls.tmp", "w");
     27   if (fp == NULL)
     28     {
     29       printf("Can not create system_calls.tmp\n");
     30       exit (0);
     31     }
     32 
     33   fwrite(s, sizeof(s), 1, fp);
     34   fseek (fp, 0, SEEK_CUR);
     35   fread(buffer, sizeof(s), 1, fp);
     36   fclose(fp);
     37 
     38   getcwd (buffer, BUF_SIZE);
     39   chdir (".");
     40   symlink ("system_calls.tmp", "system_calls.link");
     41   remove("system_calls.link");
     42   rename ("system_calls.tmp", "system_calls.tmp1");
     43   stat ("system_calls.tmp", &state);
     44   access ("system_calls.tmp", R_OK);
     45   remove("system_calls.tmp1");
     46 
     47   mkdir ("system_call_mkdir", 0777);
     48   rmdir ("system_call_mkdir");
     49 
     50   return 0;
     51 }
     52