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