Annotation of dietlibc/t.c, revision 1.112
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.76 fefe 28: #include <sys/socket.h>
29: #include <netdb.h>
1.86 fefe 30: #include <signal.h>
1.88 fefe 31: #include <sys/io.h>
1.97 fefe 32: #include <getopt.h>
1.101 fefe 33: #include <arpa/nameser.h>
34: #include <resolv.h>
1.102 fefe 35: #include <fnmatch.h>
1.109 fefe 36: #include <stdarg.h>
1.71 fefe 37:
1.109 fefe 38: void fnord(char*x,...) {
39: int i;
40: va_list v;
41: va_start(v,x);
42: for (i=0; i<10; ++i) {
43: char *tmp=va_arg(v,char*);
44: if (!tmp) break;
45: write(1,tmp,strlen(tmp));
46: }
47: }
1.107 fefe 48:
1.97 fefe 49: int main(int argc,char *argv[]) {
1.109 fefe 50: fnord("fnord","foo\n","bar\n",0);
1.112 ! fefe 51: assert(0);
1.105 fefe 52: #if 0
53: printf("%hd %hhd\n",-5,-1234567);
54: #endif
1.103 fefe 55: #if 0
1.102 fefe 56: printf("%d\n",fnmatch("*.o", "x.o", FNM_PATHNAME));
57: printf("%d\n",fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME));
1.103 fefe 58: #endif
1.102 fefe 59: #if 0
1.101 fefe 60: char buf[1024];
61: int len;
62: len=res_search("fu-berlin.de",ns_c_in,ns_t_ns,buf,sizeof(buf));
1.102 fefe 63: #endif
1.104 fefe 64: #if 0
1.100 fefe 65: regex_t t;
66: regmatch_t rm;
1.103 fefe 67: // regcomp(&t,"^ *read",0);
68: regcomp(&t,"^ *read",0);
69: printf("%d\n",regexec(&t," read",1,&rm,0));
1.100 fefe 70: printf("ofs %d\n",rm.rm_so);
1.101 fefe 71: #endif
1.100 fefe 72: #if 0
1.98 fefe 73: char buf[100];
1.99 fefe 74: printf("%d\n",fread(buf,1,0,stdin));
1.100 fefe 75: #endif
1.99 fefe 76: #if 0
77: char buf[100];
1.98 fefe 78: memset(buf,17,100);
79: buf[0]=0;
80: strncat(buf,"foobarbaz23",10);
81: puts(buf);
1.99 fefe 82: #endif
1.98 fefe 83: #if 0
1.97 fefe 84: int aflag = 0;
85: int bflag = 0;
86: char *cvalue = NULL;
87: int index;
88: int c;
89:
90: opterr = 1;
91:
92: while ((c = getopt (argc, argv, "abc:")) != -1)
93: switch (c)
94: {
95: case 'a':
96: aflag = 1;
97: break;
98: case 'b':
99: bflag = 1;
100: break;
101: case 'c':
102: cvalue = optarg;
103: break;
104: case '?':
105: if (isprint (optopt))
106: fprintf (stderr, "Unknown option `-%c'.\n", optopt);
107: else
108: fprintf (stderr,
109: "Unknown option character `\\x%x'.\n",
110: optopt);
111: return 1;
112: default:
113: abort ();
114: }
1.96 fefe 115:
1.97 fefe 116: printf ("aflag = %d, bflag = %d, cvalue = %s\n",
117: aflag, bflag, cvalue);
118:
119: for (index = optind; index < argc; index++)
120: printf ("Non-option argument %s\n", argv[index]);
121: return 0;
1.98 fefe 122: #endif
1.97 fefe 123: #if 0
1.96 fefe 124: char *t="foobar";
125: char *c;
126: char buf[1000];
127: puts(strcat(strcpy(buf,"HOME="),t));
1.97 fefe 128: #endif
1.89 fefe 129: #if 0
130: struct netent* n=getnetbyname("loopback");
131: printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
132: #endif
133: #if 0
1.88 fefe 134: fprintf(stdout,"foo\n");
135: sleep(1);
136: fprintf(stdout,"bar");
137: fprintf(stderr,"blonk");
138: sleep(1);
139: fprintf(stdout,"\rbz");
140: sleep(1);
141: fprintf(stdout,"\n");
142: sleep(1);
1.89 fefe 143: #endif
1.87 fefe 144: #if 0
1.86 fefe 145: sigset_t s; /* sigsetops */
146:
147: sigemptyset(&s);
148: sigaddset(&s,SIGCHLD);
149: sigaddset(&s,SIGHUP);
150: sigsuspend(&s);
1.87 fefe 151: #endif
1.85 fefe 152: #if 0
1.84 fefe 153: char buf[1024];
154: FILE *f=popen("uname -srm","r");
155: fgets(buf,1023,f);
156: pclose(f);
157: write(1,buf,strlen(buf));
1.85 fefe 158: #endif
1.84 fefe 159: #if 0
1.82 fefe 160: char type[64];
1.83 fefe 161: char filename[256];
162: int major,minor;
1.82 fefe 163: int len;
1.83 fefe 164: printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
165: printf("%s %s %d %d\n",type,filename,major,minor);
1.84 fefe 166: #endif
1.82 fefe 167: #if 0
1.81 fefe 168: char buf[100];
169: char ip[16];
170: memset(ip,0,16);
171: printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
172: puts(buf);
1.82 fefe 173: #endif
1.107 fefe 174: #if 0
1.76 fefe 175: struct addrinfo *ai;
1.78 fefe 176: struct addrinfo hints;
1.79 fefe 177: char buf[16];
1.78 fefe 178: hints.ai_family = AF_UNSPEC;
1.79 fefe 179: hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
1.78 fefe 180: hints.ai_socktype = SOCK_STREAM;
1.106 fefe 181: printf("%d\n",getaddrinfo("ftp.fu-berlin.de","ftp",0,&ai));
1.76 fefe 182: while (ai) {
183: printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
184: ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
185: ((struct sockaddr_in*)ai->ai_addr)->sin_port),
186: ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
187: ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
1.80 fefe 188: {
189: char buf[100];
190: inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
191: (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
192: (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
193: printf(" %s\n",buf);
194: }
1.76 fefe 195: ai=ai->ai_next;
196: }
1.81 fefe 197: #endif
1.76 fefe 198: #if 0
1.71 fefe 199: int i=foo;
1.75 fefe 200: printf("load average is %3.2f\n",0.0);
1.76 fefe 201: #endif
1.70 fefe 202: #if 0
1.69 fefe 203: struct dirent **namelist;
204: int n;
1.16 fefe 205:
1.69 fefe 206: n = scandir(".", &namelist, 0, alphasort);
207: if (n < 0)
208: perror("scandir");
209: else {
210: while(n--) {
211: printf("%s\n", namelist[n]->d_name);
212: free(namelist[n]);
213: }
214: free(namelist);
215: }
1.70 fefe 216: #endif
1.68 fefe 217: #if 0
1.67 fefe 218: char foo[10]="none,zlib";
219: char *tmp,*tmp2=foo;
220: while (tmp=strsep(&tmp2,",")) {
221: puts(tmp);
222: }
1.68 fefe 223: #endif
1.65 fefe 224: #if 0
1.61 fefe 225: char foo[10];
1.64 fefe 226: printf("%d %d\n",abs(-3),abs(23));
1.63 fefe 227: strcpy(foo,"foo");
228: strncat(foo,"barbaz",3);
229: foo[6]=0;
230: puts(foo);
1.65 fefe 231: #endif
1.111 fefe 232: #if 0
1.58 fefe 233: struct hostent * host;
234: struct in_addr i;
1.57 fefe 235:
1.110 fefe 236: host = gethostbyname2("knuth",AF_INET);
1.57 fefe 237:
1.58 fefe 238: if (!host)
239: printf("host null\n");
1.57 fefe 240:
1.58 fefe 241: if (host && host->h_name) {
242: printf("name %s\n", host->h_name);
243: }
244: if (host && (host->h_addr_list)[0]) {
245: struct in_addr address;
246: address = *((struct in_addr *) (host->h_addr_list)[0]);
247: printf("addr %s\n", inet_ntoa(address));
248: }
1.59 fefe 249: #endif
1.57 fefe 250: #if 0
1.56 fefe 251: struct msgbuf bla;
252: bla.mtype=0;
253: bla.mtext[0]='x';
254: msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57 fefe 255: #endif
1.55 fefe 256: #if 0
1.54 fefe 257: char buf[PATH_MAX];
258: printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55 fefe 259: #endif
1.73 fefe 260: #if 0
1.53 fefe 261: regex_t t;
1.68 fefe 262: regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65 fefe 263: printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56 fefe 264: #endif
1.53 fefe 265: #if 0
1.52 fefe 266: float my_float = 9.2334;
267: char buffer[100];
268:
269: sprintf(buffer, "%.2f", my_float);
270: fprintf(stdout, "%s", buffer);
1.53 fefe 271: #endif
1.52 fefe 272: #if 0
1.51 fefe 273: printf("%d\n",setenv("foo","bar",0));
274: printf("%d\n",setenv("foo","bar",1));
275: execlp("printenv","printenv","foo",0);
1.52 fefe 276: #endif
1.106 fefe 277: #if 0
1.59 fefe 278: printf("%d\n",fnmatch("*c*","bin",0));
1.50 fefe 279: if (!fnmatch("s*", "sub", 0))
280: printf("s* sub\n");
281: if (!fnmatch("s*", "glob", 0))
282: printf("s* glob\n");
283: if (!fnmatch("s*b", "sub", 0))
284: printf("s*b sub\n");
285: if (!fnmatch("s*h", "sub", 0))
286: printf("s*h sub\n");
1.51 fefe 287: #endif
1.49 fefe 288: #if 0
1.48 fefe 289: char*tmp;
290: int n=asprintf(&tmp,"foo %s %d\n","bar",23);
291: write(1,tmp,n);
292: free(tmp);
1.49 fefe 293: #endif
1.41 fefe 294: #if 0
1.40 fefe 295: struct passwd *p=getpwnam("leitner");
1.41 fefe 296: struct spwd *s=getspnam("leitner");
1.39 fefe 297: printf("%g\n",30.0123);
1.41 fefe 298: #endif
1.43 fefe 299: #if 0
1.42 fefe 300: initgroups("root",100);
1.43 fefe 301: #endif
1.38 fefe 302: #if 0
1.37 fefe 303: time_t t=time(0);
304: puts(asctime(localtime(&t)));
1.38 fefe 305: #endif
1.37 fefe 306: #if 0
1.36 fefe 307: struct servent *foo=getservbyname("ident","tcp");
308: if (foo)
309: printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37 fefe 310: #endif
1.35 fefe 311: #if 0
1.33 fefe 312: char buf[128];
313: strcpy(buf,"/tmp/foo.XXXXXXX");
314: printf("%d\n",mkstemp(buf));
1.34 fefe 315: printf("%s\n",buf);
316: unlink(buf);
1.35 fefe 317: #endif
1.33 fefe 318: #if 0
1.32 fefe 319: char buf[512]="foo";
320: strncat(buf,"barbaz",3);
321: puts(buf);
1.33 fefe 322: #endif
1.32 fefe 323: #if 0
1.31 fefe 324: time_t oink=time(0);
325: struct tm *duh=localtime(&oink);
326: strftime(buf,512,"%A %B %Y\n",duh);
327: puts(buf);
1.32 fefe 328: #endif
1.31 fefe 329: #if 0
1.28 fefe 330: struct in_addr bar;
331: struct hostent *foo;
1.29 fefe 332: /* inet_aton("160.45.10.8",&bar); */
333: foo=gethostbyname("zeit.fu-berlin.de");
334: /* foo=gethostbyaddr(&bar,4,AF_INET); */
1.30 fefe 335: if (foo)
336: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22 fefe 337: /* printf("%g %g\n",1e-10,1e10); */
1.31 fefe 338: #endif
1.18 fefe 339: #if 0
1.17 fefe 340: double d=0.0;
341: long long t=0x12345678ABCDEF01;
342: d/=0.0;
343: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 344: #endif
1.17 fefe 345: #if 0
1.16 fefe 346: int i,j;
347: long a,b,c;
348: int *res;
349: printf("%p\n",malloc(0));
350: qsort(array,2,sizeof(int),compint);
351: for (i=0; i<SIZE; ++i)
352: array[i]=rand();
353: rdtscl(a);
354: qsort(array,SIZE,sizeof(int),compint);
355: rdtscl(b);
356: j=array[LOOKFOR];
357: res=bsearch(&j,array,SIZE,sizeof(int),compint);
358: rdtscl(c);
359: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
360: for (i=0; i<SIZE-1; ++i)
361: if (array[i]>array[i+1]) {
362: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
363: return 1;
364: }
365: if (*res!=j)
366: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
367: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 368: #endif
1.13 fefe 369: #if 0
1.12 fefe 370: struct in_addr duh;
371: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
372: printf("%x\n",duh.s_addr);
1.13 fefe 373: #endif
1.12 fefe 374: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 375: #if 0
1.10 fefe 376: char buf[100];
377: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
378: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 379: #endif
1.9 fefe 380: #if 0
1.7 fefe 381: struct tm duh;
382: time_t t;
1.8 fefe 383: time(&t);
384: gmtime_r(&t,&duh);
385: printf("%s\n",asctime(&duh));
1.9 fefe 386: #endif
1.8 fefe 387: #if 0
1.7 fefe 388: char buf[30];
389: duh.tm_sec=42;
390: duh.tm_min=23;
391: duh.tm_hour=17;
392: duh.tm_mday=2;
393: duh.tm_mon=7;
394: duh.tm_year=100;
395: t=mktime(&duh);
396: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 397: #endif
1.2 fefe 398: #if 0
1.1 cvs 399: int i;
400: for (i=0; i<5; i++) {
401: fprintf(stdout,"first message\n");
402: fprintf(stdout,"second message\n");
403: fprintf(stdout,"third message\n");
404: printf("foo %d\n",i);
405: }
1.2 fefe 406: #endif
1.1 cvs 407: #if 0
408: char buf[1024];
409: sscanf("foo bar","%s",buf);
410: printf("%s\n",buf);
411: #endif
412: #if 0
413: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
414: perror("mount");
415: #endif
416: #if 0
417: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
418: int i=strtol(t+1,&t,10);
419: printf("%d %s\n",i,t);
420: #endif
421: #if 0
422: char **tmp;
423: putenv("FOO");
424: assert(1==2);
425: for (tmp=environ; *tmp; tmp++)
426: puts(*tmp);
427: #endif
428: #if 0
429: char buf[1024];
430: printf("%d\n",fprintf(stderr,"duh\n"));
431: #endif
432: #if 0
433: struct passwd *p=getpwuid(100);
434: puts(p->pw_name);
435: #endif
436: #if 0
437: int pid;
438: char name[32];
439: sscanf("1 (init","%d (%15c",&pid,name);
440: printf("pid %d name %s\n",pid,name);
441: #endif
1.109 fefe 442: #if 0
1.1 cvs 443: DIR *d=opendir("/proc");
444: if (d) {
445: struct dirent *D;
446: while (D=readdir(d))
447: puts(D->d_name);
448: closedir(d);
449: }
450: #endif
451: #if 0
452: char buf[1024];
453: int fd=open("/etc/passwd",0);
454: pread(fd,buf,30,32);
455: close(fd);
456: write(1,buf,32);
457: #endif
458: #if 0
459: char *argv[] = {"echo","foo",0};
460: char buf[100];
461: buf[5]='x';
462: sprintf(buf,"foo\n");
463: if (buf[5] == 'x')
464: exit(0);
465: else
466: exit(1);
467: execvp(argv[0],argv);
468: #endif
1.10 fefe 469: #if 0
1.1 cvs 470: struct stat64 f;
471: char buf[128];
472: fstat64(0,&f);
473: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
474: return 0;
475: #endif
476: #if 0
477: FILE *f=fopen("foo","w");
478: fputc('a',f);
479: fputc('b',f);
480: fputc('c',f);
481: #endif
482: /* fprintf(stdout,"foo\n"); */
483: }
LinuxTV legacy CVS <linuxtv.org/cvs>