Annotation of dietlibc/t.c, revision 1.222

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

LinuxTV legacy CVS <linuxtv.org/cvs>