Annotation of dietlibc/t.c, revision 1.211

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

LinuxTV legacy CVS <linuxtv.org/cvs>