Annotation of dietlibc/t.c, revision 1.39

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

LinuxTV legacy CVS <linuxtv.org/cvs>