Annotation of dietlibc/t.c, revision 1.209

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

LinuxTV legacy CVS <linuxtv.org/cvs>