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