Annotation of dietlibc/t.c, revision 1.166

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

LinuxTV legacy CVS <linuxtv.org/cvs>