Annotation of dietlibc/t.c, revision 1.48

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

LinuxTV legacy CVS <linuxtv.org/cvs>