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