Annotation of dietlibc/t.c, revision 1.98

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

LinuxTV legacy CVS <linuxtv.org/cvs>