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