Annotation of dietlibc/t.c, revision 1.168

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

LinuxTV legacy CVS <linuxtv.org/cvs>