Annotation of dietlibc/t.c, revision 1.63

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

LinuxTV legacy CVS <linuxtv.org/cvs>