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