Annotation of dietlibc/t.c, revision 1.25

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

LinuxTV legacy CVS <linuxtv.org/cvs>