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