Annotation of dietlibc/t.c, revision 1.115

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

LinuxTV legacy CVS <linuxtv.org/cvs>