Annotation of dietlibc/t.c, revision 1.198

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

LinuxTV legacy CVS <linuxtv.org/cvs>