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