• Post Reply Bookmark Topic Watch Topic
  • New Topic

implementing own pwd command  RSS feed

 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an assignment. I need to implement my own pwd command. I researched and found that I may have to use /proc directory to implement this.I am not allowed to use bash commands or system() function. Please help.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ravindra, welcome to the Ranch!

Can you show us what you've done so far? You mention that your research suggests using the /proc dir, can you expand on what you mean by that? How would you use that directory to get what you want?
 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that i can use readlink /proc/self/cwd from command line to get the current working directory. But I have trouble using this in my program. How can I use this in my program
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra koranga wrote:I found that i can use readlink /proc/self/cwd from command line to get the current working directory. But I have trouble using this in my program. How can I use this in my program


Linux/Unix has the getcwd() function, which returns the current working directory. Isn't that easier than using readlink() to resolve the symbolic link that is maintained in procfs?

Regardless, readlink() on the symlink should work. What trouble are you facing?

Henry
 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I got it. I didn't know readlink() fun is available in linux. My doubt is solved. Thank You!
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the benefit of others reading this thread, it would be really cool if you were to show us you final solution.

Would you do that for us?
 
ravindra koranga
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my final solution is to use getcwd function.It is available in unistd.h library.
If we call getcwd(0,0); then the current working directory is returned by the function.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!