Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How Does One Discover the Full Path Name of the Current Directory?

Reply
Thread Tools

How Does One Discover the Full Path Name of the Current Directory?

 
 
Mark McIntyre
Guest
Posts: n/a
 
      05-11-2007
On Fri, 11 May 2007 09:06:52 +0100, in comp.lang.c , Chris Dollin
<(E-Mail Removed)> wrote:

>jacob navia wrote:
>
>> Richard Bos a écrit :
>>> http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Tobin) wrote:

>
>>> All operating systems _where this is possible in the first place_. It is
>>> not always possible; for example, under very early versions of MS-DOS,
>>> there was no such thing as a directory. All common modern desktop OSes
>>> have them, but I would not be surprised at all to learn of embedded ones
>>> that have files, but no directories, and therefore no path names,
>>> absolute or relative.
>>>
>>> Richard

>>
>> Nobody cares about those systems.

>
>I bet that's not true.


Safe bet: how many mobile phone systems programmers exist? Not to
mention vehicle management systems, EPOS and a zillion other
environments.

>> Living in the past is a favorite passtime of people in this group
>> apparently.


Speak for yourself - I have a funny feeling that embedded systems make
up a significant part of the future.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
 
 
 
Kenneth Brody
Guest
Posts: n/a
 
      05-11-2007
(E-Mail Removed) wrote:
[...]
> Is there some way in C to retrieve the absolute path name of the
> current directory,

[...]

In straight C, no. (C doesn't even know about "directories".)
However, if you want to expand from straight C into the POSIX
world (which is OT here) you can use getcwd(). If you need
more help, you'll need to ask somewhere else where POSIX is
topical. Perhaps comp.unix.programmer?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <(E-Mail Removed)>


 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      05-11-2007
Mark McIntyre wrote:
> On Fri, 11 May 2007 09:06:52 +0100, in comp.lang.c , Chris Dollin
> <(E-Mail Removed)> wrote:
>
>
>>jacob navia wrote:
>>
>>
>>>Richard Bos a écrit :
>>>
>>>>(E-Mail Removed) (Richard Tobin) wrote:

>>
>>>>All operating systems _where this is possible in the first place_. It is
>>>>not always possible; for example, under very early versions of MS-DOS,
>>>>there was no such thing as a directory. All common modern desktop OSes
>>>>have them, but I would not be surprised at all to learn of embedded ones
>>>>that have files, but no directories, and therefore no path names,
>>>>absolute or relative.
>>>>
>>>>Richard
>>>
>>>Nobody cares about those systems.

>>
>>I bet that's not true.

>
>
> Safe bet: how many mobile phone systems programmers exist? Not to
> mention vehicle management systems, EPOS and a zillion other
> environments.
>


Postgres data base in mobile phones?
Did you even READ what the original poster said?

His message started with:

"I've written a piece of code that interfaces with Postgres."

In this context it is stupid to assume he wants his code to run
in some embedded system that hasn't even directories!

But we are lectured about this at every question!

>
>>>Living in the past is a favorite passtime of people in this group
>>>apparently.

>
>
> Speak for yourself - I have a funny feeling that embedded systems make
> up a significant part of the future.



Future "embedded systems" will look more and more like
workstations. Linux has been embedded into a simple watch, for instance.

But embedded systems wasn't the question but the famous

getcwd() function
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-11-2007
In article <46441d87$0$5086$(E-Mail Removed)>,
jacob navia <(E-Mail Removed)> wrote:

>But at each question we have to know apparently how we make the
>program portable to MSDOS systems without directories, or whatever.
>
>Living in the past is a favorite passtime of people in this group
>apparently.


How about a modern OS under active development, then?

PalmOS (for which there are several mutually mostly-compatible
freestanding C implementations, and I believe at least one hosted one)
supports accessing files on an external memory card, but has no concept
of a directory. As far as the OS is concerned, 'card slot 1, file
"/path/to/file"' IS the filename.

How would you find the "current directory" in a PalmOS program?


dave

--
Dave Vandervies (E-Mail Removed)

Your dictionary leaves something to be desired... like a new dictionary.
--James Riden in the scary devil monastery
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      05-11-2007
Dave Vandervies wrote:
> In article <46441d87$0$5086$(E-Mail Removed)>,
> jacob navia <(E-Mail Removed)> wrote:
>
>
>>But at each question we have to know apparently how we make the
>>program portable to MSDOS systems without directories, or whatever.
>>
>>Living in the past is a favorite passtime of people in this group
>>apparently.

>
>
> How about a modern OS under active development, then?
>
> PalmOS (for which there are several mutually mostly-compatible
> freestanding C implementations, and I believe at least one hosted one)
> supports accessing files on an external memory card, but has no concept
> of a directory. As far as the OS is concerned, 'card slot 1, file
> "/path/to/file"' IS the filename.
>
> How would you find the "current directory" in a PalmOS program?
>
>
> dave
>


Hi dave

Two points:

FIRST:
-----

http://www.developer.com/ws/palm/article.php/3508341

Starting from Palm OS 4.0, applications can a utilize new set of
additional system extensions that provide a unified interface for
accessing various expansion capabilities.

....

The Virtual File System Manager is a software layer that manages all
installed file system libraries. The file system is implemented as a
shared library of type sysFileTFileSystem.

Common Operations

VFS Manager supports a standard set of common file operations. They are
listed below, grouped by operation:

Err VFSDirCreate(UInt16 volRefNum, const Char *dirNameP);
Err VFSGetDefaultDirectory(UInt16 volRefNum, const Char *fileTypeStr,
Char *pathStr, UInt16 *bufLenP);
Err VFSRegisterDefaultDirectory(const Char *fileTypeStr,
UInt32 mediaType,
const Char *pathStr);
Err VFSUnregisterDefaultDirectory(const Char *fileTypeStr,
UInt32 mediaType);

This is then, how you manage directories under Palm OS.
It is not good to live in the past

SECOND:
------
I would like to add that the original poster spoke about
"Interfacing to Postgres database". This makes it clear that
he is NOT running in Palm OS or in a coffee machine OS.
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-11-2007
In article <4644b34e$0$5078$(E-Mail Removed)>,
jacob navia <(E-Mail Removed)> wrote:
>Dave Vandervies wrote:
>> In article <46441d87$0$5086$(E-Mail Removed)>,
>> jacob navia <(E-Mail Removed)> wrote:
>>
>>
>>>But at each question we have to know apparently how we make the
>>>program portable to MSDOS systems without directories, or whatever.
>>>
>>>Living in the past is a favorite passtime of people in this group
>>>apparently.

>>
>>
>> How about a modern OS under active development, then?
>>
>> PalmOS (for which there are several mutually mostly-compatible
>> freestanding C implementations, and I believe at least one hosted one)
>> supports accessing files on an external memory card, but has no concept
>> of a directory. As far as the OS is concerned, 'card slot 1, file
>> "/path/to/file"' IS the filename.
>>
>> How would you find the "current directory" in a PalmOS program?
>>
>>
>> dave
>>

>
>Hi dave
>
>Two points:
>
>FIRST:
>-----
>
>http://www.developer.com/ws/palm/article.php/3508341
>
>Starting from Palm OS 4.0, applications can a utilize new set of
>additional system extensions that provide a unified interface for
>accessing various expansion capabilities.


[...]

>Err VFSDirCreate(UInt16 volRefNum, const Char *dirNameP);
>Err VFSGetDefaultDirectory(UInt16 volRefNum, const Char *fileTypeStr,
> Char *pathStr, UInt16 *bufLenP);
>Err VFSRegisterDefaultDirectory(const Char *fileTypeStr,
> UInt32 mediaType,
> const Char *pathStr);
>Err VFSUnregisterDefaultDirectory(const Char *fileTypeStr,
> UInt32 mediaType);
>
>This is then, how you manage directories under Palm OS.
>It is not good to live in the past


If you had actually read the documentation and not just looked at the
names, you would have discovered that these don't actually correspond
to the notion of "directory" as a location in a "directory tree" that you
can move around in, in which you can store "files" that you seem to
be committed to; rather, they provide a way to construct filenames to
access a certain type of file without needing to know where on the card
they're stored when the code is written.
As far as the OS is concerned, all these do is access and manipulate
information about what valid and useful filenames look like. They have
nothing to do with how you access the file once you've figured out
the name.



>SECOND:
>------
>I would like to add that the original poster spoke about
>"Interfacing to Postgres database". This makes it clear that
>he is NOT running in Palm OS or in a coffee machine OS.


I would be entirely unsurprised to find that somebody has written code
that will run on a Palm and interface with a database. (Note that the
database doesn't have to be running on the Palm for code running on the
Palm to interface with it.)


dave

--
Dave Vandervies (E-Mail Removed)
Unfortunately requiring an operating system to function properly is
beyond the authority of the C language standard.
--Jack Klein in comp.lang.c
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      05-11-2007
On Fri, 11 May 2007 19:16:19 +0200, in comp.lang.c , jacob navia
<(E-Mail Removed)> wrote:

>Mark McIntyre wrote:
>> On Fri, 11 May 2007 09:06:52 +0100, in comp.lang.c , Chris Dollin
>> <(E-Mail Removed)> wrote:
>>

>
>Postgres data base in mobile phones?
>Did you even READ what the original poster said?


Sure, but what does postgres have to do with whether or not anyone
cares about systems that don't support directories?

If you had said "on a system which uses relational databases, its
unlikely there is not support for directories" you would have been
correct, (though someone would probably have pointed out that at least
one RDBMS zaps the partition and reformats with its own filesystem
that has no directories).

>In this context it is stupid to assume he wants his code to run
>in some embedded system that hasn't even directories!


Whats stupid is to say
"nobody cares about such systems".
when you mean
"the OP probably doesn't care about such systems".

The trick is to write what you mean, rather than arrogant-sounding
generalities that annoy people.

>But we are lectured about this at every question!


Well, /you/ certainly are.

>> Speak for yourself - I have a funny feeling that embedded systems make
>> up a significant part of the future.

>
>Future "embedded systems" will look more and more like
>workstations.


And the future of desktop computing is diskless workstations.
If Larry can get it wrong, explain why I should believe you...

Myself, I think that future embedded systems will look less and less
like computers at all. Why waste memory and flash with an os that
supports directories, when you're programming the central heating
system?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      05-11-2007
On Fri, 11 May 2007 18:45:13 +0000 (UTC), in comp.lang.c ,
(E-Mail Removed) (Dave Vandervies) wrote:

>I would be entirely unsurprised to find that somebody has written code
>that will run on a Palm and interface with a database. (Note that the
>database doesn't have to be running on the Palm for code running on the
>Palm to interface with it.)


For what its worth, programming for Palm 4.x and below is almost
entirely like working inside a database. You write what are
effectively SPs to access and manipulate data stored in table-like
structures. There's a reason they're called PDBs...

Oh, and there's an ODBC driver for PalmOS.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-12-2007
In article <(E-Mail Removed)>,
Mark McIntyre <(E-Mail Removed)> wrote:
>On Fri, 11 May 2007 18:45:13 +0000 (UTC), in comp.lang.c ,
>(E-Mail Removed) (Dave Vandervies) wrote:
>
>>I would be entirely unsurprised to find that somebody has written code
>>that will run on a Palm and interface with a database. (Note that the
>>database doesn't have to be running on the Palm for code running on the
>>Palm to interface with it.)

>
>For what its worth, programming for Palm 4.x and below is almost
>entirely like working inside a database. You write what are
>effectively SPs to access and manipulate data stored in table-like
>structures. There's a reason they're called PDBs...


Yes. (That's still mostly the case for 5.x as well.) The concept of a
"file" doesn't exist in the Palm's internal storage; you only have files
if there's a memory card in an external expansion slot.
This is one of the reasons why freestanding implementations don't need
to have <stdio.h>.

I doubt that accessing a PDB is anything like interfacing with a Postgres
database, though.


dave

--
Dave Vandervies (E-Mail Removed)
Yet there is no error here, no undefined behavior, no contravention
of anything except good sense.
--Eric Sosman in comp.lang.c
 
Reply With Quote
 
guru.jois@gmail.com
Guest
Posts: n/a
 
      05-14-2007
On May 11, 5:26 am, (E-Mail Removed) (Richard Tobin) wrote:
> In article <(E-Mail Removed). com>,
>
> <(E-Mail Removed)> wrote:
> >I've written a piece of code that interfaces with Postgres. It needs
> >to write a Postgres table to disk, which it does with the <COPY> com-
> >mand. That command requires the absolute file name of the file being
> >written to. Right now I've got it hard coded to the exact location
> >where I want it, but that's not very portable. Is there some way in C
> >to retrieve the absolute path name of the current directory, so that I
> >could use that in my code and therefore have my code function right no
> >matter where it's executed? Any information on this would be greatly
> >appreciated.

>
> There's no portable way to do this in standard C: in fact, C itself
> doesn't know anything at all about directories. But all operating
> systems provide a way to do it. For example, unix systems have
> getcwd() ("get current working directory") which is declared in
> <unistd.h>.

This require dynamic memory to hold path length, tough to predict. If
less, lost. If more segfault.
Better try
char * get_current_dir_name(void);
which calls malloc by itself...
>
> -- Richard
> --
> "Consideration shall be given to the need for as many as 32 characters
> in some alphabets" - X3.4, 1963.


Bye
Gururaj.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to get Full Path of current directory ? (ASP.net) PHaroZ ASP .Net 5 08-17-2012 08:39 AM
The name <name> does not exist in the current context Montand ASP .Net 1 02-20-2008 08:09 AM
Get Current Full App Path? xeroxero ASP .Net 1 12-08-2006 05:56 AM
best way to discover this process's current memory usage, cross-platform? Alex Martelli Python 25 12-01-2005 11:58 PM



Advertisments