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