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