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