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