swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a couple of C questions about ASM-objc


From: Ralf Stephan
Subject: Re: a couple of C questions about ASM-objc
Date: Thu, 18 May 2000 09:08:56 +0200

Paul: 
> I don't understand why sfsm declares all these functions with extern,
> though.

Yes, the right[tm] way to do it is #include headers and use #ifdef
to distinguish between different headers on different platforms.

>... I kept getting segfaults because I was relying on the
> getcwd to malloc some space for me.  The man page says it will do it if
> you pass in a null pointer.  But later I did
>         pathname=calloc(MAXPATHLEN, sizeof(char));
>          getcwd( (char*) pathname, MAXPATHLEN);
> 
> then it worked fine.  Eventually I found a manual that said it was
> discouraged to rely on getcwd to allocate the memory, but it did not say
> why.   

Strange.  My Debian says:

       As  an  extension  to the POSIX.1 standard, getcwd() allo-
       cates the buffer dynamically using malloc() if buf is NULL
       on  call.   In  this  case,  the  allocated buffer has the
       length size unless size is less than  zero,  when  buf  is
       allocated  as  big  as  necessary.   It  is possible (and,
       indeed, advisable) to free() the buffers if they have been
       obtained this way.

       get_current_dir_name,   which   is   only   prototyped  if
       __USE_GNU is defined, will malloc(3) an array  big  enough
       to  hold  the  current directory name.  If the environment
       variable PWD is set, and its value is correct,  then  that
       value will be returned.

       getwd,  which  is only prototyped if __USE_BSD is defined,
       will not malloc(3) any memory.


ralf
-- 
http://ME.IN-berlin.de/~rws/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]