Annotation of dietlibc/t.c, revision 1.66
1.56 fefe 1: #define _GNU_SOURCE
1.47 fefe 2: #define _FILE_OFFSET_BITS 64
1.1 cvs 3: #include <unistd.h>
4: #include <endian.h>
5: #include <stdlib.h>
6: #include <dirent.h>
7: #include <pwd.h>
1.40 fefe 8: #include <shadow.h>
1.1 cvs 9: #include <stdio.h>
10: #include <assert.h>
11: #include <sys/mount.h>
1.7 fefe 12: #include <time.h>
1.9 fefe 13: #include <sys/stat.h>
1.10 fefe 14: #include <stdio.h>
1.12 fefe 15: #include <arpa/inet.h>
1.13 fefe 16: #include <sys/sem.h>
1.14 fefe 17: #include <sys/shm.h>
1.17 fefe 18: #include <math.h>
1.20 fefe 19: #include <termios.h>
1.22 fefe 20: #include <netdb.h>
1.38 fefe 21: #include <sys/mman.h>
1.45 fefe 22: #include <ctype.h>
1.49 fefe 23: #include <mntent.h>
1.53 fefe 24: #include <regex.h>
1.56 fefe 25: #include <sys/types.h>
26: #include <sys/msg.h>
1.63 fefe 27: #include <string.h>
1.1 cvs 28:
1.17 fefe 29: #if 0
1.16 fefe 30: int compint(const void *a,const void *b) {
31: /* printf("comparing %d with %d\n",*(int*)a,*(int*)b); */
32: return (*(int*)a-*(int*)b);
33: }
34:
35: #define SIZE 100000
36: #define LOOKFOR ((SIZE/2)-2)
37:
38: int array[SIZE];
39:
40: #define rdtscl(low) \
41: __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
42:
43: static unsigned int seed=1;
44:
45: static int rand() {
46: return ((seed = seed * 1103515245 + 12345) % ((unsigned int)RAND_MAX + 1));
47: }
1.17 fefe 48: #endif
1.16 fefe 49:
1.24 fefe 50: extern double atof(const char *c);
51:
1.66 ! fefe 52: int compar(const void*a,const void*b) {
! 53: return *(char*)a - *(char*)b;
! 54: }
1.57 fefe 55:
1.12 fefe 56: int main(int argc,char *argv[]) {
1.66 ! fefe 57: char foo[10]="abcdefghij";
! 58: printf("%c\n",*((char*)bsearch("j",foo,10,1,compar)));
1.65 fefe 59: #if 0
1.61 fefe 60: char foo[10];
1.64 fefe 61: printf("%d %d\n",abs(-3),abs(23));
1.63 fefe 62: strcpy(foo,"foo");
63: strncat(foo,"barbaz",3);
64: foo[6]=0;
65: puts(foo);
1.65 fefe 66: #endif
1.59 fefe 67: #if 0
1.58 fefe 68: struct hostent * host;
69: struct in_addr i;
1.57 fefe 70:
1.58 fefe 71: host = gethostbyname("ftp.ciril.fr");
1.57 fefe 72:
1.58 fefe 73: if (!host)
74: printf("host null\n");
1.57 fefe 75:
1.58 fefe 76: if (host && host->h_name) {
77: printf("name %s\n", host->h_name);
78: }
79: if (host && (host->h_addr_list)[0]) {
80: struct in_addr address;
81: address = *((struct in_addr *) (host->h_addr_list)[0]);
82: printf("addr %s\n", inet_ntoa(address));
83: }
1.59 fefe 84: #endif
1.57 fefe 85: #if 0
1.56 fefe 86: struct msgbuf bla;
87: bla.mtype=0;
88: bla.mtext[0]='x';
89: msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57 fefe 90: #endif
1.55 fefe 91: #if 0
1.54 fefe 92: char buf[PATH_MAX];
93: printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55 fefe 94: #endif
1.66 ! fefe 95: #if 0
1.53 fefe 96: regex_t t;
1.65 fefe 97: regcomp(&t,"^OpenSSH[-_]2\\.[012]",5);
98: printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56 fefe 99: #endif
1.53 fefe 100: #if 0
1.52 fefe 101: float my_float = 9.2334;
102: char buffer[100];
103:
104: sprintf(buffer, "%.2f", my_float);
105: fprintf(stdout, "%s", buffer);
1.53 fefe 106: #endif
1.52 fefe 107: #if 0
1.51 fefe 108: printf("%d\n",setenv("foo","bar",0));
109: printf("%d\n",setenv("foo","bar",1));
110: execlp("printenv","printenv","foo",0);
1.52 fefe 111: #endif
1.60 fefe 112: #if 0
1.59 fefe 113: printf("%d\n",fnmatch("*c*","bin",0));
1.50 fefe 114: if (!fnmatch("s*", "sub", 0))
115: printf("s* sub\n");
116: if (!fnmatch("s*", "glob", 0))
117: printf("s* glob\n");
118: if (!fnmatch("s*b", "sub", 0))
119: printf("s*b sub\n");
120: if (!fnmatch("s*h", "sub", 0))
121: printf("s*h sub\n");
1.51 fefe 122: #endif
1.49 fefe 123: #if 0
1.48 fefe 124: char*tmp;
125: int n=asprintf(&tmp,"foo %s %d\n","bar",23);
126: write(1,tmp,n);
127: free(tmp);
1.49 fefe 128: #endif
1.41 fefe 129: #if 0
1.40 fefe 130: struct passwd *p=getpwnam("leitner");
1.41 fefe 131: struct spwd *s=getspnam("leitner");
1.39 fefe 132: printf("%g\n",30.0123);
1.41 fefe 133: #endif
1.43 fefe 134: #if 0
1.42 fefe 135: initgroups("root",100);
1.43 fefe 136: #endif
1.38 fefe 137: #if 0
1.37 fefe 138: time_t t=time(0);
139: puts(asctime(localtime(&t)));
1.38 fefe 140: #endif
1.37 fefe 141: #if 0
1.36 fefe 142: struct servent *foo=getservbyname("ident","tcp");
143: if (foo)
144: printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37 fefe 145: #endif
1.35 fefe 146: #if 0
1.33 fefe 147: char buf[128];
148: strcpy(buf,"/tmp/foo.XXXXXXX");
149: printf("%d\n",mkstemp(buf));
1.34 fefe 150: printf("%s\n",buf);
151: unlink(buf);
1.35 fefe 152: #endif
1.33 fefe 153: #if 0
1.32 fefe 154: char buf[512]="foo";
155: strncat(buf,"barbaz",3);
156: puts(buf);
1.33 fefe 157: #endif
1.32 fefe 158: #if 0
1.31 fefe 159: time_t oink=time(0);
160: struct tm *duh=localtime(&oink);
161: strftime(buf,512,"%A %B %Y\n",duh);
162: puts(buf);
1.32 fefe 163: #endif
1.31 fefe 164: #if 0
1.28 fefe 165: struct in_addr bar;
166: struct hostent *foo;
1.29 fefe 167: /* inet_aton("160.45.10.8",&bar); */
168: foo=gethostbyname("zeit.fu-berlin.de");
169: /* foo=gethostbyaddr(&bar,4,AF_INET); */
1.30 fefe 170: if (foo)
171: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22 fefe 172: /* printf("%g %g\n",1e-10,1e10); */
1.31 fefe 173: #endif
1.18 fefe 174: #if 0
1.17 fefe 175: double d=0.0;
176: long long t=0x12345678ABCDEF01;
177: d/=0.0;
178: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 179: #endif
1.17 fefe 180: #if 0
1.16 fefe 181: int i,j;
182: long a,b,c;
183: int *res;
184: printf("%p\n",malloc(0));
185: qsort(array,2,sizeof(int),compint);
186: for (i=0; i<SIZE; ++i)
187: array[i]=rand();
188: rdtscl(a);
189: qsort(array,SIZE,sizeof(int),compint);
190: rdtscl(b);
191: j=array[LOOKFOR];
192: res=bsearch(&j,array,SIZE,sizeof(int),compint);
193: rdtscl(c);
194: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
195: for (i=0; i<SIZE-1; ++i)
196: if (array[i]>array[i+1]) {
197: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
198: return 1;
199: }
200: if (*res!=j)
201: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
202: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 203: #endif
1.13 fefe 204: #if 0
1.12 fefe 205: struct in_addr duh;
206: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
207: printf("%x\n",duh.s_addr);
1.13 fefe 208: #endif
1.12 fefe 209: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 210: #if 0
1.10 fefe 211: char buf[100];
212: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
213: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 214: #endif
1.9 fefe 215: #if 0
1.7 fefe 216: struct tm duh;
217: time_t t;
1.8 fefe 218: time(&t);
219: gmtime_r(&t,&duh);
220: printf("%s\n",asctime(&duh));
1.9 fefe 221: #endif
1.8 fefe 222: #if 0
1.7 fefe 223: char buf[30];
224: duh.tm_sec=42;
225: duh.tm_min=23;
226: duh.tm_hour=17;
227: duh.tm_mday=2;
228: duh.tm_mon=7;
229: duh.tm_year=100;
230: t=mktime(&duh);
231: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 232: #endif
1.2 fefe 233: #if 0
1.1 cvs 234: int i;
235: for (i=0; i<5; i++) {
236: fprintf(stdout,"first message\n");
237: fprintf(stdout,"second message\n");
238: fprintf(stdout,"third message\n");
239: printf("foo %d\n",i);
240: }
1.2 fefe 241: #endif
1.1 cvs 242: #if 0
243: char buf[1024];
244: sscanf("foo bar","%s",buf);
245: printf("%s\n",buf);
246: #endif
247: #if 0
248: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
249: perror("mount");
250: #endif
251: #if 0
252: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
253: int i=strtol(t+1,&t,10);
254: printf("%d %s\n",i,t);
255: #endif
256: #if 0
257: char **tmp;
258: putenv("FOO");
259: assert(1==2);
260: for (tmp=environ; *tmp; tmp++)
261: puts(*tmp);
262: #endif
263: #if 0
264: char buf[1024];
265: printf("%d\n",fprintf(stderr,"duh\n"));
266: #endif
267: #if 0
268: struct passwd *p=getpwuid(100);
269: puts(p->pw_name);
270: #endif
271: #if 0
272: int pid;
273: char name[32];
274: sscanf("1 (init","%d (%15c",&pid,name);
275: printf("pid %d name %s\n",pid,name);
276: #endif
277: #if 0
278: DIR *d=opendir("/proc");
279: if (d) {
280: struct dirent *D;
281: while (D=readdir(d))
282: puts(D->d_name);
283: closedir(d);
284: }
285: #endif
286: #if 0
287: char buf[1024];
288: int fd=open("/etc/passwd",0);
289: pread(fd,buf,30,32);
290: close(fd);
291: write(1,buf,32);
292: #endif
293: #if 0
294: char *argv[] = {"echo","foo",0};
295: char buf[100];
296: buf[5]='x';
297: sprintf(buf,"foo\n");
298: if (buf[5] == 'x')
299: exit(0);
300: else
301: exit(1);
302: execvp(argv[0],argv);
303: #endif
1.10 fefe 304: #if 0
1.1 cvs 305: struct stat64 f;
306: char buf[128];
307: fstat64(0,&f);
308: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
309: return 0;
310: #endif
311: #if 0
312: FILE *f=fopen("foo","w");
313: fputc('a',f);
314: fputc('b',f);
315: fputc('c',f);
316: #endif
317: /* fprintf(stdout,"foo\n"); */
318: }
LinuxTV legacy CVS <linuxtv.org/cvs>