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