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