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