FENIX_coreutils/pwd.c

32 lines
603 B
C
Raw Normal View History

#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 */
if(argc > 1) {
for(int i = 1; i < argc; i++) {
if(argv[i][1] == 'L' && argv[i][2] == '\0') {
mode = 01;
}
else if(argv[i][1] == 'P' && argv[i][2] == '\0') {
mode = 02;
}
else {
fprintf(stderr, "%s: invalid option: %s\n", argv[0], argv[i]);
exit(1);
}
}
}
if(mode == 01) {
printf("%s\n", getenv("PWD"));
}
else {
printf("%s\n", getcwd(NULL, 0));
}
return 0;
}