Annotation of dietlibc/t.c, revision 1.170

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

LinuxTV legacy CVS <linuxtv.org/cvs>