Annotation of dietlibc/t.c, revision 1.76

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

LinuxTV legacy CVS <linuxtv.org/cvs>