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