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