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