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