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