Annotation of dietlibc/t.c, revision 1.221

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

LinuxTV legacy CVS <linuxtv.org/cvs>