Add an implementation of the factorial algorithm in Haskell.
[4chanprog.git] / coreutils / pwd.c
blob170c5fb5961088a54b1b0848ed820b6465bd0078
1 #include <errno.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
6 /* Not yet posix, command line arguments not handled */
8 int not_posix = 0;
10 int main(void)
12 char *pathname;
13 if(not_posix)
15 pathname = getcwd(0, 0); /* Not POSIX, but a reasonable option */
17 else
19 size_t i = 100;
20 pathname = NULL;
21 while(1)
23 pathname = realloc(pathname, i);
24 if(! pathname)
26 fputs("pwd: memory allocation failure", stderr);
27 return 1;
30 if(getcwd(pathname, i))
31 break;
33 if(errno != ERANGE)
35 perror("pwd");
36 free(pathname);
37 return 1;
40 i += 100;
44 if((!not_posix || pathname) && puts(pathname) != EOF)
46 free(pathname);
47 return 0;
49 else
51 perror("pwd");
52 free(pathname);
53 return 1;