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