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