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