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