Annotation of dietlibc/t.c, revision 1.146

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

LinuxTV legacy CVS <linuxtv.org/cvs>