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