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