Re: Porting git to HP NonStop

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

 



On Wed, Aug 22, 2012 at 10:18 AM, Joachim Schmitz
<jojo@xxxxxxxxxxxxxxxxxx> wrote:
>> From: Brandon Casey [mailto:drafnel@xxxxxxxxx]
>> Sent: Wednesday, August 22, 2012 7:01 PM
>> To: Joachim Schmitz
>> Cc: Junio C Hamano; Shawn Pearce; git@xxxxxxxxxxxxxxx;
>> rsbecker@xxxxxxxxxxxxx
>> Subject: Re: Porting git to HP NonStop
>>
>> On Wed, Aug 22, 2012 at 9:30 AM, Joachim Schmitz <jojo@xxxxxxxxxxxxxxxxxx>
>> wrote:
>>
>> > OK, so how about this:
>> > /usr/local/bin/diff -EBbu ./compat/mkdir.c.orig ./compat/mkdir.c
>> > --- ./compat/mkdir.c.orig       2012-08-21 05:02:11 -0500
>> > +++ ./compat/mkdir.c    2012-08-21 05:02:11 -0500
>> > @@ -0,0 +1,24 @@
>> > +#include "../git-compat-util.h"
>> > +#undef mkdir
>> > +
>> > +/* for platforms that can't deal with a trailing '/' */ int
>> > +compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) {
>> > +       int retval;
>> > +       char *tmp_dir = NULL;
>> > +       size_t len = strlen(dir);
>> > +
>> > +       if (len && dir[len-1] == '/') {
>> > +               if ((tmp_dir = strdup(dir)) == NULL)
>> > +                       return -1;
>> > +               tmp_dir[len-1] = '\0';
>> > +       }
>> > +       else
>> > +               tmp_dir = (char *)dir;
>> > +
>> > +       retval = mkdir(tmp_dir, mode);
>> > +       if (tmp_dir != dir)
>> > +               free(tmp_dir);
>> > +
>> > +       return retval;
>> > +}
>>
>> Why not rearrange this so that you assign to dir the value of tmp_dir and then
>> just pass dir to mkdir.  Then you can avoid the recast of dir to (char*) in the
>> else branch.  Later, just call free(tmp_dir).  Also, we have xstrndup.  So I think
>> the body of your function can become something like:
>>
>>    if (len && dir[len-1] == '/')
>>        dir = tmp_dir = xstrndup(dir, len-1);
>
> xstndup() can't fail?

Correct.  It will either succeed or die.  It will also try to free up
some memory used by git if possible.

-Brandon
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]