Annotation of dietlibc/t.c, revision 1.42

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

LinuxTV legacy CVS <linuxtv.org/cvs>