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

J

Joachim Schmitz

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
 
J

jacob navia

Mark said:
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.
 
D

Dave Vandervies

jacob navia said:
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
 
D

Dave Vandervies

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
 
R

Richard Bos

Mark McIntyre 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
 
L

Lew Pitcher

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top