Re: [HACKERS] Does this make sense: - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Does this make sense:
Date
Msg-id 199812141455.JAA21406@candle.pha.pa.us
Whole thread Raw
In response to Does this make sense:  (The Hermit Hacker <scrappy@hub.org>)
Responses Re: [HACKERS] Does this make sense:  (jwieck@debis.com (Jan Wieck))
List pgsql-hackers
> 
> char *  
> crypt_getpwdfilename()
> { 
>     
>   static char *pfnam = NULL;
>   
>   if (!pfnam)
>   { 
>     int bufsize;
>     bufsize = strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2;
>     pfnam = (char *) palloc(bufsize); 
>     spprintf(pfnam, bufsize, "%s/%s", DataDir, CRYPT_PWD_FILE);
>   }
>   
>   return pfnam;
> }
> 
> Why the check for '!ipfnam'?  Seems useless since we are setting it to
> NULL the line before...no?

Actually, no.  We are declaring it as static, so the first time the
function is called, it is set to NULL.  After that, it is not
initialized for each function call because a static local variable's
value is kept between function calls.  It is like a global variable in
its duration, but in local scope.

This is an old trick to run the initialization code only the first time
the function is called.

--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: "Thomas G. Lockhart"
Date:
Subject: Re: [HACKERS] nabstime.c changes...
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Bug report: PL/pgSQL and mixed case table/field names.