2020-12-12 06:33:20 +00:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
2020-02-12 05:30:50 +00:00
|
|
|
#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;
|
|
|
|
}
|