Annotation of dietlibc/t.c, revision 1.220

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

LinuxTV legacy CVS <linuxtv.org/cvs>