Annotation of dietlibc/t.c, revision 1.54

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

LinuxTV legacy CVS <linuxtv.org/cvs>