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