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