Annotation of dietlibc/t.c, revision 1.23
1.1 cvs 1: #include <unistd.h>
2: #include <endian.h>
3: #include <stdlib.h>
4: #include <dirent.h>
5: #include <pwd.h>
6: #include <stdio.h>
7: #include <assert.h>
8: #include <sys/mount.h>
1.7 fefe 9: #include <time.h>
1.9 fefe 10: #include <sys/stat.h>
1.10 fefe 11: #include <stdio.h>
1.12 fefe 12: #include <arpa/inet.h>
1.13 fefe 13: #include <sys/sem.h>
1.14 fefe 14: #include <sys/shm.h>
1.17 fefe 15: #include <math.h>
1.20 fefe 16: #include <termios.h>
1.22 fefe 17: #include <netdb.h>
1.1 cvs 18:
1.17 fefe 19: #if 0
1.16 fefe 20: int compint(const void *a,const void *b) {
21: /* printf("comparing %d with %d\n",*(int*)a,*(int*)b); */
22: return (*(int*)a-*(int*)b);
23: }
24:
25: #define SIZE 100000
26: #define LOOKFOR ((SIZE/2)-2)
27:
28: int array[SIZE];
29:
30: #define rdtscl(low) \
31: __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
32:
33: static unsigned int seed=1;
34:
35: static int rand() {
36: return ((seed = seed * 1103515245 + 12345) % ((unsigned int)RAND_MAX + 1));
37: }
1.17 fefe 38: #endif
1.16 fefe 39:
1.12 fefe 40: int main(int argc,char *argv[]) {
1.22 fefe 41: struct hostent *foo=gethostbyname("knuth.fefe.de");
1.23 ! fefe 42: /* if (foo)
! 43: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr)); */
1.22 fefe 44: /* printf("%g %g\n",1e-10,1e10); */
1.18 fefe 45: #if 0
1.17 fefe 46: double d=0.0;
47: long long t=0x12345678ABCDEF01;
48: d/=0.0;
49: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 50: #endif
1.17 fefe 51: #if 0
1.16 fefe 52: int i,j;
53: long a,b,c;
54: int *res;
55: printf("%p\n",malloc(0));
56: qsort(array,2,sizeof(int),compint);
57: for (i=0; i<SIZE; ++i)
58: array[i]=rand();
59: rdtscl(a);
60: qsort(array,SIZE,sizeof(int),compint);
61: rdtscl(b);
62: j=array[LOOKFOR];
63: res=bsearch(&j,array,SIZE,sizeof(int),compint);
64: rdtscl(c);
65: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
66: for (i=0; i<SIZE-1; ++i)
67: if (array[i]>array[i+1]) {
68: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
69: return 1;
70: }
71: if (*res!=j)
72: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
73: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 74: #endif
1.13 fefe 75: #if 0
1.12 fefe 76: struct in_addr duh;
77: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
78: printf("%x\n",duh.s_addr);
1.13 fefe 79: #endif
1.12 fefe 80: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 81: #if 0
1.10 fefe 82: char buf[100];
83: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
84: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 85: #endif
1.9 fefe 86: #if 0
1.7 fefe 87: struct tm duh;
88: time_t t;
1.8 fefe 89: time(&t);
90: gmtime_r(&t,&duh);
91: printf("%s\n",asctime(&duh));
1.9 fefe 92: #endif
1.8 fefe 93: #if 0
1.7 fefe 94: char buf[30];
95: duh.tm_sec=42;
96: duh.tm_min=23;
97: duh.tm_hour=17;
98: duh.tm_mday=2;
99: duh.tm_mon=7;
100: duh.tm_year=100;
101: t=mktime(&duh);
102: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 103: #endif
1.2 fefe 104: #if 0
1.1 cvs 105: int i;
106: for (i=0; i<5; i++) {
107: fprintf(stdout,"first message\n");
108: fprintf(stdout,"second message\n");
109: fprintf(stdout,"third message\n");
110: printf("foo %d\n",i);
111: }
1.2 fefe 112: #endif
1.1 cvs 113: #if 0
114: char buf[1024];
115: sscanf("foo bar","%s",buf);
116: printf("%s\n",buf);
117: #endif
118: #if 0
119: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
120: perror("mount");
121: #endif
122: #if 0
123: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
124: int i=strtol(t+1,&t,10);
125: printf("%d %s\n",i,t);
126: #endif
127: #if 0
128: char **tmp;
129: putenv("FOO");
130: assert(1==2);
131: for (tmp=environ; *tmp; tmp++)
132: puts(*tmp);
133: #endif
134: #if 0
135: char buf[1024];
136: printf("%d\n",fprintf(stderr,"duh\n"));
137: #endif
138: #if 0
139: struct passwd *p=getpwuid(100);
140: puts(p->pw_name);
141: #endif
142: #if 0
143: int pid;
144: char name[32];
145: sscanf("1 (init","%d (%15c",&pid,name);
146: printf("pid %d name %s\n",pid,name);
147: #endif
148: #if 0
149: DIR *d=opendir("/proc");
150: if (d) {
151: struct dirent *D;
152: while (D=readdir(d))
153: puts(D->d_name);
154: closedir(d);
155: }
156: #endif
157: #if 0
158: char buf[1024];
159: int fd=open("/etc/passwd",0);
160: pread(fd,buf,30,32);
161: close(fd);
162: write(1,buf,32);
163: #endif
164: #if 0
165: char *argv[] = {"echo","foo",0};
166: char buf[100];
167: buf[5]='x';
168: sprintf(buf,"foo\n");
169: if (buf[5] == 'x')
170: exit(0);
171: else
172: exit(1);
173: execvp(argv[0],argv);
174: #endif
1.10 fefe 175: #if 0
1.1 cvs 176: struct stat64 f;
177: char buf[128];
178: fstat64(0,&f);
179: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
180: return 0;
181: #endif
182: #if 0
183: FILE *f=fopen("foo","w");
184: fputc('a',f);
185: fputc('b',f);
186: fputc('c',f);
187: #endif
188: /* fprintf(stdout,"foo\n"); */
189: }
LinuxTV legacy CVS <linuxtv.org/cvs>