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