Annotation of dietlibc/t.c, revision 1.89
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.1 cvs 32:
1.71 fefe 33: int foo;
34:
1.69 fefe 35: int main(int argc,char *argv[]) {
1.89 ! fefe 36: #if 0
! 37: struct netent* n=getnetbyname("loopback");
! 38: printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
! 39: #endif
! 40: #if 0
1.88 fefe 41: fprintf(stdout,"foo\n");
42: sleep(1);
43: fprintf(stdout,"bar");
44: fprintf(stderr,"blonk");
45: sleep(1);
46: fprintf(stdout,"\rbz");
47: sleep(1);
48: fprintf(stdout,"\n");
49: sleep(1);
1.89 ! fefe 50: #endif
1.87 fefe 51: #if 0
1.86 fefe 52: sigset_t s; /* sigsetops */
53:
54: sigemptyset(&s);
55: sigaddset(&s,SIGCHLD);
56: sigaddset(&s,SIGHUP);
57: sigsuspend(&s);
1.87 fefe 58: #endif
1.85 fefe 59: #if 0
1.84 fefe 60: char buf[1024];
61: FILE *f=popen("uname -srm","r");
62: fgets(buf,1023,f);
63: pclose(f);
64: write(1,buf,strlen(buf));
1.85 fefe 65: #endif
1.84 fefe 66: #if 0
1.82 fefe 67: char type[64];
1.83 fefe 68: char filename[256];
69: int major,minor;
1.82 fefe 70: int len;
1.83 fefe 71: printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
72: printf("%s %s %d %d\n",type,filename,major,minor);
1.84 fefe 73: #endif
1.82 fefe 74: #if 0
1.81 fefe 75: char buf[100];
76: char ip[16];
77: memset(ip,0,16);
78: printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
79: puts(buf);
1.82 fefe 80: #endif
1.86 fefe 81: #if 0
1.76 fefe 82: struct addrinfo *ai;
1.78 fefe 83: struct addrinfo hints;
1.79 fefe 84: char buf[16];
1.78 fefe 85: hints.ai_family = AF_UNSPEC;
1.79 fefe 86: hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
1.78 fefe 87: hints.ai_socktype = SOCK_STREAM;
1.85 fefe 88: printf("%d\n",getaddrinfo("maddison.math.fu-berlin.de","ssh",&hints,&ai));
1.76 fefe 89: while (ai) {
90: printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
91: ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
92: ((struct sockaddr_in*)ai->ai_addr)->sin_port),
93: ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
94: ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
1.80 fefe 95: {
96: char buf[100];
97: inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
98: (char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
99: (char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
100: printf(" %s\n",buf);
101: }
1.76 fefe 102: ai=ai->ai_next;
103: }
1.81 fefe 104: #endif
1.76 fefe 105: #if 0
1.71 fefe 106: int i=foo;
1.75 fefe 107: printf("load average is %3.2f\n",0.0);
1.76 fefe 108: #endif
1.70 fefe 109: #if 0
1.69 fefe 110: struct dirent **namelist;
111: int n;
1.16 fefe 112:
1.69 fefe 113: n = scandir(".", &namelist, 0, alphasort);
114: if (n < 0)
115: perror("scandir");
116: else {
117: while(n--) {
118: printf("%s\n", namelist[n]->d_name);
119: free(namelist[n]);
120: }
121: free(namelist);
122: }
1.70 fefe 123: #endif
1.68 fefe 124: #if 0
1.67 fefe 125: char foo[10]="none,zlib";
126: char *tmp,*tmp2=foo;
127: while (tmp=strsep(&tmp2,",")) {
128: puts(tmp);
129: }
1.68 fefe 130: #endif
1.65 fefe 131: #if 0
1.61 fefe 132: char foo[10];
1.64 fefe 133: printf("%d %d\n",abs(-3),abs(23));
1.63 fefe 134: strcpy(foo,"foo");
135: strncat(foo,"barbaz",3);
136: foo[6]=0;
137: puts(foo);
1.65 fefe 138: #endif
1.89 ! fefe 139: #if 1
1.58 fefe 140: struct hostent * host;
141: struct in_addr i;
1.57 fefe 142:
1.89 ! fefe 143: host = gethostbyname("pegasus");
1.57 fefe 144:
1.58 fefe 145: if (!host)
146: printf("host null\n");
1.57 fefe 147:
1.58 fefe 148: if (host && host->h_name) {
149: printf("name %s\n", host->h_name);
150: }
151: if (host && (host->h_addr_list)[0]) {
152: struct in_addr address;
153: address = *((struct in_addr *) (host->h_addr_list)[0]);
154: printf("addr %s\n", inet_ntoa(address));
155: }
1.59 fefe 156: #endif
1.57 fefe 157: #if 0
1.56 fefe 158: struct msgbuf bla;
159: bla.mtype=0;
160: bla.mtext[0]='x';
161: msgsnd(327680,&bla,5,IPC_NOWAIT);
1.57 fefe 162: #endif
1.55 fefe 163: #if 0
1.54 fefe 164: char buf[PATH_MAX];
165: printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
1.55 fefe 166: #endif
1.73 fefe 167: #if 0
1.53 fefe 168: regex_t t;
1.68 fefe 169: regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
1.65 fefe 170: printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
1.56 fefe 171: #endif
1.53 fefe 172: #if 0
1.52 fefe 173: float my_float = 9.2334;
174: char buffer[100];
175:
176: sprintf(buffer, "%.2f", my_float);
177: fprintf(stdout, "%s", buffer);
1.53 fefe 178: #endif
1.52 fefe 179: #if 0
1.51 fefe 180: printf("%d\n",setenv("foo","bar",0));
181: printf("%d\n",setenv("foo","bar",1));
182: execlp("printenv","printenv","foo",0);
1.52 fefe 183: #endif
1.60 fefe 184: #if 0
1.59 fefe 185: printf("%d\n",fnmatch("*c*","bin",0));
1.50 fefe 186: if (!fnmatch("s*", "sub", 0))
187: printf("s* sub\n");
188: if (!fnmatch("s*", "glob", 0))
189: printf("s* glob\n");
190: if (!fnmatch("s*b", "sub", 0))
191: printf("s*b sub\n");
192: if (!fnmatch("s*h", "sub", 0))
193: printf("s*h sub\n");
1.51 fefe 194: #endif
1.49 fefe 195: #if 0
1.48 fefe 196: char*tmp;
197: int n=asprintf(&tmp,"foo %s %d\n","bar",23);
198: write(1,tmp,n);
199: free(tmp);
1.49 fefe 200: #endif
1.41 fefe 201: #if 0
1.40 fefe 202: struct passwd *p=getpwnam("leitner");
1.41 fefe 203: struct spwd *s=getspnam("leitner");
1.39 fefe 204: printf("%g\n",30.0123);
1.41 fefe 205: #endif
1.43 fefe 206: #if 0
1.42 fefe 207: initgroups("root",100);
1.43 fefe 208: #endif
1.38 fefe 209: #if 0
1.37 fefe 210: time_t t=time(0);
211: puts(asctime(localtime(&t)));
1.38 fefe 212: #endif
1.37 fefe 213: #if 0
1.36 fefe 214: struct servent *foo=getservbyname("ident","tcp");
215: if (foo)
216: printf("found service %s on port %d\n",foo->s_name,foo->s_port);
1.37 fefe 217: #endif
1.35 fefe 218: #if 0
1.33 fefe 219: char buf[128];
220: strcpy(buf,"/tmp/foo.XXXXXXX");
221: printf("%d\n",mkstemp(buf));
1.34 fefe 222: printf("%s\n",buf);
223: unlink(buf);
1.35 fefe 224: #endif
1.33 fefe 225: #if 0
1.32 fefe 226: char buf[512]="foo";
227: strncat(buf,"barbaz",3);
228: puts(buf);
1.33 fefe 229: #endif
1.32 fefe 230: #if 0
1.31 fefe 231: time_t oink=time(0);
232: struct tm *duh=localtime(&oink);
233: strftime(buf,512,"%A %B %Y\n",duh);
234: puts(buf);
1.32 fefe 235: #endif
1.31 fefe 236: #if 0
1.28 fefe 237: struct in_addr bar;
238: struct hostent *foo;
1.29 fefe 239: /* inet_aton("160.45.10.8",&bar); */
240: foo=gethostbyname("zeit.fu-berlin.de");
241: /* foo=gethostbyaddr(&bar,4,AF_INET); */
1.30 fefe 242: if (foo)
243: printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
1.22 fefe 244: /* printf("%g %g\n",1e-10,1e10); */
1.31 fefe 245: #endif
1.18 fefe 246: #if 0
1.17 fefe 247: double d=0.0;
248: long long t=0x12345678ABCDEF01;
249: d/=0.0;
250: printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
1.18 fefe 251: #endif
1.17 fefe 252: #if 0
1.16 fefe 253: int i,j;
254: long a,b,c;
255: int *res;
256: printf("%p\n",malloc(0));
257: qsort(array,2,sizeof(int),compint);
258: for (i=0; i<SIZE; ++i)
259: array[i]=rand();
260: rdtscl(a);
261: qsort(array,SIZE,sizeof(int),compint);
262: rdtscl(b);
263: j=array[LOOKFOR];
264: res=bsearch(&j,array,SIZE,sizeof(int),compint);
265: rdtscl(c);
266: printf("%lu cycles sort, %lu cycles bsearch\n",b-a,c-b);
267: for (i=0; i<SIZE-1; ++i)
268: if (array[i]>array[i+1]) {
269: printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
270: return 1;
271: }
272: if (*res!=j)
273: printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
274: /* printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
1.17 fefe 275: #endif
1.13 fefe 276: #if 0
1.12 fefe 277: struct in_addr duh;
278: printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
279: printf("%x\n",duh.s_addr);
1.13 fefe 280: #endif
1.12 fefe 281: /* printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
1.11 fefe 282: #if 0
1.10 fefe 283: char buf[100];
284: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
285: fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
1.11 fefe 286: #endif
1.9 fefe 287: #if 0
1.7 fefe 288: struct tm duh;
289: time_t t;
1.8 fefe 290: time(&t);
291: gmtime_r(&t,&duh);
292: printf("%s\n",asctime(&duh));
1.9 fefe 293: #endif
1.8 fefe 294: #if 0
1.7 fefe 295: char buf[30];
296: duh.tm_sec=42;
297: duh.tm_min=23;
298: duh.tm_hour=17;
299: duh.tm_mday=2;
300: duh.tm_mon=7;
301: duh.tm_year=100;
302: t=mktime(&duh);
303: printf("%s\n",asctime_r(&duh,buf));
1.8 fefe 304: #endif
1.2 fefe 305: #if 0
1.1 cvs 306: int i;
307: for (i=0; i<5; i++) {
308: fprintf(stdout,"first message\n");
309: fprintf(stdout,"second message\n");
310: fprintf(stdout,"third message\n");
311: printf("foo %d\n",i);
312: }
1.2 fefe 313: #endif
1.1 cvs 314: #if 0
315: char buf[1024];
316: sscanf("foo bar","%s",buf);
317: printf("%s\n",buf);
318: #endif
319: #if 0
320: mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
321: perror("mount");
322: #endif
323: #if 0
324: char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
325: int i=strtol(t+1,&t,10);
326: printf("%d %s\n",i,t);
327: #endif
328: #if 0
329: char **tmp;
330: putenv("FOO");
331: assert(1==2);
332: for (tmp=environ; *tmp; tmp++)
333: puts(*tmp);
334: #endif
335: #if 0
336: char buf[1024];
337: printf("%d\n",fprintf(stderr,"duh\n"));
338: #endif
339: #if 0
340: struct passwd *p=getpwuid(100);
341: puts(p->pw_name);
342: #endif
343: #if 0
344: int pid;
345: char name[32];
346: sscanf("1 (init","%d (%15c",&pid,name);
347: printf("pid %d name %s\n",pid,name);
348: #endif
349: #if 0
350: DIR *d=opendir("/proc");
351: if (d) {
352: struct dirent *D;
353: while (D=readdir(d))
354: puts(D->d_name);
355: closedir(d);
356: }
357: #endif
358: #if 0
359: char buf[1024];
360: int fd=open("/etc/passwd",0);
361: pread(fd,buf,30,32);
362: close(fd);
363: write(1,buf,32);
364: #endif
365: #if 0
366: char *argv[] = {"echo","foo",0};
367: char buf[100];
368: buf[5]='x';
369: sprintf(buf,"foo\n");
370: if (buf[5] == 'x')
371: exit(0);
372: else
373: exit(1);
374: execvp(argv[0],argv);
375: #endif
1.10 fefe 376: #if 0
1.1 cvs 377: struct stat64 f;
378: char buf[128];
379: fstat64(0,&f);
380: fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
381: return 0;
382: #endif
383: #if 0
384: FILE *f=fopen("foo","w");
385: fputc('a',f);
386: fputc('b',f);
387: fputc('c',f);
388: #endif
389: /* fprintf(stdout,"foo\n"); */
390: }
LinuxTV legacy CVS <linuxtv.org/cvs>