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