Annotation of dietlibc/t.c, revision 1.182

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

LinuxTV legacy CVS <linuxtv.org/cvs>