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