Annotation of dietlibc/t.c, revision 1.80

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

LinuxTV legacy CVS <linuxtv.org/cvs>