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