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