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