Annotation of dietlibc/t.c, revision 1.21

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

LinuxTV legacy CVS <linuxtv.org/cvs>