// MKCP204pwdc 20240722
// description: pwd command, read full path of the current directory.
// using system call on LINUX
// board: Milk-V DUO 256MB
// MPU:RISC-V CPU 1 x C906@1GHz + 1 x C906@700MHz
// SD card: DUOV1.1.1.img
// os cat /etc/os-release NAME=Buildroot VERSION=20240528-2053
// device:
// language: C, cross compile riscv64-unknown-linux-musl-gcc
// IDE: VScode using wsl ubuntu on windows11
// duo-example/MKCP204pwdc
// | makefile
// | pwdc.c
//$ cd duo-examples
//$ source envsetup.sh >> SDK environment is read
//$ cd MKCP204pwdc
//$ make
//--------------------------------------
// target folder mkdir MKCP204pwdc
//$ scp -O pwdc root@192.168.42.1:/root/MKCP204pwdc
//$ ssh root@192.168.42.1
//# cd MKCP204pwdc
//# ./pwdc
//# ./pwdc >> /root/MKCP204pwdc \n /root/MKCP204pwdc \n /root/MKCP204pwdc \n
#include
#include
#include
#include
int main() {
char buffer[PATH_MAX]; // PATH_MAX:4096
getcwd(buffer, PATH_MAX); // retrieves the current directory path
// if (!getcwd(buffer, PATH_MAX)) { //handing error
// perror("getcwd");
// exit(1);
// }
puts(buffer); // write buffer
printf("%s\n",buffer); // write buffer as same as upper
int i=0;
while(buffer[i]) { // write buffer as same as upper
putchar(buffer[i++]);
}
putchar('\n');
}