Annotation of dietlibc/t.c, revision 1.16

1.1       cvs         1: #include <unistd.h>
                      2: #include <endian.h>
                      3: #include <stdlib.h>
                      4: #include <dirent.h>
                      5: #include <pwd.h>
                      6: #include <stdio.h>
                      7: #include <assert.h>
                      8: #include <sys/mount.h>
1.7       fefe        9: #include <time.h>
1.9       fefe       10: #include <sys/stat.h>
1.10      fefe       11: #include <stdio.h>
1.12      fefe       12: #include <arpa/inet.h>
1.13      fefe       13: #include <sys/sem.h>
1.14      fefe       14: #include <sys/shm.h>
1.1       cvs        15: 
1.16    ! fefe       16: int compint(const void *a,const void *b) {
        !            17: /*  printf("comparing %d with %d\n",*(int*)a,*(int*)b); */
        !            18:   return (*(int*)a-*(int*)b);
        !            19: }
        !            20: 
        !            21: #define SIZE 100000
        !            22: #define LOOKFOR ((SIZE/2)-2)
        !            23: 
        !            24: int array[SIZE];
        !            25: 
        !            26: #define rdtscl(low) \
        !            27:      __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
        !            28: 
        !            29: static unsigned int seed=1;
        !            30: 
        !            31: static int rand() {
        !            32:   return ((seed = seed * 1103515245 + 12345) % ((unsigned int)RAND_MAX + 1));
        !            33: }
        !            34: 
1.12      fefe       35: int main(int argc,char *argv[]) {
1.16    ! fefe       36:   int i,j;
        !            37:   long a,b,c;
        !            38:   int *res;
        !            39:   printf("%p\n",malloc(0));
        !            40:   qsort(array,2,sizeof(int),compint);
        !            41:   for (i=0; i<SIZE; ++i)
        !            42:     array[i]=rand();
        !            43:   rdtscl(a);
        !            44:   qsort(array,SIZE,sizeof(int),compint);
        !            45:   rdtscl(b);
        !            46:   j=array[LOOKFOR];
        !            47:   res=bsearch(&j,array,SIZE,sizeof(int),compint);
        !            48:   rdtscl(c);
        !            49:   printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
        !            50:   for (i=0; i<SIZE-1; ++i)
        !            51:     if (array[i]>array[i+1]) {
        !            52:       printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
        !            53:       return 1;
        !            54:     }
        !            55:   if (*res!=j)
        !            56:     printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
        !            57: /*  printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.13      fefe       58: #if 0
1.12      fefe       59:   struct in_addr duh;
                     60:   printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
                     61:   printf("%x\n",duh.s_addr);
1.13      fefe       62: #endif
1.12      fefe       63: /*  printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11      fefe       64: #if 0
1.10      fefe       65:   char buf[100];
                     66:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
                     67:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11      fefe       68: #endif
1.9       fefe       69: #if 0
1.7       fefe       70:   struct tm duh;
                     71:   time_t t;
1.8       fefe       72:   time(&t);
                     73:   gmtime_r(&t,&duh);
                     74:   printf("%s\n",asctime(&duh));
1.9       fefe       75: #endif
1.8       fefe       76: #if 0
1.7       fefe       77:   char buf[30];
                     78:   duh.tm_sec=42;
                     79:   duh.tm_min=23;
                     80:   duh.tm_hour=17;
                     81:   duh.tm_mday=2;
                     82:   duh.tm_mon=7;
                     83:   duh.tm_year=100;
                     84:   t=mktime(&duh);
                     85:   printf("%s\n",asctime_r(&duh,buf));
1.8       fefe       86: #endif
1.2       fefe       87: #if 0
1.1       cvs        88:   int i;
                     89:   for (i=0; i<5; i++) {
                     90:     fprintf(stdout,"first message\n");
                     91:     fprintf(stdout,"second message\n");
                     92:     fprintf(stdout,"third message\n");
                     93:     printf("foo %d\n",i);
                     94:   }
1.2       fefe       95: #endif
1.1       cvs        96: #if 0
                     97:   char buf[1024];
                     98:   sscanf("foo bar","%s",buf);
                     99:   printf("%s\n",buf);
                    100: #endif
                    101: #if 0
                    102:   mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
                    103:   perror("mount");
                    104: #endif
                    105: #if 0
                    106:   char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
                    107:   int i=strtol(t+1,&t,10);
                    108:   printf("%d %s\n",i,t);
                    109: #endif
                    110: #if 0
                    111:   char **tmp;
                    112:   putenv("FOO");
                    113:   assert(1==2);
                    114:   for (tmp=environ; *tmp; tmp++)
                    115:     puts(*tmp);
                    116: #endif
                    117: #if 0
                    118:   char buf[1024];
                    119:   printf("%d\n",fprintf(stderr,"duh\n"));
                    120: #endif
                    121: #if 0
                    122:   struct passwd *p=getpwuid(100);
                    123:   puts(p->pw_name);
                    124: #endif
                    125: #if 0
                    126:   int pid;
                    127:   char name[32];
                    128:   sscanf("1 (init","%d (%15c",&pid,name);
                    129:   printf("pid %d name %s\n",pid,name);
                    130: #endif
                    131: #if 0
                    132:   DIR *d=opendir("/proc");
                    133:   if (d) {
                    134:     struct dirent *D;
                    135:     while (D=readdir(d))
                    136:       puts(D->d_name);
                    137:     closedir(d);
                    138:   }
                    139: #endif
                    140: #if 0
                    141:   char buf[1024];
                    142:   int fd=open("/etc/passwd",0);
                    143:   pread(fd,buf,30,32);
                    144:   close(fd);
                    145:   write(1,buf,32);
                    146: #endif
                    147: #if 0
                    148:   char *argv[] = {"echo","foo",0};
                    149:   char buf[100];
                    150:   buf[5]='x';
                    151:   sprintf(buf,"foo\n");
                    152:   if (buf[5] == 'x')
                    153:     exit(0);
                    154:   else
                    155:     exit(1);
                    156:   execvp(argv[0],argv);
                    157: #endif
1.10      fefe      158: #if 0
1.1       cvs       159:   struct stat64 f;
                    160:   char buf[128];
                    161:   fstat64(0,&f);
                    162:   fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
                    163:   return 0;
                    164: #endif
                    165: #if 0
                    166:   FILE *f=fopen("foo","w");
                    167:   fputc('a',f);
                    168:   fputc('b',f);
                    169:   fputc('c',f);
                    170: #endif
                    171: /*  fprintf(stdout,"foo\n"); */
                    172: }

LinuxTV legacy CVS <linuxtv.org/cvs>