Annotation of dietlibc/t.c, revision 1.62

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

LinuxTV legacy CVS <linuxtv.org/cvs>