Questions tagged [getcwd]

The getcwd() function retrieves the current working directory pathname on POSIX compliant machines.

The function getcwd() is available on Unix machines to copy the current working directory (as an absolute pathname) to a supplied buffer of an array of characters of a given length. It is specified in POSIX.1-2001 to have the following signature:

char *getcwd(char *buffer, size_t size);
104 questions
5
votes
2 answers

Why does getcwd() returns / in __destruct()?

I have just noticed that getcwd() return "/" if called within __destruct() magic function, while in any other method it returns the expected path. Do you have an explanation for this?
Michael
  • 4,786
  • 11
  • 45
  • 68
4
votes
2 answers

What can I do if getcwd() and getenv("PWD") don't match?

I have a build system tool that is using getcwd() to get the current working directory. That's great, except that sometimes people have spaces in their paths, which isn't supported by the build system. You'd think that you could just make a…
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
4
votes
2 answers

C programming getcwd variable manipulation

Basically I need an if statement of which the response is dependent upon the current working directory. I have done some research on the topic and I believe that the getcwd() function is what I am looking for, but I can't figure out how to interface…
user4493605
  • 391
  • 2
  • 18
4
votes
7 answers

How return a std::string from C's "getcwd" function

Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { …
rubenvb
  • 74,642
  • 33
  • 187
  • 332
4
votes
5 answers

Does the order I declare pointers really matter in C? getcwd() problem

On a Solaris 5.8 machine, I have the following code: [non-working code] char *buf; char *dir; size_t psize; psize = (size_t) 1024; dir = getcwd(buf, psize); On this unix machine, the above does not work and I get a segmentation fault when trying…
chucknelson
  • 2,328
  • 3
  • 24
  • 31
4
votes
1 answer

Is there a wchar_t version of getcwd?

I am trying to this: wchar_t buff[PATH_MAX]; wgetcwd( buff, PATH_MAX); I have also tried _wgetcwd. Google suggests _wgetcwd is in dir.h, but i have never heard of such a header file. I'm using GCC 4.3. Thank you.
mikbal
  • 1,168
  • 1
  • 16
  • 27
4
votes
4 answers

Python os.getcwd() returns with tilde in the path. e.g. C:\MYFOLD~1\test

How can I get python to return the full pathname of C:\myfolderisafolder\test?
Brad Conyers
  • 1,161
  • 4
  • 15
  • 24
3
votes
1 answer

Behavior of opendir() after removing a directory with rmdir()

I'm trying to understand how removing the current working directory works from a C program. I'm using the Advanced Programming in Unix Enviroment book as a reference. First, I make the following sequence of calls (/tmp is an existing directory): //…
3
votes
0 answers

What is the cause of the hard limit on the directory nesting depth returned by getcwd on macOS and how can it be circumvented?

On linux and macOS, directories can be nested to seemingly arbitrary depth, as demonstrated by the following C program. However, on macOS but not on linux, there seems to be a hard limit on the nesting level returned by getcwd, specifically a…
feeley
  • 71
  • 4
3
votes
1 answer

Docker: getcwd: cannot access parent directories

I have a Java app, packaged to the docker container via sbt-native-packager. When testing on local machine or other server, the container starts just fine. And on one of the CoreOS machines on Azure, I'm getting: shell-init: error retrieving current…
3
votes
2 answers

Why doesn't 'C:' mean what I think it means?

On Windows 7 I fire up my IDLE Python 2.7.5 Shell: >>> import os >>> os.getcwd() 'C:\\Python27' >>> os.path.relpath('C:\\') '..' >>> os.path.relpath('C:') '.' >>> os.chdir('C:') >>> os.getcwd() 'C:\\Python27' What is going on, and why does it have…
Scruffy
  • 908
  • 1
  • 8
  • 21
2
votes
1 answer

os.getcwd() leading to FileNotFoundError

I'm trying to import data from a csv into a database following this repository. I run the function on my windows desktop, and get this error: ['Customer Contracts$.csv', 'Customer Demo.csv', 'Customer…
2
votes
2 answers

C, Linux, getcwd/chdir(): get binary path

I want to open a number of files (log4cxx configs, other logs etc) relative to binary's location. Unfortunately, both getwd() and getcwd() are giving me the directory, from which I try to run binary at known path, instead of giving me the path where…
kagali-san
  • 2,964
  • 7
  • 48
  • 87
2
votes
2 answers

getcwd second parameter

What should i fill in the second parameter of the function getcwd if I am reading the current directory?
lital maatuk
  • 5,921
  • 20
  • 57
  • 79
2
votes
0 answers

Shell Init Error trying to install Webpack

I am trying to install Webpack on OSX Sierra. I used the Sudo command and this is what I am getting shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied path.js:1142 cwd =…