Annotation of dietlibc/t.c, revision 1.214

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

LinuxTV legacy CVS <linuxtv.org/cvs>