Annotation of dietlibc/t.c, revision 1.43

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

LinuxTV legacy CVS <linuxtv.org/cvs>