Annotation of dietlibc/t.c, revision 1.156

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

LinuxTV legacy CVS <linuxtv.org/cvs>