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