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