Annotation of dietlibc/t.c, revision 1.60

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

LinuxTV legacy CVS <linuxtv.org/cvs>