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