FENIX_coreutils/pwd.c

27 lines
474 B
C
Raw Normal View History

#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 */
2020-12-13 16:22:44 +00:00
char c;
2020-12-13 16:22:44 +00:00
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;
}