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