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