Annotation of dietlibc/t.c, revision 1.210

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

LinuxTV legacy CVS <linuxtv.org/cvs>