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