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