Annotation of dietlibc/t.c, revision 1.149

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

LinuxTV legacy CVS <linuxtv.org/cvs>