Annotation of dietlibc/t.c, revision 1.145

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

LinuxTV legacy CVS <linuxtv.org/cvs>