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