Annotation of dietlibc/t.c, revision 1.36

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

LinuxTV legacy CVS <linuxtv.org/cvs>