git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: Porting git to HP NonStop

From
Joachim Schmitz <jojo@schmitz-digital.de>
Date
Aug 22, 2012, 18:52 UTC
Message-ID
<004201cd8097$4ef04a80$ecd0df80$@schmitz-digital.de>
In-Reply-To
<7v393e943x.fsf@alter.siamese.dyndns.org>
Show 14 quoted lines
> From: Junio C Hamano [mailto:gitster@pobox.com]
> Sent: Wednesday, August 22, 2012 8:25 PM
> To: Joachim Schmitz
> Cc: 'Brandon Casey'; 'Shawn Pearce'; git@vger.kernel.org;
> rsbecker@nexbridge.com
> Subject: Re: Porting git to HP NonStop
> 
> "Joachim Schmitz" <jojo@schmitz-digital.de> writes:
> 
> >> Nice.  And we have xmemdupz() would be even better as you followed-up.
> >
> > How's that one used?
> 
> I forgot that we frown upon use of any x<allocate>() wrapper in the
compat/
Show 21 quoted lines
> layer as J6t mentioned.
> 
> So probably something along these lines...
> 
> 	int retval;
> 	char *dir_to_free = NULL;
> 	size_t len = strlen(dir);
> 
>         if (len && dir[len - 1] == '/') {
> 		dir_to_free = malloc(len);
>                 if (!dir_to_free) {
> 			fprintf(stderr, "malloc failed!\n");
> 			exit(1);
> 		}
>                 memcpy(dir_to_free, dir, len - 1);
>                 dir_to_free[len - 1] = '\0';
>                 dir = dir_to_free;
> 	}
> 	retval = mkdir(dir, mode);
> 	free(dir_to_free);
>         return retval;
So why not just strdup? I stole the idea from gnulib...
int
rpl_mkdir (char const *dir, mode_t mode maybe_unused)
{
  int ret_val;
  char *tmp_dir;
  size_t len = strlen (dir);
  if (len && dir[len - 1] == '/')
    {
      tmp_dir = strdup (dir);
      if (!tmp_dir)
        {
          /* Rather than rely on strdup-posix, we set errno ourselves.  */
          errno = ENOMEM;
          return -1;
        }
      strip_trailing_slashes (tmp_dir);
    }
  else
    {
      tmp_dir = (char *) dir;
    }

They strip more than one trailing slash, but for git's purpose I believed this to be too much overhead. Also the errno stuff doesn't seem to be really needed IMHO. Same for the following code

#if FUNC_MKDIR_DOT_BUG
  /* Additionally, cygwin 1.5 mistakenly creates a directory "d/./".  */
  {
    char *last = last_component (tmp_dir);
    if (*last == '.' && (last[1] == '\0'
                         || (last[1] == '.' && last[2] == '\0')))
      {
        struct stat st;
        if (stat (tmp_dir, &st) == 0)
          errno = EEXIST;
        return -1;
      }
  }
#endif /* FUNC_MKDIR_DOT_BUG */
Then it goes on like mine:
  ret_val = mkdir (tmp_dir, mode);
  if (tmp_dir != dir)
    free (tmp_dir);
  return ret_val;
}

Compare: $ cat compat/mkdir.c #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;
}
Bye, Jojo
Previous: Junio C HamanoNext: Johannes Sixt
Message 20 of 39 in “RE: Porting git to HP NonStop”
  1. Joachim SchmitzAug 10, 2012
  2. Shawn PearceAug 10, 2012
  3. Joachim SchmitzAug 10, 2012
  4. Shawn PearceAug 10, 2012
  5. Joachim SchmitzAug 19, 2012
  6. Junio C HamanoAug 19, 2012
  7. Joachim SchmitzAug 20, 2012
  8. Junio C HamanoAug 20, 2012
  9. Joachim SchmitzAug 20, 2012
  10. Junio C HamanoAug 20, 2012
  11. Joachim SchmitzAug 22, 2012
  12. Brandon CaseyAug 22, 2012
  13. Brandon CaseyAug 22, 2012
  14. Joachim SchmitzAug 22, 2012
  15. Brandon CaseyAug 22, 2012
  16. Joachim SchmitzAug 22, 2012
  17. Junio C HamanoAug 22, 2012
  18. Joachim SchmitzAug 22, 2012
  19. Junio C HamanoAug 22, 2012
  20. Joachim SchmitzAug 22, 2012
  21. Johannes SixtAug 22, 2012
  22. Joachim SchmitzAug 22, 2012
  23. Johannes SixtAug 22, 2012
  24. Joachim SchmitzAug 22, 2012
  25. Brandon CaseyAug 22, 2012
  26. Brandon CaseyAug 22, 2012
  27. Junio C HamanoAug 22, 2012
  28. Brandon CaseyAug 22, 2012
  29. Joachim SchmitzAug 22, 2012
  30. Junio C HamanoAug 22, 2012
  31. Joachim SchmitzAug 22, 2012
  32. Junio C HamanoAug 22, 2012
  33. Joachim SchmitzAug 22, 2012
  34. Junio C HamanoAug 22, 2012
  35. Junio C HamanoAug 22, 2012
  36. Joachim SchmitzAug 10, 2012
  37. Johannes SixtAug 11, 2012
  38. Joachim SchmitzAug 14, 2012
  39. Junio C HamanoAug 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.