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