Annotation of dietlibc/t.c, revision 1.44

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

LinuxTV legacy CVS <linuxtv.org/cvs>