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