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);
88 questions
1
vote
1 answer

is there such thing as a getcwd() syscall on macos

I am wondering if there is a getcwd system call on macos. I can't seem to find any leads on the code for getcwd apart from https://www.informatik.htw-dresden.de/~beck/ASM/syscall_list.html. However, the code it gives does not function. I have tried…
1
vote
1 answer

Python: os.getcwd() randomly fails in mounted network drive

I'm on Debian using python3.7. I have a network drive that I typically mount to /media/N_drive with dir_mode=0777 and file_mode=0777. I generally have no issues with reading/writing files in this network drive. Occasionally, especially soon after…
1
vote
5 answers

warning: comparison between pointer and integer in C

I get a warning warning: comparison between pointer and integer on the line containing if from the next piece of code: char cwd[1024]; if (getcwd(cwd, sizeof(cwd)) != (char*)NULL) printf("%s\n",cwd); else error_print("error in pwd"); how…
SIMEL
  • 8,246
  • 23
  • 76
  • 115
1
vote
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,646
  • 6
  • 40
  • 84
1
vote
1 answer

getcwd error when $HOME

I wrote my own find() function. When I do: ./myown $HOME/Documents test.txt I get: /Users/CJ/Documents/test/test.txt /Users/CJ/Documents/test/test1/test.txt /Users/CJ/Documents/test/test2/test.txt However when I do: ./myown $HOME test.txt I…
C.J
  • 129
  • 1
  • 9
1
vote
1 answer

Change current working directory in child process in C

I have to write a program which generates child process than ends parent process and after that that created child process has to ask user to input new working directory, change it and print path to its new working directory. I wrote this, but scanf…
szeejdi
  • 476
  • 5
  • 19
1
vote
2 answers

Python module import not working

I am getting an error with the following code: from os import getcwd os.getcwd() Traceback (most recent call last): File "", line 1, in os.getcwd() NameError: name 'os' is not defined Anyone know why importing this way is not…
West
  • 1,356
  • 2
  • 12
  • 34
1
vote
2 answers

current working directory mismatch in python

I have imported a existing filesystem folder as the new project folder in eclipse. I have a script which get the current working directory path of the code. I need to change directory location to acccess files in other directory related to it. But…
1
vote
4 answers

Why some functions return the result both in return value and by writing to pointer passed?

Recently was reading man page of getcwd(3). It writes current working directory to passed buf pointer and also returns it as pointer to char. Could you please explain why it does so(giving result using two ways)?
Bulat M.
  • 638
  • 6
  • 21
1
vote
2 answers

PHP if/else is not functioning properly

I am trying to use an if/else statement in PHP. Currently what I am trying to do is if the $_SESSION['usr']; is equal to the current directory ($dir_auth2) variable that the user is trying to access. Then they can access the directory or index.php I…
aidangig
  • 167
  • 10
1
vote
1 answer

Incorrect path with function getcwd()

I get the wrong path back. The Datafile is in D:... and get everytime the path C:\Python27\lib\site-packages\xy back from python. I use the function path = getcwd() How can I fix it?
A.Boss
  • 207
  • 4
  • 8
1
vote
3 answers

What could change the directory in php Windows besides chdir() and chroot()? (Simpletest include file bug in Windows)

(Sorry if this is titled poorly. I'm actually trying to accomplish two things - find out how the current directory can get changed in PHP, and fix a bug in Simpletest running on WAMP.) I'm running SimpleTest (simpletest.org) on my Windows 7 local…
Burton Kent
  • 788
  • 5
  • 10
1
vote
2 answers

getcwd for current location based on ftp account permission

I'm trying to make a small script that's changing the permission for specific file using a ftp connection. My problem is the absolute path. I have a ftp account wich land on the script directory (/script/). If i'm using getcwd, it will return the…
John Doe
  • 23
  • 4
1
vote
2 answers

non-standard / non-POSIX getcwd() not calling malloc

What part of this quote from the getcwd man-page am I misunderstanding? char *getcwd(char *buf, size_t size); ... As an extension to the POSIX.1-2001 standard, Linux (libc4, libc5, glibc) getcwd() allocates the buffer dynamically…
Kdawg
  • 167
  • 11
1
vote
4 answers

Using malloc properly

I'm trying to put my directory pathname on a string variable, like this: int main(int ac, char **av) { char*dir; if(ac > 2) { dir = malloc(sizeof(*dir) * 512); getcwd(dir, sizeof(*dir)); printf("dat dir is:\n"); …
Saxtheowl
  • 724
  • 3
  • 12
  • 27