Annotation of dietlibc/t.c, revision 1.197

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.118     fefe       37: #include <sys/wait.h>
1.133     fefe       38: #include <libgen.h>
1.144     fefe       39: #include <math.h>
1.121     fefe       40: #include <errno.h>
                     41: #include <syslog.h>
                     42: #include <sys/un.h>
                     43: #include <fcntl.h>
1.150     fefe       44: #include <iconv.h>
1.166     fefe       45: #include <features.h>
                     46: #ifdef __dietlibc__
                     47: #include <md5.h>
1.170     fefe       48: #include <write12.h>
1.166     fefe       49: #endif
1.121     fefe       50: 
                     51: #if 0
                     52: static const char* Ident;
                     53: static int Option;
                     54: static int Facility;
                     55: static struct sockaddr_un sock;
                     56: static int fd=-1;
                     57: 
                     58: static void syslogconnect(void) {
                     59:   sock.sun_family=AF_UNIX;
                     60:   strcpy(sock.sun_path,"/dev/log");
                     61:   if ((fd=socket(AF_UNIX,SOCK_STREAM,0))==-1) return;
                     62:   if (connect(fd,(struct sockaddr*)&sock,sizeof(sock))==-1) {
                     63:     int save=errno;
                     64:     close(fd);
                     65:     fd=-1;
1.109     fefe       66:   }
1.121     fefe       67:   fcntl(fd,F_SETFL,FD_CLOEXEC);                /* doesn't work?  too bad */
1.109     fefe       68: }
1.107     fefe       69: 
1.121     fefe       70: void openlog(const char *ident, int option, int facility) {
                     71:   Ident=ident;
                     72:   Option=option;
                     73:   Facility=facility;
                     74:   syslogconnect();
1.116     fefe       75: }
                     76: 
1.121     fefe       77: void syslog(int priority, const char *format, ...) {
                     78:   /* write(fd,"<13>Jun 29 19:21:32 leitner: fnord",...) */
                     79: }
                     80: 
                     81: void closelog(void) {
                     82: }
                     83: #endif
                     84: 
1.139     fefe       85: void foo(int tmp,...) {
                     86:   long long l;
                     87:   va_list va;
                     88:   va_start(va,tmp);
                     89:   l=va_arg(va,long long);
                     90:   if (l!=-1) write(2,"kaputt\n",7);
                     91: }
                     92: 
1.176     fefe       93: int compint(const void *a, const void *b) {
1.179     fefe       94:   register const int* A=a;
                     95:   register const int* B=b;
1.176     fefe       96:   return *B-*A;
                     97: }
                     98: 
1.164     fefe       99: extern char* strcpy2(char*a,char*b);
                    100: 
                    101: #define rdtscl(low) \
                    102:      __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
                    103: 
1.97      fefe      104: int main(int argc,char *argv[]) {
1.197   ! fefe      105:   time_t t=1009921588;
        !           106:   puts(asctime(localtime(&t)));
1.196     fefe      107: #if 0
1.195     leitner   108:   printf("%g\n",atof("30"));
1.196     fefe      109: #endif
1.193     leitner   110: #if 0
1.192     leitner   111:   char* buf[]={"FOO=FNORD","A=B","C=D","PATH=/usr/bin:/bin",0};
                    112:   environ=buf;
                    113:   putenv("FOO=BAR");
                    114:   putenv("FOO=BAZ");
                    115:   putenv("BLUB=DUH");
                    116:   system("printenv");
1.193     leitner   117: #endif
1.192     leitner   118: #if 0
1.191     fefe      119:   char buf[1024];
                    120:   time_t t1=time(0);
                    121:   struct tm* t=localtime(&t1);
                    122:   printf("%d %s\n",strftime(buf,sizeof buf,"%b %d %H:%M",t),buf);
1.192     leitner   123: #endif
1.190     fefe      124: #if 0
1.189     fefe      125:   tzset();
                    126:   printf("%d\n",daylight);
1.190     fefe      127: #endif
1.189     fefe      128: #if 0
1.188     fefe      129:   struct in_addr addr;
                    130:   inet_aton("10.0.0.100\t",&addr);
                    131:   printf("%s\n",inet_ntoa(addr));
1.189     fefe      132: #endif
1.168     fefe      133: #if 0
1.169     fefe      134:   printf("%u\n",getuid32());
                    135: #endif
                    136: #if 0
1.167     fefe      137:   FILE *f;
                    138:   int i;
                    139:   char addr6p[8][5];
                    140:   int plen, scope, dad_status, if_idx;
                    141:   char addr6[40], devname[20];
                    142:   if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) {
                    143:     while ((i=fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
                    144:                addr6p[0], addr6p[1], addr6p[2], addr6p[3],
                    145:                addr6p[4], addr6p[5], addr6p[6], addr6p[7],
                    146:                &if_idx, &plen, &scope, &dad_status, devname)) != EOF) {
                    147:       printf("i=%d\n",i);
                    148:     }
                    149:   }
1.168     fefe      150: #endif
1.169     fefe      151: #if 0
1.166     fefe      152:   printf("%s\n",crypt("test","$1$"));
1.167     fefe      153: #endif
1.173     fefe      154: #if 0
1.166     fefe      155:   MD5_CTX x;
                    156:   unsigned char md5[16];
                    157:   MD5Init(&x);
1.167     fefe      158:   MD5Update(&x,"a",1);
1.166     fefe      159:   MD5Final(md5,&x);
                    160:   {
                    161:     int i;
                    162:     for (i=0; i<16; ++i) {
                    163:       printf("%02x",md5[i]);
                    164:     }
                    165:     putchar('\n');
                    166:   }
                    167: #endif
1.164     fefe      168: #if 0
                    169:   long a,b,c;
1.161     fefe      170:   char buf[20]="fnord";
1.164     fefe      171:   strcpy(buf,"Fnordhausen");
                    172:   strcpy2(buf,"Fnordhausen");
                    173:   rdtscl(a);
                    174:   strcpy(buf,"Fnordhausen");
                    175:   rdtscl(b);
                    176:   strcpy2(buf,"Fnordhausen");
                    177:   rdtscl(c);
                    178:   printf("C: %d ticks, asm: %d ticks\n",b-a,c-b);
                    179: #endif
                    180: 
1.163     fefe      181: /*  printf("%d\n",strcmp(buf,"fnord")); */
1.157     fefe      182: #if 0
                    183:   regex_t r;
                    184: //  printf("regcomp %d\n",regcomp(&r,"^(re([\\[0-9\\]+])*|aw):[ \t]*",REG_EXTENDED));
                    185:   printf("regcomp %d\n",regcomp(&r,"^([A-Za-z ]+>|[]>:|}-][]>:|}-]*)",REG_EXTENDED));
                    186:   printf("regexec %d\n",regexec(&r,"Marketing-Laufbahn hinterdir.",1,0,REG_NOSUB));
                    187: #endif
                    188: #if 0
1.156     fefe      189:   FILE *f=fopen("/home/leitner/Mail/outbox","r");
                    190:   char buf[1024];
                    191:   int i=0;
                    192:   if (f) {
                    193:     while (fgets(buf,1023,f)) {
                    194:       ++i;
                    195:       printf("%d %lu %s",i,ftell(f),buf);
                    196:     }
                    197:   }
1.157     fefe      198: #endif
1.152     fefe      199: #if 0
1.151     fefe      200:   char template[]="/tmp/duh/fnord-XXXXXX";
                    201:   printf("%d\n",mkdtemp(template));
1.152     fefe      202: #endif
1.151     fefe      203: #if 0
1.150     fefe      204:   char *inbuf="\xe2\x89\xa0";
                    205: //  char *inbuf="\xc2\xa9";
                    206:   char outbuf[100];
                    207:   char *obptr=&outbuf;
                    208:   size_t iblen=strlen(inbuf);
                    209:   size_t oblen=100;
                    210:   iconv_t i=iconv_open("utf-8","utf-8");
                    211:   iconv(i,&inbuf,&iblen,&obptr,&oblen);
                    212:   iconv_close(i);
                    213:   outbuf[100-oblen]=0;
                    214:   puts(outbuf);
1.151     fefe      215: #endif
1.150     fefe      216: #if 0
1.149     fefe      217:   printf("%c %c\n",tolower('C'),toupper('c'));
1.150     fefe      218: #endif
1.147     fefe      219: #if 0
1.145     fefe      220:   printf("foo\n");
1.146     fefe      221: #endif
1.145     fefe      222: #if 0
                    223:   char strport[10];
                    224:   int i;
                    225:   for (i=0; i<10; ++i) strport[i]=i+'0';
                    226:   snprintf( strport, sizeof(strport), "%d", 80 );
                    227:   puts(strport);
                    228: #endif
1.179     fefe      229: #if 0
1.145     fefe      230:   struct addrinfo *ai;
                    231:   struct addrinfo hints;
                    232:   char buf[16];
                    233:   memset(&hints,0,sizeof(hints));
1.157     fefe      234: #if 0
1.145     fefe      235:   hints.ai_family = AF_UNSPEC;
                    236:   hints.ai_flags = AI_PASSIVE;
                    237:   hints.ai_socktype = SOCK_STREAM;
1.157     fefe      238: #endif
                    239:   hints.ai_family=0;
                    240:   hints.ai_flags=0;
                    241:   hints.ai_socktype=1;
                    242:   hints.ai_protocol=0;
                    243:   hints.ai_addrlen=0;
                    244:   hints.ai_addr=0;
                    245:   hints.ai_canonname=0;
                    246:   hints.ai_next=0;
                    247:   printf("%d\n",getaddrinfo("news.fu-berlin.de","119",&hints,&ai));
1.145     fefe      248:   while (ai) {
                    249:     printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
                    250:           ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
                    251:                                   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
                    252:           ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
                    253:           ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
                    254:     {
                    255:       char buf[100];
                    256:       inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
                    257:                (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
                    258:                (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
                    259:       printf("  %s\n",buf);
                    260:     }
                    261:     ai=ai->ai_next;
                    262:   }
                    263: #endif
1.144     fefe      264: #if 0
                    265:   char buf[101];
                    266:   __dtostr(M_PI,buf,100,6);
                    267: #endif
1.145     fefe      268: #if 0
1.144     fefe      269:   printf("%d\n",strcasecmp("foo","FOO"));
1.145     fefe      270: #endif
1.144     fefe      271: #if 0
1.143     fefe      272:   printf("%.24s", "Sun Jan  2 08:29:13 1994\n");
1.144     fefe      273: #endif
1.143     fefe      274: #if 0
                    275:   printf("%.*s\n",13,"fnord");
                    276: #endif
1.141     fefe      277: #if 0
1.140     fefe      278:   double d=strtod(argv[1],0);
                    279:   printf("%g|\n",d);
1.141     fefe      280: #endif
1.140     fefe      281: #if 0
1.139     fefe      282:   char buf[100];
                    283:   printf("%d\n",__lltostr(buf,30,-1ll,10,0));
                    284:   puts(buf);
1.140     fefe      285: #endif
                    286: #if 0
1.139     fefe      287:   printf("%lld\n",-1ll);
                    288: #endif
1.143     fefe      289: #if 0
1.139     fefe      290:   char *str="e";
                    291:   setbuf(stdout,0);
                    292:   printf("foo\n");
                    293:   fputc(toupper(*str++),stdout);
                    294:   printf("bar\n");
1.138     fefe      295: #endif
1.137     fefe      296: #if 0
1.136     fefe      297:   fwrite("foobar",6,1,stdout);
1.137     fefe      298: #endif
1.136     fefe      299: #if 0
1.135     fefe      300:   char x[5];
                    301:   x[4]='x';
                    302:   fgets(x,4,stdin);
                    303:   puts(x);
                    304:   printf("%c\n",x[4]);
1.136     fefe      305: #endif
1.134     fefe      306: #if 0
1.133     fefe      307:   char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
                    308:   char* want[]={"/usr","/",".","/",".","."};
                    309:   int i;
                    310:   for (i=0; i<6; ++i) {
                    311:     printf("%s\t%s\t%s\n",paths[i],want[i],dirname(strdup(paths[i])));
                    312:   }
1.134     fefe      313: #endif
1.133     fefe      314: #if 0
                    315:   char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
                    316:   char* want[]={"lib","usr","usr","/",".",".."};
                    317:   int i;
                    318:   for (i=0; i<6; ++i) {
                    319:     printf("%s\t%s\t%s\n",paths[i],want[i],basename(strdup(paths[i])));
                    320:   }
                    321: #endif
                    322: #if 0
1.132     fefe      323:   int i;
                    324:   for (i=0; i<255; ++i) {
                    325:     int a=isalpha(i);
                    326:     int b=(i>='a' && i<='z') || (i>='A' && i<='Z');
                    327:     if (a!=b) printf("%d: %d %d\n",i,a,b);
                    328:   }
1.133     fefe      329: #endif
1.131     fefe      330: #if 0
1.130     fefe      331:   char* name;
                    332:   int ptyfd,ttyfd;
                    333:   int i=openpty(&ptyfd,&ttyfd,0,0,0);
                    334:   if (i<0) perror("openpty");
                    335:   printf("%d %d\n",ptyfd,ttyfd);
                    336:   printf("%s %s\n",ttyname(ptyfd),ttyname(ttyfd));
1.131     fefe      337: #endif
1.129     fefe      338: #if 0
                    339:   printf("0x%8.7lx\n",0xfefe);
                    340: #endif
                    341: #if 0
1.128     fefe      342:   puts(ttyname(0));
1.129     fefe      343: #endif
1.195     leitner   344: #if 0
1.125     fefe      345:   char buf[1024];
                    346:   struct hostent* r;
1.194     leitner   347:   int i=0;
                    348:   r=gethostbyname("cyberelks.net");
                    349: again:
1.174     fefe      350:   if (!r) {
                    351:     printf("dns error: %s\n",hstrerror(h_errno));
                    352:   }
1.152     fefe      353:   {
                    354: /*  while (r=gethostent_r(buf,1024)) { */
1.125     fefe      355:     if (r && r->h_name) {
1.152     fefe      356:       int i;
                    357:       printf("name \"%s\"; ", r->h_name);
                    358:       for (i=0; i<8; ++i)
                    359:        if (r->h_aliases[i]) {
                    360:          printf("alias \"%s\"; ",r->h_aliases[i]);
1.174     fefe      361:        } else break;
1.152     fefe      362:       if ((r->h_addr_list)[0]) {
                    363:        struct in_addr address;
                    364:        address = *((struct in_addr *) (r->h_addr_list)[0]);
                    365:        printf("addr %s; ", inet_ntoa(address));
                    366:       }
                    367:       putchar('\n');
1.125     fefe      368:     }
1.194     leitner   369:   }
                    370:   if (!i) {
                    371:     i=1;
                    372:     r=gethostbyname("prdownloads.sourceforge.net");
                    373:     goto again;
1.125     fefe      374:   }
                    375: #endif
                    376: #if 0
1.124     fefe      377:   char *tmp;
                    378:   printf("%lu\n",strtol("0xf0000000",&tmp,0));
1.125     fefe      379: #endif
1.128     fefe      380: #if 0
1.123     fefe      381:   struct mntent* me;
1.127     fefe      382:   FILE* f=fopen("/etc/fstab","r");
1.123     fefe      383:   while (me=getmntent(f)) {
1.139     fefe      384:     printf("%s\n",hasmntopt(me,"defaults"));
1.123     fefe      385:     printf("%s %s %s %s %d %d\n",me->mnt_fsname,me->mnt_dir,me->mnt_type,me->mnt_opts,me->mnt_freq,me->mnt_passno);
1.139     fefe      386:     break;
1.123     fefe      387:   }
1.124     fefe      388: #endif
1.123     fefe      389: #if 0
                    390:   char *tmp;
                    391:   printf("%x\n",strtol("0Xffff",&tmp,16));
                    392: #endif
1.155     fefe      393: /*  putchar('c');
                    394:   write(1,"fnord\n",6); */
1.176     fefe      395: #if 0
1.121     fefe      396:   struct addrinfo *ai;
1.175     fefe      397: //  getaddrinfo("xorn","22",0,&ai);
                    398:   puts(gai_strerror(getaddrinfo("xorn","22",0,&ai)));
1.121     fefe      399: #endif
1.122     fefe      400: #if 0
1.121     fefe      401:   struct hostent host,*res;
                    402:   char buf[4096];
                    403:   int fnord;
                    404: 
1.131     fefe      405:   gethostbyname2_r("nagus",AF_INET,&host,buf,4096,&res,&fnord);
1.122     fefe      406: #endif
1.121     fefe      407: #if 0
1.119     fefe      408:   char buf[128];
1.120     fefe      409:   strcpy(buf,"/tmp/fnord/foo.XXXXXXX");
1.119     fefe      410:   printf("%d\n",mkdtemp(buf));
                    411:   printf("%s\n",buf);
1.120     fefe      412: #endif
1.119     fefe      413: #if 0
1.118     fefe      414:   printf("%d\n",WEXITSTATUS(system("exit 17")));
1.119     fefe      415: #endif
1.113     fefe      416: #if 0
1.109     fefe      417:   fnord("fnord","foo\n","bar\n",0);
1.112     fefe      418:   assert(0);
1.113     fefe      419: #endif
1.105     fefe      420: #if 0
                    421:   printf("%hd %hhd\n",-5,-1234567);
                    422: #endif
1.103     fefe      423: #if 0
1.102     fefe      424:   printf("%d\n",fnmatch("*.o", "x.o", FNM_PATHNAME));
                    425:   printf("%d\n",fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME));
1.103     fefe      426: #endif
1.102     fefe      427: #if 0
1.101     fefe      428:   char buf[1024];
                    429:   int len;
                    430:   len=res_search("fu-berlin.de",ns_c_in,ns_t_ns,buf,sizeof(buf));
1.102     fefe      431: #endif
1.114     fefe      432: #if 0
1.100     fefe      433:   regex_t t;
                    434:   regmatch_t rm;
1.103     fefe      435: //  regcomp(&t,"^ *read",0);
1.113     fefe      436:   regcomp(&t,"\\<foo\\>",0);
                    437:   printf("%d\n",regexec(&t,"  blub foo,",1,&rm,0));
1.100     fefe      438:   printf("ofs %d\n",rm.rm_so);
1.101     fefe      439: #endif
1.100     fefe      440: #if 0
1.98      fefe      441:   char buf[100];
1.99      fefe      442:   printf("%d\n",fread(buf,1,0,stdin));
1.100     fefe      443: #endif
1.99      fefe      444: #if 0
                    445:   char buf[100];
1.98      fefe      446:   memset(buf,17,100);
                    447:   buf[0]=0;
                    448:   strncat(buf,"foobarbaz23",10);
                    449:   puts(buf);
1.99      fefe      450: #endif
1.98      fefe      451: #if 0
1.97      fefe      452:   int aflag = 0;
                    453:   int bflag = 0;
                    454:   char *cvalue = NULL;
                    455:   int index;
                    456:   int c;
                    457: 
                    458:   opterr = 1;
                    459: 
                    460:   while ((c = getopt (argc, argv, "abc:")) != -1)
                    461:     switch (c)
                    462:       {
                    463:       case 'a':
                    464:        aflag = 1;
                    465:        break;
                    466:       case 'b':
                    467:        bflag = 1;
                    468:        break;
                    469:       case 'c':
                    470:        cvalue = optarg;
                    471:        break;
                    472:       case '?':
                    473:        if (isprint (optopt))
                    474:          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                    475:        else
                    476:          fprintf (stderr,
                    477:                  "Unknown option character `\\x%x'.\n",
                    478:                  optopt);
                    479:        return 1;
                    480:       default:
                    481:        abort ();
                    482:       }
1.96      fefe      483: 
1.97      fefe      484:   printf ("aflag = %d, bflag = %d, cvalue = %s\n",
                    485:          aflag, bflag, cvalue);
                    486: 
                    487:   for (index = optind; index < argc; index++)
                    488:     printf ("Non-option argument %s\n", argv[index]);
                    489:   return 0;
1.98      fefe      490: #endif
1.97      fefe      491: #if 0
1.96      fefe      492:   char *t="foobar";
                    493:   char *c;
                    494:   char buf[1000];
                    495:   puts(strcat(strcpy(buf,"HOME="),t));
1.97      fefe      496: #endif
1.89      fefe      497: #if 0
                    498:   struct netent* n=getnetbyname("loopback");
                    499:   printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
                    500: #endif
                    501: #if 0
1.88      fefe      502:   fprintf(stdout,"foo\n");
                    503:   sleep(1);
                    504:   fprintf(stdout,"bar");
                    505:   fprintf(stderr,"blonk");
                    506:   sleep(1);
                    507:   fprintf(stdout,"\rbz");
                    508:   sleep(1);
                    509:   fprintf(stdout,"\n");
                    510:   sleep(1);
1.89      fefe      511: #endif
1.87      fefe      512: #if 0
1.86      fefe      513:   sigset_t s;  /* sigsetops */
                    514: 
                    515:   sigemptyset(&s);
                    516:   sigaddset(&s,SIGCHLD);
                    517:   sigaddset(&s,SIGHUP);
                    518:   sigsuspend(&s);
1.87      fefe      519: #endif
1.85      fefe      520: #if 0
1.84      fefe      521:   char buf[1024];
                    522:   FILE *f=popen("uname -srm","r");
                    523:   fgets(buf,1023,f);
                    524:   pclose(f);
                    525:   write(1,buf,strlen(buf));
1.85      fefe      526: #endif
1.84      fefe      527: #if 0
1.82      fefe      528:   char type[64];
1.83      fefe      529:   char filename[256];
                    530:   int major,minor;
1.82      fefe      531:   int len;
1.83      fefe      532:   printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
                    533:   printf("%s %s %d %d\n",type,filename,major,minor);
1.84      fefe      534: #endif
1.82      fefe      535: #if 0
1.81      fefe      536:   char buf[100];
                    537:   char ip[16];
                    538:   memset(ip,0,16);
                    539:   printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
                    540:   puts(buf);
1.82      fefe      541: #endif
1.127     fefe      542: #if 0
1.76      fefe      543:   struct addrinfo *ai;
1.78      fefe      544:   struct addrinfo hints;
1.79      fefe      545:   char buf[16];
1.78      fefe      546:   hints.ai_family = AF_UNSPEC;
1.79      fefe      547:   hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
1.78      fefe      548:   hints.ai_socktype = SOCK_STREAM;
1.126     fefe      549:   printf("%d\n",getaddrinfo("xorn.continuum.local","ssh",0,&ai));
1.76      fefe      550:   while (ai) {
                    551:     printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
                    552:           ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
                    553:                                   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
                    554:           ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
                    555:           ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
1.80      fefe      556:     {
                    557:       char buf[100];
                    558:       inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
                    559:                (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
                    560:                (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
                    561:       printf("  %s\n",buf);
                    562:     }
1.76      fefe      563:     ai=ai->ai_next;
                    564:   }
1.81      fefe      565: #endif
1.76      fefe      566: #if 0
1.71      fefe      567:   int i=foo;
1.75      fefe      568:   printf("load average is %3.2f\n",0.0);
1.76      fefe      569: #endif
1.70      fefe      570: #if 0
1.69      fefe      571:   struct dirent **namelist;
                    572:   int n;
1.16      fefe      573: 
1.69      fefe      574:   n = scandir(".", &namelist, 0, alphasort);
                    575:   if (n < 0)
                    576:     perror("scandir");
                    577:   else {
                    578:     while(n--) {
                    579:       printf("%s\n", namelist[n]->d_name);
                    580:       free(namelist[n]);
                    581:     }
                    582:     free(namelist);
                    583:   }
1.70      fefe      584: #endif
1.68      fefe      585: #if 0
1.67      fefe      586:   char foo[10]="none,zlib";
                    587:   char *tmp,*tmp2=foo;
                    588:   while (tmp=strsep(&tmp2,",")) {
                    589:     puts(tmp);
                    590:   }
1.68      fefe      591: #endif
1.65      fefe      592: #if 0
1.61      fefe      593:   char foo[10];
1.64      fefe      594:   printf("%d %d\n",abs(-3),abs(23));
1.63      fefe      595:   strcpy(foo,"foo");
                    596:   strncat(foo,"barbaz",3);
                    597:   foo[6]=0;
                    598:   puts(foo);
1.65      fefe      599: #endif
1.115     fefe      600: #if 0
1.58      fefe      601:   struct hostent * host;
                    602:   struct in_addr i;
1.57      fefe      603: 
1.131     fefe      604:   host = gethostbyname2("nagus",AF_INET);
1.57      fefe      605: 
1.58      fefe      606:   if (!host)
                    607:     printf("host null\n");
1.57      fefe      608: 
1.58      fefe      609:   if (host && host->h_name) {
                    610:     printf("name %s\n", host->h_name);
                    611:   }
                    612:   if (host && (host->h_addr_list)[0]) {
                    613:     struct in_addr address;
                    614:     address = *((struct in_addr *) (host->h_addr_list)[0]);
                    615:     printf("addr %s\n", inet_ntoa(address));
                    616:   }
1.59      fefe      617: #endif
1.57      fefe      618: #if 0
1.56      fefe      619:   struct msgbuf bla;
                    620:   bla.mtype=0;
                    621:   bla.mtext[0]='x';
                    622:   msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57      fefe      623: #endif
1.55      fefe      624: #if 0
1.54      fefe      625:   char buf[PATH_MAX];
                    626:   printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55      fefe      627: #endif
1.73      fefe      628: #if 0
1.53      fefe      629:   regex_t t;
1.68      fefe      630:   regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65      fefe      631:   printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56      fefe      632: #endif
1.53      fefe      633: #if 0
1.52      fefe      634:   float my_float = 9.2334;
                    635:   char buffer[100];
                    636: 
                    637:   sprintf(buffer, "%.2f", my_float);
                    638:   fprintf(stdout, "%s", buffer);
1.53      fefe      639: #endif
1.52      fefe      640: #if 0
1.51      fefe      641:   printf("%d\n",setenv("foo","bar",0));
                    642:   printf("%d\n",setenv("foo","bar",1));
                    643:   execlp("printenv","printenv","foo",0);
1.52      fefe      644: #endif
1.106     fefe      645: #if 0
1.59      fefe      646:   printf("%d\n",fnmatch("*c*","bin",0));
1.50      fefe      647:   if (!fnmatch("s*", "sub", 0))
                    648:     printf("s* sub\n");
                    649:   if (!fnmatch("s*", "glob", 0))
                    650:     printf("s* glob\n");
                    651:   if (!fnmatch("s*b", "sub", 0))
                    652:     printf("s*b sub\n");
                    653:   if (!fnmatch("s*h", "sub", 0))
                    654:     printf("s*h sub\n");
1.51      fefe      655: #endif
1.49      fefe      656: #if 0
1.48      fefe      657:   char*tmp;
                    658:   int n=asprintf(&tmp,"foo %s %d\n","bar",23);
                    659:   write(1,tmp,n);
                    660:   free(tmp);
1.49      fefe      661: #endif
1.41      fefe      662: #if 0
1.40      fefe      663:   struct passwd *p=getpwnam("leitner");
1.41      fefe      664:   struct spwd *s=getspnam("leitner");
1.39      fefe      665:   printf("%g\n",30.0123);
1.41      fefe      666: #endif
1.43      fefe      667: #if 0
1.42      fefe      668:   initgroups("root",100);
1.43      fefe      669: #endif
1.38      fefe      670: #if 0
1.37      fefe      671:   time_t t=time(0);
1.197   ! fefe      672:   printf("%lu\n",t);
1.37      fefe      673:   puts(asctime(localtime(&t)));
1.38      fefe      674: #endif
1.135     fefe      675: #if 0
1.134     fefe      676:   struct servent *foo=getservbyname("pop-3","tcp");
1.36      fefe      677:   if (foo)
                    678:     printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37      fefe      679: #endif
1.121     fefe      680: #if 0
1.33      fefe      681:   char buf[128];
1.120     fefe      682:   strcpy(buf,"/tmp/blub/foo.XXXXXXX");
1.33      fefe      683:   printf("%d\n",mkstemp(buf));
1.34      fefe      684:   printf("%s\n",buf);
                    685:   unlink(buf);
1.35      fefe      686: #endif
1.33      fefe      687: #if 0
1.32      fefe      688:   char buf[512]="foo";
                    689:   strncat(buf,"barbaz",3);
                    690:   puts(buf);
1.33      fefe      691: #endif
1.32      fefe      692: #if 0
1.31      fefe      693:   time_t oink=time(0);
                    694:   struct tm *duh=localtime(&oink);
                    695:   strftime(buf,512,"%A %B %Y\n",duh);
                    696:   puts(buf);
1.32      fefe      697: #endif
1.126     fefe      698: #if 0
1.28      fefe      699:   struct in_addr bar;
                    700:   struct hostent *foo;
1.125     fefe      701:   inet_aton("160.45.10.8",&bar);
                    702: /*  foo=gethostbyname("zeit.fu-berlin.de"); */
                    703:   foo=gethostbyaddr(&bar,4,AF_INET);
1.30      fefe      704:   if (foo)
                    705:     printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22      fefe      706: /*  printf("%g %g\n",1e-10,1e10); */
1.31      fefe      707: #endif
1.18      fefe      708: #if 0
1.17      fefe      709:   double d=0.0;
                    710:   long long t=0x12345678ABCDEF01;
                    711:   d/=0.0;
                    712:   printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18      fefe      713: #endif
1.177     fefe      714: #if 0
1.176     fefe      715: #define SIZE 1000
                    716:   int array[SIZE],array2[SIZE];
1.16      fefe      717:   int i,j;
                    718:   long a,b,c;
1.176     fefe      719:   int *k;
                    720:   for (i=0; i<SIZE; ++i) array[i]=rand();
                    721:   memcpy(array2,array,sizeof(array));
                    722:   qsort(array,SIZE,sizeof(int),compint);
                    723:   for (i=0; i<SIZE-1; ++i)
                    724:     assert(array[i]>array[i+1]);
                    725:   k=bsearch(array+10,array,SIZE,sizeof(int),compint);
                    726:   printf("%d\n",*k);
                    727: #endif
                    728: #if 0
1.16      fefe      729:   printf("%p\n",malloc(0));
                    730:   qsort(array,2,sizeof(int),compint);
                    731:   for (i=0; i<SIZE; ++i)
                    732:     array[i]=rand();
                    733:   rdtscl(a);
                    734:   qsort(array,SIZE,sizeof(int),compint);
                    735:   rdtscl(b);
                    736:   j=array[LOOKFOR];
                    737:   res=bsearch(&j,array,SIZE,sizeof(int),compint);
                    738:   rdtscl(c);
                    739:   printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
                    740:   for (i=0; i<SIZE-1; ++i)
                    741:     if (array[i]>array[i+1]) {
                    742:       printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
                    743:       return 1;
                    744:     }
                    745:   if (*res!=j)
                    746:     printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
                    747: /*  printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17      fefe      748: #endif
1.13      fefe      749: #if 0
1.12      fefe      750:   struct in_addr duh;
                    751:   printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
                    752:   printf("%x\n",duh.s_addr);
1.13      fefe      753: #endif
1.12      fefe      754: /*  printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11      fefe      755: #if 0
1.10      fefe      756:   char buf[100];
                    757:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
                    758:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11      fefe      759: #endif
1.9       fefe      760: #if 0
1.7       fefe      761:   struct tm duh;
                    762:   time_t t;
1.8       fefe      763:   time(&t);
                    764:   gmtime_r(&t,&duh);
                    765:   printf("%s\n",asctime(&duh));
1.9       fefe      766: #endif
1.8       fefe      767: #if 0
1.7       fefe      768:   char buf[30];
                    769:   duh.tm_sec=42;
                    770:   duh.tm_min=23;
                    771:   duh.tm_hour=17;
                    772:   duh.tm_mday=2;
                    773:   duh.tm_mon=7;
                    774:   duh.tm_year=100;
                    775:   t=mktime(&duh);
                    776:   printf("%s\n",asctime_r(&duh,buf));
1.8       fefe      777: #endif
1.2       fefe      778: #if 0
1.1       cvs       779:   int i;
                    780:   for (i=0; i<5; i++) {
                    781:     fprintf(stdout,"first message\n");
                    782:     fprintf(stdout,"second message\n");
                    783:     fprintf(stdout,"third message\n");
                    784:     printf("foo %d\n",i);
                    785:   }
1.2       fefe      786: #endif
1.1       cvs       787: #if 0
                    788:   char buf[1024];
                    789:   sscanf("foo bar","%s",buf);
                    790:   printf("%s\n",buf);
                    791: #endif
                    792: #if 0
                    793:   mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
                    794:   perror("mount");
                    795: #endif
                    796: #if 0
                    797:   char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
                    798:   int i=strtol(t+1,&t,10);
                    799:   printf("%d %s\n",i,t);
                    800: #endif
                    801: #if 0
                    802:   char **tmp;
1.115     fefe      803:   putenv("A=foo");
1.1       cvs       804:   for (tmp=environ; *tmp; tmp++)
                    805:     puts(*tmp);
                    806: #endif
                    807: #if 0
                    808:   char buf[1024];
                    809:   printf("%d\n",fprintf(stderr,"duh\n"));
                    810: #endif
                    811: #if 0
                    812:   struct passwd *p=getpwuid(100);
                    813:   puts(p->pw_name);
                    814: #endif
                    815: #if 0
                    816:   int pid;
                    817:   char name[32];
                    818:   sscanf("1 (init","%d (%15c",&pid,name);
                    819:   printf("pid %d name %s\n",pid,name);
                    820: #endif
1.109     fefe      821: #if 0
1.1       cvs       822:   DIR *d=opendir("/proc");
                    823:   if (d) {
                    824:     struct dirent *D;
                    825:     while (D=readdir(d))
                    826:       puts(D->d_name);
                    827:     closedir(d);
                    828:   }
                    829: #endif
                    830: #if 0
                    831:   char buf[1024];
                    832:   int fd=open("/etc/passwd",0);
                    833:   pread(fd,buf,30,32);
                    834:   close(fd);
                    835:   write(1,buf,32);
                    836: #endif
                    837: #if 0
                    838:   char *argv[] = {"echo","foo",0};
                    839:   char buf[100];
                    840:   buf[5]='x';
                    841:   sprintf(buf,"foo\n");
                    842:   if (buf[5] == 'x')
                    843:     exit(0);
                    844:   else
                    845:     exit(1);
                    846:   execvp(argv[0],argv);
                    847: #endif
1.10      fefe      848: #if 0
1.1       cvs       849:   struct stat64 f;
                    850:   char buf[128];
                    851:   fstat64(0,&f);
                    852:   fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
                    853:   return 0;
                    854: #endif
                    855: #if 0
                    856:   FILE *f=fopen("foo","w");
                    857:   fputc('a',f);
                    858:   fputc('b',f);
                    859:   fputc('c',f);
                    860: #endif
                    861: /*  fprintf(stdout,"foo\n"); */
                    862: }

LinuxTV legacy CVS <linuxtv.org/cvs>