Annotation of dietlibc/t.c, revision 1.40

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

LinuxTV legacy CVS <linuxtv.org/cvs>