Annotation of dietlibc/t.c, revision 1.102

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

LinuxTV legacy CVS <linuxtv.org/cvs>