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