Annotation of dietlibc/t.c, revision 1.52

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

LinuxTV legacy CVS <linuxtv.org/cvs>