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?

 
 
Joachim Schmitz
Guest
Posts: n/a
 
      05-14-2007
<(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) oups.com...
> On May 11, 5:26 am, (E-Mail Removed) (Richard Tobin) wrote:
>> In article <(E-Mail Removed). com>,

....
>> 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...

as per the manual:
char *getcwd(char *buffer, size_t size)
....
if the buffer parameter is a null pointer, getcwd() uses the malloc()
function to allocate a buffer from the heap of the calling process

getcwd() is POSIX, get_current_dir_name() isn't part of any standard, is it?

Bye, Jojo


 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      05-14-2007
In article <(E-Mail Removed) .com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
>On May 11, 5:26 am, (E-Mail Removed) (Richard Tobin) wrote:
>> In article <(E-Mail Removed). com>,


>> 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>.


>Better try
> char * get_current_dir_name(void);
> which calls malloc by itself...


get_current_dir_name() appears to be defined only on a limited
range of systems, and only when _GNU_SOURCE is defined. As best
I can tell at the moment, it appears to be part of Linux. Linux
is not unix.
--
All is vanity. -- Ecclesiastes
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      05-15-2007
Mark McIntyre wrote:
> 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?


Because the heating system is supposed to keep statistics
about temperature and oil usage and send them through a
wireless internet connection to the workstation of the administrator
of the building each night at 3AM.

Data is stored in files, and files are best handled with an
OS that has a reasonable file system. Besides, standards are
important and an embedded linux system is much easier to maintain
than a cutomized file system without directories.

An OS provides more capabilities to an embedded system that
allows it to be more useful, without having to develop all
things by yourself.

Linux comes with internet/tcpip stack, file system, and many other
goodies you do not have to develop when you put it in your
system.

And I say "linux" as I would say any *OS*. There are others, simpler
than linux, but with advanced file systems.
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-16-2007
In article <464a38d6$0$5112$(E-Mail Removed)>,
jacob navia <(E-Mail Removed)> wrote:

>Data is stored in files, and files are best handled with an
>OS that has a reasonable file system.


Counterexample: PalmOS.
It understands filesystems, which lets it read and write external memory
cards using the same language that the rest of the world understands,
but it stores data perfectly well in internal storage without a filesystem
in sight.


dave

--
Dave Vandervies (E-Mail Removed)
If you guys are going to have a fight, don't mind me - I can always make
a buck on the ticket sales. But make it a nice /clean/ fight, okay?
--Richard Heathfield in comp.lang.c
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-16-2007
In article <(E-Mail Removed)>,
CBFalconer <(E-Mail Removed)> wrote:
>Dave Vandervies wrote:
>> jacob navia <(E-Mail Removed)> wrote:
>>
>>> Data is stored in files, and files are best handled with an
>>> OS that has a reasonable file system.

>>
>> Counterexample: PalmOS.
>> It understands filesystems, which lets it read and write external
>> memory cards using the same language that the rest of the world
>> understands, but it stores data perfectly well in internal storage
>> without a filesystem in sight.

>
>What counterexample? So does Linux, CP/M, DOS, even Winblows.


I would have to do nontrivial work to get a Linux system to manage data
in persistent storage without a filesystem. (It can of course be done,
but I would have to acquire or build the tools to do it.) The natural
way to store data is in files, and the system makes handling files easy.
I don't have enough (deep enough or recent enough) knowledge of CP/M,
DOS, or Windows to be certain that that's the case there, but I would
be quite surprised if it weren't.
PalmOS is quite happy, out of the box, to store my data without a
filesystem, which makes it a counterexample to navia's claim that data
is stored in files.


dave

--
Dave Vandervies (E-Mail Removed)
I bet half of my CDs are from shops that are now no longer in business. It's
a good thing that they don't need to phone home every 90 days to keep
working, really. --Peter Corlett in the scary devil monastery
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      06-04-2007
Mark McIntyre <(E-Mail Removed)> wrote:

> On Fri, 11 May 2007 19:16:19 +0200, in comp.lang.c , jacob navia
> <(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).


I *hate* that system. It's completely unmaintainable, and it bloody well
leaks memory.

Nevertheless, it does exist, and anyone writing C code had better be
aware that it, and systems vaguely like it, do exist. And may then
choose to ignore them, of course; but _choose_ to, not assume, from lack
of education, that they do not exist.

Richard
 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      06-04-2007
On May 16, 11:45 am, (E-Mail Removed) (Dave
Vandervies) wrote:
> In article <(E-Mail Removed)>,
>
> CBFalconer <(E-Mail Removed)> wrote:
> >Dave Vandervies wrote:
> >> jacob navia <(E-Mail Removed)> wrote:

>
> >>> Data is stored in files, and files are best handled with an
> >>> OS that has a reasonable file system.

>
> >> Counterexample: PalmOS.
> >> It understands filesystems, which lets it read and write external
> >> memory cards using the same language that the rest of the world
> >> understands, but it stores data perfectly well in internal storage
> >> without a filesystem in sight.

>
> >What counterexample? So does Linux, CP/M, DOS, even Winblows.

>
> I would have to do nontrivial work to get a Linux system to manage data
> in persistent storage without a filesystem.


Well, I guess it depends on what you mean by "a filesystem", and how
much work you consider "nontrivial" to be.

Assuming that a raw device qualifies as "persistant storage without a
filesystem", then it is trivially easy to get a Linux system (or any
Posix system, for that matter) to manage data on it. It can even be
done is ISO standard C:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *storage;
int datum;

if ((storage = fopen("/dev/hdb", "r+b")) != NULL)
{
fprintf(storage,"%s\n","Persistent data");
fseek(storage,0l,SEEK_SET);
for (datum=fgetc(storage);datum != EOF && datum !=
'\n';datum=fgetc(storage))
putchar(datum);
fclose(storage);
return EXIT_SUCCESS;
}
else return EXIT_FAILURE;
}


[snip]

 
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