Annotation of dietlibc/t.c, revision 1.33
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.24 fefe 40: extern double atof(const char *c);
41:
1.12 fefe 42: int main(int argc,char *argv[]) {
1.33 ! fefe 43: char buf[128];
! 44: strcpy(buf,"/tmp/foo.XXXXXXX");
! 45: printf("%d\n",mkstemp(buf));
! 46: #if 0
1.32 fefe 47: char buf[512]="foo";
48: strncat(buf,"barbaz",3);
49: puts(buf);
1.33 ! fefe 50: #endif
1.32 fefe 51: #if 0
1.31 fefe 52: time_t oink=time(0);
53: struct tm *duh=localtime(&oink);
54: strftime(buf,512,"%A %B %Y\n",duh);
55: puts(buf);
1.32 fefe 56: #endif
1.31 fefe 57: #if 0
1.28 fefe 58: struct in_addr bar;
59: struct hostent *foo;
1.29 fefe 60: /* inet_aton("160.45.10.8",&bar); */
61: foo=gethostbyname("zeit.fu-berlin.de");
62: /* foo=gethostbyaddr(&bar,4,AF_INET); */
1.30 fefe 63: if (foo)
64: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22 fefe 65: /* printf("%g %g\n",1e-10,1e10); */
1.31 fefe 66: #endif
1.18 fefe 67: #if 0
1.17 fefe 68: double d=0.0;
69: long long t=0x12345678ABCDEF01;
70: d/=0.0;
71: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 72: #endif
1.17 fefe 73: #if 0
1.16 fefe 74: int i,j;
75: long a,b,c;
76: int *res;
77: printf("%p\n",malloc(0));
78: qsort(array,2,sizeof(int),compint);
79: for (i=0; i<SIZE; ++i)
80: array[i]=rand();
81: rdtscl(a);
82: qsort(array,SIZE,sizeof(int),compint);
83: rdtscl(b);
84: j=array[LOOKFOR];
85: res=bsearch(&j,array,SIZE,sizeof(int),compint);
86: rdtscl(c);
87: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
88: for (i=0; i<SIZE-1; ++i)
89: if (array[i]>array[i+1]) {
90: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
91: return 1;
92: }
93: if (*res!=j)
94: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
95: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 96: #endif
1.13 fefe 97: #if 0
1.12 fefe 98: struct in_addr duh;
99: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
100: printf("%x\n",duh.s_addr);
1.13 fefe 101: #endif
1.12 fefe 102: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 103: #if 0
1.10 fefe 104: char buf[100];
105: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
106: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 107: #endif
1.9 fefe 108: #if 0
1.7 fefe 109: struct tm duh;
110: time_t t;
1.8 fefe 111: time(&t);
112: gmtime_r(&t,&duh);
113: printf("%s\n",asctime(&duh));
1.9 fefe 114: #endif
1.8 fefe 115: #if 0
1.7 fefe 116: char buf[30];
117: duh.tm_sec=42;
118: duh.tm_min=23;
119: duh.tm_hour=17;
120: duh.tm_mday=2;
121: duh.tm_mon=7;
122: duh.tm_year=100;
123: t=mktime(&duh);
124: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 125: #endif
1.2 fefe 126: #if 0
1.1 cvs 127: int i;
128: for (i=0; i<5; i++) {
129: fprintf(stdout,"first message\n");
130: fprintf(stdout,"second message\n");
131: fprintf(stdout,"third message\n");
132: printf("foo %d\n",i);
133: }
1.2 fefe 134: #endif
1.1 cvs 135: #if 0
136: char buf[1024];
137: sscanf("foo bar","%s",buf);
138: printf("%s\n",buf);
139: #endif
140: #if 0
141: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
142: perror("mount");
143: #endif
144: #if 0
145: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
146: int i=strtol(t+1,&t,10);
147: printf("%d %s\n",i,t);
148: #endif
149: #if 0
150: char **tmp;
151: putenv("FOO");
152: assert(1==2);
153: for (tmp=environ; *tmp; tmp++)
154: puts(*tmp);
155: #endif
156: #if 0
157: char buf[1024];
158: printf("%d\n",fprintf(stderr,"duh\n"));
159: #endif
160: #if 0
161: struct passwd *p=getpwuid(100);
162: puts(p->pw_name);
163: #endif
164: #if 0
165: int pid;
166: char name[32];
167: sscanf("1 (init","%d (%15c",&pid,name);
168: printf("pid %d name %s\n",pid,name);
169: #endif
170: #if 0
171: DIR *d=opendir("/proc");
172: if (d) {
173: struct dirent *D;
174: while (D=readdir(d))
175: puts(D->d_name);
176: closedir(d);
177: }
178: #endif
179: #if 0
180: char buf[1024];
181: int fd=open("/etc/passwd",0);
182: pread(fd,buf,30,32);
183: close(fd);
184: write(1,buf,32);
185: #endif
186: #if 0
187: char *argv[] = {"echo","foo",0};
188: char buf[100];
189: buf[5]='x';
190: sprintf(buf,"foo\n");
191: if (buf[5] == 'x')
192: exit(0);
193: else
194: exit(1);
195: execvp(argv[0],argv);
196: #endif
1.10 fefe 197: #if 0
1.1 cvs 198: struct stat64 f;
199: char buf[128];
200: fstat64(0,&f);
201: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
202: return 0;
203: #endif
204: #if 0
205: FILE *f=fopen("foo","w");
206: fputc('a',f);
207: fputc('b',f);
208: fputc('c',f);
209: #endif
210: /* fprintf(stdout,"foo\n"); */
211: }
LinuxTV legacy CVS <linuxtv.org/cvs>