FENIX_coreutils/pwd.c
2020-12-13 10:22:44 -06:00

26 lines
474 B
C
Executable file

#define _POSIX_C_SOURCE 200809L
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[]) {
int mode = 01; /* 01: print PWD -L, 02: print physical path -P */
char c;
while((c = getopt(argc, argv, "LP")) != -1) {
switch(c) {
case 'L': mode = 01; break;
case 'P': mode = 02; break;
}
}
if(mode == 01) {
printf("%s\n", getenv("PWD"));
}
else {
printf("%s\n", getcwd(NULL, 0));
}
return 0;
}