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