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