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