Annotation of dietlibc/t.c, revision 1.84

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

LinuxTV legacy CVS <linuxtv.org/cvs>