Annotation of dietlibc/t.c, revision 1.97

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

LinuxTV legacy CVS <linuxtv.org/cvs>