Annotation of dietlibc/t.c, revision 1.108

1.56      fefe        1: #define _GNU_SOURCE
1.47      fefe        2: #define _FILE_OFFSET_BITS 64
1.1       cvs         3: #include <unistd.h>
                      4: #include <endian.h>
                      5: #include <stdlib.h>
                      6: #include <dirent.h>
                      7: #include <pwd.h>
1.40      fefe        8: #include <shadow.h>
1.1       cvs         9: #include <stdio.h>
                     10: #include <assert.h>
                     11: #include <sys/mount.h>
1.7       fefe       12: #include <time.h>
1.9       fefe       13: #include <sys/stat.h>
1.10      fefe       14: #include <stdio.h>
1.12      fefe       15: #include <arpa/inet.h>
1.13      fefe       16: #include <sys/sem.h>
1.14      fefe       17: #include <sys/shm.h>
1.17      fefe       18: #include <math.h>
1.20      fefe       19: #include <termios.h>
1.22      fefe       20: #include <netdb.h>
1.38      fefe       21: #include <sys/mman.h>
1.45      fefe       22: #include <ctype.h>
1.49      fefe       23: #include <mntent.h>
1.53      fefe       24: #include <regex.h>
1.56      fefe       25: #include <sys/types.h>
                     26: #include <sys/msg.h>
1.63      fefe       27: #include <string.h>
1.76      fefe       28: #include <sys/socket.h>
                     29: #include <netdb.h>
1.86      fefe       30: #include <signal.h>
1.88      fefe       31: #include <sys/io.h>
1.97      fefe       32: #include <getopt.h>
1.101     fefe       33: #include <arpa/nameser.h>
                     34: #include <resolv.h>
1.102     fefe       35: #include <fnmatch.h>
1.71      fefe       36: 
1.107     fefe       37: extern int errno;
                     38: 
1.97      fefe       39: int main(int argc,char *argv[]) {
1.105     fefe       40: #if 0
                     41:   printf("%hd %hhd\n",-5,-1234567);
                     42: #endif
1.103     fefe       43: #if 0
1.102     fefe       44:   printf("%d\n",fnmatch("*.o", "x.o", FNM_PATHNAME));
                     45:   printf("%d\n",fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME));
1.103     fefe       46: #endif
1.102     fefe       47: #if 0
1.101     fefe       48:   char buf[1024];
                     49:   int len;
                     50:   len=res_search("fu-berlin.de",ns_c_in,ns_t_ns,buf,sizeof(buf));
1.102     fefe       51: #endif
1.104     fefe       52: #if 0
1.100     fefe       53:   regex_t t;
                     54:   regmatch_t rm;
1.103     fefe       55: //  regcomp(&t,"^ *read",0);
                     56:   regcomp(&t,"^ *read",0);
                     57:   printf("%d\n",regexec(&t,"    read",1,&rm,0));
1.100     fefe       58:   printf("ofs %d\n",rm.rm_so);
1.101     fefe       59: #endif
1.100     fefe       60: #if 0
1.98      fefe       61:   char buf[100];
1.99      fefe       62:   printf("%d\n",fread(buf,1,0,stdin));
1.100     fefe       63: #endif
1.99      fefe       64: #if 0
                     65:   char buf[100];
1.98      fefe       66:   memset(buf,17,100);
                     67:   buf[0]=0;
                     68:   strncat(buf,"foobarbaz23",10);
                     69:   puts(buf);
1.99      fefe       70: #endif
1.98      fefe       71: #if 0
1.97      fefe       72:   int aflag = 0;
                     73:   int bflag = 0;
                     74:   char *cvalue = NULL;
                     75:   int index;
                     76:   int c;
                     77: 
                     78:   opterr = 1;
                     79: 
                     80:   while ((c = getopt (argc, argv, "abc:")) != -1)
                     81:     switch (c)
                     82:       {
                     83:       case 'a':
                     84:        aflag = 1;
                     85:        break;
                     86:       case 'b':
                     87:        bflag = 1;
                     88:        break;
                     89:       case 'c':
                     90:        cvalue = optarg;
                     91:        break;
                     92:       case '?':
                     93:        if (isprint (optopt))
                     94:          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                     95:        else
                     96:          fprintf (stderr,
                     97:                  "Unknown option character `\\x%x'.\n",
                     98:                  optopt);
                     99:        return 1;
                    100:       default:
                    101:        abort ();
                    102:       }
1.96      fefe      103: 
1.97      fefe      104:   printf ("aflag = %d, bflag = %d, cvalue = %s\n",
                    105:          aflag, bflag, cvalue);
                    106: 
                    107:   for (index = optind; index < argc; index++)
                    108:     printf ("Non-option argument %s\n", argv[index]);
                    109:   return 0;
1.98      fefe      110: #endif
1.97      fefe      111: #if 0
1.96      fefe      112:   char *t="foobar";
                    113:   char *c;
                    114:   char buf[1000];
                    115:   puts(strcat(strcpy(buf,"HOME="),t));
1.97      fefe      116: #endif
1.89      fefe      117: #if 0
                    118:   struct netent* n=getnetbyname("loopback");
                    119:   printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
                    120: #endif
                    121: #if 0
1.88      fefe      122:   fprintf(stdout,"foo\n");
                    123:   sleep(1);
                    124:   fprintf(stdout,"bar");
                    125:   fprintf(stderr,"blonk");
                    126:   sleep(1);
                    127:   fprintf(stdout,"\rbz");
                    128:   sleep(1);
                    129:   fprintf(stdout,"\n");
                    130:   sleep(1);
1.89      fefe      131: #endif
1.87      fefe      132: #if 0
1.86      fefe      133:   sigset_t s;  /* sigsetops */
                    134: 
                    135:   sigemptyset(&s);
                    136:   sigaddset(&s,SIGCHLD);
                    137:   sigaddset(&s,SIGHUP);
                    138:   sigsuspend(&s);
1.87      fefe      139: #endif
1.85      fefe      140: #if 0
1.84      fefe      141:   char buf[1024];
                    142:   FILE *f=popen("uname -srm","r");
                    143:   fgets(buf,1023,f);
                    144:   pclose(f);
                    145:   write(1,buf,strlen(buf));
1.85      fefe      146: #endif
1.84      fefe      147: #if 0
1.82      fefe      148:   char type[64];
1.83      fefe      149:   char filename[256];
                    150:   int major,minor;
1.82      fefe      151:   int len;
1.83      fefe      152:   printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
                    153:   printf("%s %s %d %d\n",type,filename,major,minor);
1.84      fefe      154: #endif
1.82      fefe      155: #if 0
1.81      fefe      156:   char buf[100];
                    157:   char ip[16];
                    158:   memset(ip,0,16);
                    159:   printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
                    160:   puts(buf);
1.82      fefe      161: #endif
1.107     fefe      162: #if 0
1.76      fefe      163:   struct addrinfo *ai;
1.78      fefe      164:   struct addrinfo hints;
1.79      fefe      165:   char buf[16];
1.78      fefe      166:   hints.ai_family = AF_UNSPEC;
1.79      fefe      167:   hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
1.78      fefe      168:   hints.ai_socktype = SOCK_STREAM;
1.106     fefe      169:   printf("%d\n",getaddrinfo("ftp.fu-berlin.de","ftp",0,&ai));
1.76      fefe      170:   while (ai) {
                    171:     printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
                    172:           ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
                    173:                                   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
                    174:           ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
                    175:           ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
1.80      fefe      176:     {
                    177:       char buf[100];
                    178:       inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
                    179:                (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
                    180:                (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
                    181:       printf("  %s\n",buf);
                    182:     }
1.76      fefe      183:     ai=ai->ai_next;
                    184:   }
1.81      fefe      185: #endif
1.76      fefe      186: #if 0
1.71      fefe      187:   int i=foo;
1.75      fefe      188:   printf("load average is %3.2f\n",0.0);
1.76      fefe      189: #endif
1.70      fefe      190: #if 0
1.69      fefe      191:   struct dirent **namelist;
                    192:   int n;
1.16      fefe      193: 
1.69      fefe      194:   n = scandir(".", &namelist, 0, alphasort);
                    195:   if (n < 0)
                    196:     perror("scandir");
                    197:   else {
                    198:     while(n--) {
                    199:       printf("%s\n", namelist[n]->d_name);
                    200:       free(namelist[n]);
                    201:     }
                    202:     free(namelist);
                    203:   }
1.70      fefe      204: #endif
1.68      fefe      205: #if 0
1.67      fefe      206:   char foo[10]="none,zlib";
                    207:   char *tmp,*tmp2=foo;
                    208:   while (tmp=strsep(&tmp2,",")) {
                    209:     puts(tmp);
                    210:   }
1.68      fefe      211: #endif
1.65      fefe      212: #if 0
1.61      fefe      213:   char foo[10];
1.64      fefe      214:   printf("%d %d\n",abs(-3),abs(23));
1.63      fefe      215:   strcpy(foo,"foo");
                    216:   strncat(foo,"barbaz",3);
                    217:   foo[6]=0;
                    218:   puts(foo);
1.65      fefe      219: #endif
1.91      fefe      220: #if 0
1.58      fefe      221:   struct hostent * host;
                    222:   struct in_addr i;
1.57      fefe      223: 
1.90      fefe      224:   host = gethostbyname2("borg",AF_INET6);
1.57      fefe      225: 
1.58      fefe      226:   if (!host)
                    227:     printf("host null\n");
1.57      fefe      228: 
1.58      fefe      229:   if (host && host->h_name) {
                    230:     printf("name %s\n", host->h_name);
                    231:   }
                    232:   if (host && (host->h_addr_list)[0]) {
                    233:     struct in_addr address;
                    234:     address = *((struct in_addr *) (host->h_addr_list)[0]);
                    235:     printf("addr %s\n", inet_ntoa(address));
                    236:   }
1.59      fefe      237: #endif
1.57      fefe      238: #if 0
1.56      fefe      239:   struct msgbuf bla;
                    240:   bla.mtype=0;
                    241:   bla.mtext[0]='x';
                    242:   msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57      fefe      243: #endif
1.55      fefe      244: #if 0
1.54      fefe      245:   char buf[PATH_MAX];
                    246:   printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55      fefe      247: #endif
1.73      fefe      248: #if 0
1.53      fefe      249:   regex_t t;
1.68      fefe      250:   regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65      fefe      251:   printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56      fefe      252: #endif
1.53      fefe      253: #if 0
1.52      fefe      254:   float my_float = 9.2334;
                    255:   char buffer[100];
                    256: 
                    257:   sprintf(buffer, "%.2f", my_float);
                    258:   fprintf(stdout, "%s", buffer);
1.53      fefe      259: #endif
1.52      fefe      260: #if 0
1.51      fefe      261:   printf("%d\n",setenv("foo","bar",0));
                    262:   printf("%d\n",setenv("foo","bar",1));
                    263:   execlp("printenv","printenv","foo",0);
1.52      fefe      264: #endif
1.106     fefe      265: #if 0
1.59      fefe      266:   printf("%d\n",fnmatch("*c*","bin",0));
1.50      fefe      267:   if (!fnmatch("s*", "sub", 0))
                    268:     printf("s* sub\n");
                    269:   if (!fnmatch("s*", "glob", 0))
                    270:     printf("s* glob\n");
                    271:   if (!fnmatch("s*b", "sub", 0))
                    272:     printf("s*b sub\n");
                    273:   if (!fnmatch("s*h", "sub", 0))
                    274:     printf("s*h sub\n");
1.51      fefe      275: #endif
1.49      fefe      276: #if 0
1.48      fefe      277:   char*tmp;
                    278:   int n=asprintf(&tmp,"foo %s %d\n","bar",23);
                    279:   write(1,tmp,n);
                    280:   free(tmp);
1.49      fefe      281: #endif
1.41      fefe      282: #if 0
1.40      fefe      283:   struct passwd *p=getpwnam("leitner");
1.41      fefe      284:   struct spwd *s=getspnam("leitner");
1.39      fefe      285:   printf("%g\n",30.0123);
1.41      fefe      286: #endif
1.43      fefe      287: #if 0
1.42      fefe      288:   initgroups("root",100);
1.43      fefe      289: #endif
1.38      fefe      290: #if 0
1.37      fefe      291:   time_t t=time(0);
                    292:   puts(asctime(localtime(&t)));
1.38      fefe      293: #endif
1.37      fefe      294: #if 0
1.36      fefe      295:   struct servent *foo=getservbyname("ident","tcp");
                    296:   if (foo)
                    297:     printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37      fefe      298: #endif
1.35      fefe      299: #if 0
1.33      fefe      300:   char buf[128];
                    301:   strcpy(buf,"/tmp/foo.XXXXXXX");
                    302:   printf("%d\n",mkstemp(buf));
1.34      fefe      303:   printf("%s\n",buf);
                    304:   unlink(buf);
1.35      fefe      305: #endif
1.33      fefe      306: #if 0
1.32      fefe      307:   char buf[512]="foo";
                    308:   strncat(buf,"barbaz",3);
                    309:   puts(buf);
1.33      fefe      310: #endif
1.32      fefe      311: #if 0
1.31      fefe      312:   time_t oink=time(0);
                    313:   struct tm *duh=localtime(&oink);
                    314:   strftime(buf,512,"%A %B %Y\n",duh);
                    315:   puts(buf);
1.32      fefe      316: #endif
1.31      fefe      317: #if 0
1.28      fefe      318:   struct in_addr bar;
                    319:   struct hostent *foo;
1.29      fefe      320: /*  inet_aton("160.45.10.8",&bar); */
                    321:   foo=gethostbyname("zeit.fu-berlin.de");
                    322: /*  foo=gethostbyaddr(&bar,4,AF_INET); */
1.30      fefe      323:   if (foo)
                    324:     printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22      fefe      325: /*  printf("%g %g\n",1e-10,1e10); */
1.31      fefe      326: #endif
1.18      fefe      327: #if 0
1.17      fefe      328:   double d=0.0;
                    329:   long long t=0x12345678ABCDEF01;
                    330:   d/=0.0;
                    331:   printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18      fefe      332: #endif
1.17      fefe      333: #if 0
1.16      fefe      334:   int i,j;
                    335:   long a,b,c;
                    336:   int *res;
                    337:   printf("%p\n",malloc(0));
                    338:   qsort(array,2,sizeof(int),compint);
                    339:   for (i=0; i<SIZE; ++i)
                    340:     array[i]=rand();
                    341:   rdtscl(a);
                    342:   qsort(array,SIZE,sizeof(int),compint);
                    343:   rdtscl(b);
                    344:   j=array[LOOKFOR];
                    345:   res=bsearch(&j,array,SIZE,sizeof(int),compint);
                    346:   rdtscl(c);
                    347:   printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
                    348:   for (i=0; i<SIZE-1; ++i)
                    349:     if (array[i]>array[i+1]) {
                    350:       printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
                    351:       return 1;
                    352:     }
                    353:   if (*res!=j)
                    354:     printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
                    355: /*  printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17      fefe      356: #endif
1.13      fefe      357: #if 0
1.12      fefe      358:   struct in_addr duh;
                    359:   printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
                    360:   printf("%x\n",duh.s_addr);
1.13      fefe      361: #endif
1.12      fefe      362: /*  printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11      fefe      363: #if 0
1.10      fefe      364:   char buf[100];
                    365:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
                    366:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11      fefe      367: #endif
1.9       fefe      368: #if 0
1.7       fefe      369:   struct tm duh;
                    370:   time_t t;
1.8       fefe      371:   time(&t);
                    372:   gmtime_r(&t,&duh);
                    373:   printf("%s\n",asctime(&duh));
1.9       fefe      374: #endif
1.8       fefe      375: #if 0
1.7       fefe      376:   char buf[30];
                    377:   duh.tm_sec=42;
                    378:   duh.tm_min=23;
                    379:   duh.tm_hour=17;
                    380:   duh.tm_mday=2;
                    381:   duh.tm_mon=7;
                    382:   duh.tm_year=100;
                    383:   t=mktime(&duh);
                    384:   printf("%s\n",asctime_r(&duh,buf));
1.8       fefe      385: #endif
1.2       fefe      386: #if 0
1.1       cvs       387:   int i;
                    388:   for (i=0; i<5; i++) {
                    389:     fprintf(stdout,"first message\n");
                    390:     fprintf(stdout,"second message\n");
                    391:     fprintf(stdout,"third message\n");
                    392:     printf("foo %d\n",i);
                    393:   }
1.2       fefe      394: #endif
1.1       cvs       395: #if 0
                    396:   char buf[1024];
                    397:   sscanf("foo bar","%s",buf);
                    398:   printf("%s\n",buf);
                    399: #endif
                    400: #if 0
                    401:   mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
                    402:   perror("mount");
                    403: #endif
                    404: #if 0
                    405:   char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
                    406:   int i=strtol(t+1,&t,10);
                    407:   printf("%d %s\n",i,t);
                    408: #endif
                    409: #if 0
                    410:   char **tmp;
                    411:   putenv("FOO");
                    412:   assert(1==2);
                    413:   for (tmp=environ; *tmp; tmp++)
                    414:     puts(*tmp);
                    415: #endif
                    416: #if 0
                    417:   char buf[1024];
                    418:   printf("%d\n",fprintf(stderr,"duh\n"));
                    419: #endif
                    420: #if 0
                    421:   struct passwd *p=getpwuid(100);
                    422:   puts(p->pw_name);
                    423: #endif
                    424: #if 0
                    425:   int pid;
                    426:   char name[32];
                    427:   sscanf("1 (init","%d (%15c",&pid,name);
                    428:   printf("pid %d name %s\n",pid,name);
                    429: #endif
1.108   ! fefe      430: #if 1
1.1       cvs       431:   DIR *d=opendir("/proc");
                    432:   if (d) {
                    433:     struct dirent *D;
                    434:     while (D=readdir(d))
                    435:       puts(D->d_name);
                    436:     closedir(d);
                    437:   }
                    438: #endif
                    439: #if 0
                    440:   char buf[1024];
                    441:   int fd=open("/etc/passwd",0);
                    442:   pread(fd,buf,30,32);
                    443:   close(fd);
                    444:   write(1,buf,32);
                    445: #endif
                    446: #if 0
                    447:   char *argv[] = {"echo","foo",0};
                    448:   char buf[100];
                    449:   buf[5]='x';
                    450:   sprintf(buf,"foo\n");
                    451:   if (buf[5] == 'x')
                    452:     exit(0);
                    453:   else
                    454:     exit(1);
                    455:   execvp(argv[0],argv);
                    456: #endif
1.10      fefe      457: #if 0
1.1       cvs       458:   struct stat64 f;
                    459:   char buf[128];
                    460:   fstat64(0,&f);
                    461:   fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
                    462:   return 0;
                    463: #endif
                    464: #if 0
                    465:   FILE *f=fopen("foo","w");
                    466:   fputc('a',f);
                    467:   fputc('b',f);
                    468:   fputc('c',f);
                    469: #endif
                    470: /*  fprintf(stdout,"foo\n"); */
                    471: }

LinuxTV legacy CVS <linuxtv.org/cvs>