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