Annotation of dietlibc/t.c, revision 1.189

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

LinuxTV legacy CVS <linuxtv.org/cvs>