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