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