Annotation of dietlibc/t.c, revision 1.171

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

LinuxTV legacy CVS <linuxtv.org/cvs>