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