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