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