Search the web
Sign In
New User? Sign Up
gbuffy · GBuffy Tool Discussion
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
safe_strdup   Message List  
Reply | Forward Message #52 of 231 |
Re: safe_strdup

Well, the obvious difference from the code is that safe_strdup()
returns NULL for "" as well as NULL strings. Its pulled from the mutt
source code, I'm not sure if we ever rely on that behavior in gbuffy,
however.

Brandon

On 02/08/03 Jon-o Addleman uttered the following other thing:
> I'm digging through the gbuffy source, in the hope of fixing various
> things, and learning stuff in the process.
>
> With my ignorance in mind, can anyone explain the point of the
> safe_strdup function? What does it do that strdup doesn't? They seem
> nearly identical.. Seems it would simplify things to just use strdup
> instead. (similar issues come up with the geometry setting, which
> currently doesn't work at all - there's an xlib function for parsing
> that...)
>
>
> Just for reference, here's strdup from glibc-2.3.1
>
> char *
> __strdup (const char *s)
> {
> size_t len = strlen (s) + 1;
> void *new = malloc (len);
>
> if (new == NULL)
> return NULL;
>
> return (char *) memcpy (new, s, len);
> }
>
>
>
> and here's safe_strdup:
>
> char *safe_strdup (const char *s)
> {
> char *p;
> size_t l;
>
> if (!s || !*s) return 0;
> l = strlen (s) + 1;
> p = (char *)malloc (l);
> memcpy (p, s, l);
> return (p);
> }
>
> --
> Jon-o Addleman
> Curious about the PGP attachments in my e-mail?
> see http://www.st-andrews.ac.uk/scotmid/pgpweb/pgpintro.shtml
> to find out why they're there!



--
"Would a precognitive telepath know what you were thinking before
you thought it?" -- Sherry M. Gottlieb
http://www.fiction.net/blong/



Sat Feb 8, 2003 8:36 pm

blong42
Offline Offline
Send Email Send Email

Forward
Message #52 of 231 |
Expand Messages Author Sort by Date

I'm digging through the gbuffy source, in the hope of fixing various things, and learning stuff in the process. With my ignorance in mind, can anyone explain...
Jon-o Addleman
zortog_the_m...
Offline Send Email
Feb 8, 2003
4:36 pm

Well, the obvious difference from the code is that safe_strdup() returns NULL for "" as well as NULL strings. Its pulled from the mutt source code, I'm not...
Brandon Long
blong42
Offline Send Email
Feb 8, 2003
8:36 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help