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