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