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