Annotation of dietlibc/t.c, revision 1.77

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.1       cvs        30: 
1.71      fefe       31: int foo;
                     32: 
1.69      fefe       33: int main(int argc,char *argv[]) {
1.77    ! fefe       34:   printf("%p\n",mmap(0,23,PROT_READ,MAP_PRIVATE,0,0));
        !            35: #if 0
1.76      fefe       36:   struct addrinfo *ai;
                     37:   printf("%d\n",getaddrinfo("knuth.fefe.de","ssh",0,&ai));
                     38:   while (ai) {
                     39:     printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
                     40:           ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
                     41:                                   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
                     42:           ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
                     43:           ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
                     44:     ai=ai->ai_next;
                     45:   }
1.77    ! fefe       46: #endif
1.76      fefe       47: #if 0
1.71      fefe       48:   int i=foo;
1.75      fefe       49:   printf("load average is %3.2f\n",0.0);
1.76      fefe       50: #endif
1.70      fefe       51: #if 0
1.69      fefe       52:   struct dirent **namelist;
                     53:   int n;
1.16      fefe       54: 
1.69      fefe       55:   n = scandir(".", &namelist, 0, alphasort);
                     56:   if (n < 0)
                     57:     perror("scandir");
                     58:   else {
                     59:     while(n--) {
                     60:       printf("%s\n", namelist[n]->d_name);
                     61:       free(namelist[n]);
                     62:     }
                     63:     free(namelist);
                     64:   }
1.70      fefe       65: #endif
1.68      fefe       66: #if 0
1.67      fefe       67:   char foo[10]="none,zlib";
                     68:   char *tmp,*tmp2=foo;
                     69:   while (tmp=strsep(&tmp2,",")) {
                     70:     puts(tmp);
                     71:   }
1.68      fefe       72: #endif
1.65      fefe       73: #if 0
1.61      fefe       74:   char foo[10];
1.64      fefe       75:   printf("%d %d\n",abs(-3),abs(23));
1.63      fefe       76:   strcpy(foo,"foo");
                     77:   strncat(foo,"barbaz",3);
                     78:   foo[6]=0;
                     79:   puts(foo);
1.65      fefe       80: #endif
1.59      fefe       81: #if 0
1.58      fefe       82:   struct hostent * host;
                     83:   struct in_addr i;
1.57      fefe       84: 
1.58      fefe       85:   host = gethostbyname("ftp.ciril.fr");
1.57      fefe       86: 
1.58      fefe       87:   if (!host)
                     88:     printf("host null\n");
1.57      fefe       89: 
1.58      fefe       90:   if (host && host->h_name) {
                     91:     printf("name %s\n", host->h_name);
                     92:   }
                     93:   if (host && (host->h_addr_list)[0]) {
                     94:     struct in_addr address;
                     95:     address = *((struct in_addr *) (host->h_addr_list)[0]);
                     96:     printf("addr %s\n", inet_ntoa(address));
                     97:   }
1.59      fefe       98: #endif
1.57      fefe       99: #if 0
1.56      fefe      100:   struct msgbuf bla;
                    101:   bla.mtype=0;
                    102:   bla.mtext[0]='x';
                    103:   msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57      fefe      104: #endif
1.55      fefe      105: #if 0
1.54      fefe      106:   char buf[PATH_MAX];
                    107:   printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55      fefe      108: #endif
1.73      fefe      109: #if 0
1.53      fefe      110:   regex_t t;
1.68      fefe      111:   regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65      fefe      112:   printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56      fefe      113: #endif
1.53      fefe      114: #if 0
1.52      fefe      115:   float my_float = 9.2334;
                    116:   char buffer[100];
                    117: 
                    118:   sprintf(buffer, "%.2f", my_float);
                    119:   fprintf(stdout, "%s", buffer);
1.53      fefe      120: #endif
1.52      fefe      121: #if 0
1.51      fefe      122:   printf("%d\n",setenv("foo","bar",0));
                    123:   printf("%d\n",setenv("foo","bar",1));
                    124:   execlp("printenv","printenv","foo",0);
1.52      fefe      125: #endif
1.60      fefe      126: #if 0
1.59      fefe      127:   printf("%d\n",fnmatch("*c*","bin",0));
1.50      fefe      128:   if (!fnmatch("s*", "sub", 0))
                    129:     printf("s* sub\n");
                    130:   if (!fnmatch("s*", "glob", 0))
                    131:     printf("s* glob\n");
                    132:   if (!fnmatch("s*b", "sub", 0))
                    133:     printf("s*b sub\n");
                    134:   if (!fnmatch("s*h", "sub", 0))
                    135:     printf("s*h sub\n");
1.51      fefe      136: #endif
1.49      fefe      137: #if 0
1.48      fefe      138:   char*tmp;
                    139:   int n=asprintf(&tmp,"foo %s %d\n","bar",23);
                    140:   write(1,tmp,n);
                    141:   free(tmp);
1.49      fefe      142: #endif
1.41      fefe      143: #if 0
1.40      fefe      144:   struct passwd *p=getpwnam("leitner");
1.41      fefe      145:   struct spwd *s=getspnam("leitner");
1.39      fefe      146:   printf("%g\n",30.0123);
1.41      fefe      147: #endif
1.43      fefe      148: #if 0
1.42      fefe      149:   initgroups("root",100);
1.43      fefe      150: #endif
1.38      fefe      151: #if 0
1.37      fefe      152:   time_t t=time(0);
                    153:   puts(asctime(localtime(&t)));
1.38      fefe      154: #endif
1.37      fefe      155: #if 0
1.36      fefe      156:   struct servent *foo=getservbyname("ident","tcp");
                    157:   if (foo)
                    158:     printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37      fefe      159: #endif
1.35      fefe      160: #if 0
1.33      fefe      161:   char buf[128];
                    162:   strcpy(buf,"/tmp/foo.XXXXXXX");
                    163:   printf("%d\n",mkstemp(buf));
1.34      fefe      164:   printf("%s\n",buf);
                    165:   unlink(buf);
1.35      fefe      166: #endif
1.33      fefe      167: #if 0
1.32      fefe      168:   char buf[512]="foo";
                    169:   strncat(buf,"barbaz",3);
                    170:   puts(buf);
1.33      fefe      171: #endif
1.32      fefe      172: #if 0
1.31      fefe      173:   time_t oink=time(0);
                    174:   struct tm *duh=localtime(&oink);
                    175:   strftime(buf,512,"%A %B %Y\n",duh);
                    176:   puts(buf);
1.32      fefe      177: #endif
1.31      fefe      178: #if 0
1.28      fefe      179:   struct in_addr bar;
                    180:   struct hostent *foo;
1.29      fefe      181: /*  inet_aton("160.45.10.8",&bar); */
                    182:   foo=gethostbyname("zeit.fu-berlin.de");
                    183: /*  foo=gethostbyaddr(&bar,4,AF_INET); */
1.30      fefe      184:   if (foo)
                    185:     printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22      fefe      186: /*  printf("%g %g\n",1e-10,1e10); */
1.31      fefe      187: #endif
1.18      fefe      188: #if 0
1.17      fefe      189:   double d=0.0;
                    190:   long long t=0x12345678ABCDEF01;
                    191:   d/=0.0;
                    192:   printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18      fefe      193: #endif
1.17      fefe      194: #if 0
1.16      fefe      195:   int i,j;
                    196:   long a,b,c;
                    197:   int *res;
                    198:   printf("%p\n",malloc(0));
                    199:   qsort(array,2,sizeof(int),compint);
                    200:   for (i=0; i<SIZE; ++i)
                    201:     array[i]=rand();
                    202:   rdtscl(a);
                    203:   qsort(array,SIZE,sizeof(int),compint);
                    204:   rdtscl(b);
                    205:   j=array[LOOKFOR];
                    206:   res=bsearch(&j,array,SIZE,sizeof(int),compint);
                    207:   rdtscl(c);
                    208:   printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
                    209:   for (i=0; i<SIZE-1; ++i)
                    210:     if (array[i]>array[i+1]) {
                    211:       printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
                    212:       return 1;
                    213:     }
                    214:   if (*res!=j)
                    215:     printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
                    216: /*  printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17      fefe      217: #endif
1.13      fefe      218: #if 0
1.12      fefe      219:   struct in_addr duh;
                    220:   printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
                    221:   printf("%x\n",duh.s_addr);
1.13      fefe      222: #endif
1.12      fefe      223: /*  printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11      fefe      224: #if 0
1.10      fefe      225:   char buf[100];
                    226:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
                    227:   fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11      fefe      228: #endif
1.9       fefe      229: #if 0
1.7       fefe      230:   struct tm duh;
                    231:   time_t t;
1.8       fefe      232:   time(&t);
                    233:   gmtime_r(&t,&duh);
                    234:   printf("%s\n",asctime(&duh));
1.9       fefe      235: #endif
1.8       fefe      236: #if 0
1.7       fefe      237:   char buf[30];
                    238:   duh.tm_sec=42;
                    239:   duh.tm_min=23;
                    240:   duh.tm_hour=17;
                    241:   duh.tm_mday=2;
                    242:   duh.tm_mon=7;
                    243:   duh.tm_year=100;
                    244:   t=mktime(&duh);
                    245:   printf("%s\n",asctime_r(&duh,buf));
1.8       fefe      246: #endif
1.2       fefe      247: #if 0
1.1       cvs       248:   int i;
                    249:   for (i=0; i<5; i++) {
                    250:     fprintf(stdout,"first message\n");
                    251:     fprintf(stdout,"second message\n");
                    252:     fprintf(stdout,"third message\n");
                    253:     printf("foo %d\n",i);
                    254:   }
1.2       fefe      255: #endif
1.1       cvs       256: #if 0
                    257:   char buf[1024];
                    258:   sscanf("foo bar","%s",buf);
                    259:   printf("%s\n",buf);
                    260: #endif
                    261: #if 0
                    262:   mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
                    263:   perror("mount");
                    264: #endif
                    265: #if 0
                    266:   char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
                    267:   int i=strtol(t+1,&t,10);
                    268:   printf("%d %s\n",i,t);
                    269: #endif
                    270: #if 0
                    271:   char **tmp;
                    272:   putenv("FOO");
                    273:   assert(1==2);
                    274:   for (tmp=environ; *tmp; tmp++)
                    275:     puts(*tmp);
                    276: #endif
                    277: #if 0
                    278:   char buf[1024];
                    279:   printf("%d\n",fprintf(stderr,"duh\n"));
                    280: #endif
                    281: #if 0
                    282:   struct passwd *p=getpwuid(100);
                    283:   puts(p->pw_name);
                    284: #endif
                    285: #if 0
                    286:   int pid;
                    287:   char name[32];
                    288:   sscanf("1 (init","%d (%15c",&pid,name);
                    289:   printf("pid %d name %s\n",pid,name);
                    290: #endif
                    291: #if 0
                    292:   DIR *d=opendir("/proc");
                    293:   if (d) {
                    294:     struct dirent *D;
                    295:     while (D=readdir(d))
                    296:       puts(D->d_name);
                    297:     closedir(d);
                    298:   }
                    299: #endif
                    300: #if 0
                    301:   char buf[1024];
                    302:   int fd=open("/etc/passwd",0);
                    303:   pread(fd,buf,30,32);
                    304:   close(fd);
                    305:   write(1,buf,32);
                    306: #endif
                    307: #if 0
                    308:   char *argv[] = {"echo","foo",0};
                    309:   char buf[100];
                    310:   buf[5]='x';
                    311:   sprintf(buf,"foo\n");
                    312:   if (buf[5] == 'x')
                    313:     exit(0);
                    314:   else
                    315:     exit(1);
                    316:   execvp(argv[0],argv);
                    317: #endif
1.10      fefe      318: #if 0
1.1       cvs       319:   struct stat64 f;
                    320:   char buf[128];
                    321:   fstat64(0,&f);
                    322:   fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
                    323:   return 0;
                    324: #endif
                    325: #if 0
                    326:   FILE *f=fopen("foo","w");
                    327:   fputc('a',f);
                    328:   fputc('b',f);
                    329:   fputc('c',f);
                    330: #endif
                    331: /*  fprintf(stdout,"foo\n"); */
                    332: }

LinuxTV legacy CVS <linuxtv.org/cvs>